@@ -3,14 +3,14 @@ use std::process::{Command, Stdio, exit};
33use std:: time:: Duration ;
44use std:: { env, fs, process, thread} ;
55
6+ const JOSH_PORT : u16 = 42042 ;
67const DEFAULT_PR_BRANCH : & str = "update-builtins" ;
78
89pub struct GitSync {
910 upstream_repo : String ,
1011 upstream_ref : String ,
1112 upstream_url : String ,
1213 josh_filter : String ,
13- josh_port : u16 ,
1414 josh_url_base : String ,
1515}
1616
@@ -20,15 +20,13 @@ impl GitSync {
2020 pub fn from_current_dir ( ) -> anyhow:: Result < Self > {
2121 let upstream_repo =
2222 env:: var ( "UPSTREAM_ORG" ) . unwrap_or_else ( |_| "rust-lang" . to_owned ( ) ) + "/rust" ;
23- let josh_port = 42042 ;
2423
2524 Ok ( Self {
2625 upstream_url : format ! ( "https://github.com/{upstream_repo}/" ) ,
2726 upstream_repo,
2827 upstream_ref : env:: var ( "UPSTREAM_REF" ) . unwrap_or_else ( |_| "HEAD" . to_owned ( ) ) ,
2928 josh_filter : ":/library/compiler-builtins" . to_owned ( ) ,
30- josh_port,
31- josh_url_base : format ! ( "http://localhost:{josh_port}" ) ,
29+ josh_url_base : format ! ( "http://localhost:{JOSH_PORT}" ) ,
3230 } )
3331 }
3432
@@ -52,7 +50,7 @@ impl GitSync {
5250 self . ensure_clean ( ) ;
5351
5452 // Make sure josh is running.
55- let _josh = self . start_josh ( ) ;
53+ let _josh = Josh :: start ( ) ;
5654 let josh_url_filtered = self . josh_url (
5755 & self . upstream_repo ,
5856 Some ( & new_upstream_base) ,
@@ -182,7 +180,7 @@ impl GitSync {
182180 . to_string ( ) ;
183181
184182 // Make sure josh is running.
185- let _josh = self . start_josh ( ) ;
183+ let _josh = Josh :: start ( ) ;
186184
187185 // Prepare the branch. Pushing works much better if we use as base exactly
188186 // the commit that we pulled from last time, so we use the `rust-version`
@@ -245,10 +243,6 @@ impl GitSync {
245243 ) ;
246244 }
247245
248- fn start_josh ( & self ) -> impl Drop {
249- Josh :: start ( self . josh_port )
250- }
251-
252246 /// Construct a url to the local Josh server with (optionally)
253247 fn josh_url ( & self , repo : & str , rev : Option < & str > , filter : Option < & str > ) -> String {
254248 format ! (
@@ -301,10 +295,10 @@ impl GitSync {
301295}
302296
303297/// Create a wrapper that stops Josh on drop.
304- struct Josh ( process:: Child ) ;
298+ pub struct Josh ( process:: Child ) ;
305299
306300impl Josh {
307- fn start ( port : u16 ) -> Self {
301+ pub fn start ( ) -> Self {
308302 // Determine cache directory.
309303 let local_dir = {
310304 let user_dirs =
@@ -318,7 +312,7 @@ impl Josh {
318312 . arg ( local_dir)
319313 . args ( [
320314 "--remote=https://github.com" ,
321- & format ! ( "--port={port }" ) ,
315+ & format ! ( "--port={JOSH_PORT }" ) ,
322316 "--no-background" ,
323317 ] )
324318 . stdout ( Stdio :: null ( ) )
@@ -329,10 +323,11 @@ impl Josh {
329323 // Wait until the port is open. We try every 10ms until 1s passed.
330324 for _ in 0 ..100 {
331325 // This will generally fail immediately when the port is still closed.
332- let addr = SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , port ) ) ;
326+ let addr = SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , JOSH_PORT ) ) ;
333327 let josh_ready = TcpStream :: connect_timeout ( & addr, Duration :: from_millis ( 1 ) ) ;
334328
335329 if josh_ready. is_ok ( ) {
330+ println ! ( "josh up and running" ) ;
336331 return Josh ( josh) ;
337332 }
338333
0 commit comments