@@ -3,14 +3,14 @@ use std::process::{Command, Stdio, exit};
3
3
use std:: time:: Duration ;
4
4
use std:: { env, fs, process, thread} ;
5
5
6
+ const JOSH_PORT : u16 = 42042 ;
6
7
const DEFAULT_PR_BRANCH : & str = "update-builtins" ;
7
8
8
9
pub struct GitSync {
9
10
upstream_repo : String ,
10
11
upstream_ref : String ,
11
12
upstream_url : String ,
12
13
josh_filter : String ,
13
- josh_port : u16 ,
14
14
josh_url_base : String ,
15
15
}
16
16
@@ -20,15 +20,13 @@ impl GitSync {
20
20
pub fn from_current_dir ( ) -> anyhow:: Result < Self > {
21
21
let upstream_repo =
22
22
env:: var ( "UPSTREAM_ORG" ) . unwrap_or_else ( |_| "rust-lang" . to_owned ( ) ) + "/rust" ;
23
- let josh_port = 42042 ;
24
23
25
24
Ok ( Self {
26
25
upstream_url : format ! ( "https://github.com/{upstream_repo}/" ) ,
27
26
upstream_repo,
28
27
upstream_ref : env:: var ( "UPSTREAM_REF" ) . unwrap_or_else ( |_| "HEAD" . to_owned ( ) ) ,
29
28
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}" ) ,
32
30
} )
33
31
}
34
32
@@ -52,7 +50,7 @@ impl GitSync {
52
50
self . ensure_clean ( ) ;
53
51
54
52
// Make sure josh is running.
55
- let _josh = self . start_josh ( ) ;
53
+ let _josh = Josh :: start ( ) ;
56
54
let josh_url_filtered = self . josh_url (
57
55
& self . upstream_repo ,
58
56
Some ( & new_upstream_base) ,
@@ -182,7 +180,7 @@ impl GitSync {
182
180
. to_string ( ) ;
183
181
184
182
// Make sure josh is running.
185
- let _josh = self . start_josh ( ) ;
183
+ let _josh = Josh :: start ( ) ;
186
184
187
185
// Prepare the branch. Pushing works much better if we use as base exactly
188
186
// the commit that we pulled from last time, so we use the `rust-version`
@@ -245,10 +243,6 @@ impl GitSync {
245
243
) ;
246
244
}
247
245
248
- fn start_josh ( & self ) -> impl Drop {
249
- Josh :: start ( self . josh_port )
250
- }
251
-
252
246
/// Construct a url to the local Josh server with (optionally)
253
247
fn josh_url ( & self , repo : & str , rev : Option < & str > , filter : Option < & str > ) -> String {
254
248
format ! (
@@ -301,10 +295,10 @@ impl GitSync {
301
295
}
302
296
303
297
/// Create a wrapper that stops Josh on drop.
304
- struct Josh ( process:: Child ) ;
298
+ pub struct Josh ( process:: Child ) ;
305
299
306
300
impl Josh {
307
- fn start ( port : u16 ) -> Self {
301
+ pub fn start ( ) -> Self {
308
302
// Determine cache directory.
309
303
let local_dir = {
310
304
let user_dirs =
@@ -318,7 +312,7 @@ impl Josh {
318
312
. arg ( local_dir)
319
313
. args ( [
320
314
"--remote=https://github.com" ,
321
- & format ! ( "--port={port }" ) ,
315
+ & format ! ( "--port={JOSH_PORT }" ) ,
322
316
"--no-background" ,
323
317
] )
324
318
. stdout ( Stdio :: null ( ) )
@@ -329,10 +323,11 @@ impl Josh {
329
323
// Wait until the port is open. We try every 10ms until 1s passed.
330
324
for _ in 0 ..100 {
331
325
// 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 ) ) ;
333
327
let josh_ready = TcpStream :: connect_timeout ( & addr, Duration :: from_millis ( 1 ) ) ;
334
328
335
329
if josh_ready. is_ok ( ) {
330
+ println ! ( "josh up and running" ) ;
336
331
return Josh ( josh) ;
337
332
}
338
333
0 commit comments