1
1
use std:: env;
2
2
use std:: ffi:: { OsStr , OsString } ;
3
3
use std:: io:: Write ;
4
+ use std:: net;
4
5
use std:: ops:: Not ;
5
6
use std:: ops:: Range ;
6
7
use std:: path:: PathBuf ;
7
8
use std:: process;
8
- use std:: thread;
9
- use std:: time;
9
+ use std:: time:: Duration ;
10
10
11
11
use anyhow:: { anyhow, bail, Context , Result } ;
12
12
use path_macro:: path;
@@ -19,7 +19,7 @@ use crate::Command;
19
19
/// Used for rustc syncs.
20
20
const JOSH_FILTER : & str =
21
21
":rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri" ;
22
- const JOSH_PORT : & str = " 42042" ;
22
+ const JOSH_PORT : u16 = 42042 ;
23
23
24
24
impl MiriEnv {
25
25
/// Returns the location of the sysroot.
@@ -105,13 +105,11 @@ impl Command {
105
105
let mut cmd = process:: Command :: new ( "josh-proxy" ) ;
106
106
cmd. arg ( "--local" ) . arg ( local_dir) ;
107
107
cmd. arg ( "--remote" ) . arg ( "https://github.com" ) ;
108
- cmd. arg ( "--port" ) . arg ( JOSH_PORT ) ;
108
+ cmd. arg ( "--port" ) . arg ( JOSH_PORT . to_string ( ) ) ;
109
109
cmd. arg ( "--no-background" ) ;
110
110
cmd. stdout ( process:: Stdio :: null ( ) ) ;
111
111
cmd. stderr ( process:: Stdio :: null ( ) ) ;
112
112
let josh = cmd. spawn ( ) . context ( "failed to start josh-proxy, make sure it is installed" ) ?;
113
- // Give it some time so hopefully the port is open. (100ms was not enough.)
114
- thread:: sleep ( time:: Duration :: from_millis ( 200 ) ) ;
115
113
116
114
// Create a wrapper that stops it on drop.
117
115
struct Josh ( process:: Child ) ;
@@ -125,7 +123,7 @@ impl Command {
125
123
. output ( )
126
124
. expect ( "failed to SIGINT josh-proxy" ) ;
127
125
// Sadly there is no "wait with timeout"... so we just give it some time to finish.
128
- thread:: sleep ( time :: Duration :: from_millis ( 100 ) ) ;
126
+ std :: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
129
127
// Now hopefully it is gone.
130
128
if self . 0 . try_wait ( ) . expect ( "failed to wait for josh-proxy" ) . is_some ( ) {
131
129
return ;
@@ -139,6 +137,14 @@ impl Command {
139
137
}
140
138
}
141
139
140
+ // Wait until the port is open.
141
+ let josh_ready = net:: TcpStream :: connect_timeout (
142
+ & net:: SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , JOSH_PORT ) ) ,
143
+ Duration :: from_secs ( 1 ) ,
144
+ )
145
+ . context ( "failed to connect to josh-proxy" ) ?;
146
+ drop ( josh_ready) ;
147
+
142
148
Ok ( Josh ( josh) )
143
149
}
144
150
@@ -236,6 +242,8 @@ impl Command {
236
242
}
237
243
// Make sure josh is running.
238
244
let josh = Self :: start_josh ( ) ?;
245
+ let josh_url =
246
+ format ! ( "http://localhost:{JOSH_PORT}/rust-lang/rust.git@{commit}{JOSH_FILTER}.git" ) ;
239
247
240
248
// Update rust-version file. As a separate commit, since making it part of
241
249
// the merge has confused the heck out of josh in the past.
@@ -250,7 +258,7 @@ impl Command {
250
258
. context ( "FAILED to commit rust-version file, something went wrong" ) ?;
251
259
252
260
// Fetch given rustc commit.
253
- cmd ! ( sh, "git fetch http://localhost:{JOSH_PORT}/rust-lang/rust.git@{commit}{JOSH_FILTER}.git " )
261
+ cmd ! ( sh, "git fetch {josh_url} " )
254
262
. run ( )
255
263
. inspect_err ( |_| {
256
264
// Try to un-do the previous `git commit`, to leave the repo in the state we found it.
@@ -294,6 +302,8 @@ impl Command {
294
302
}
295
303
// Make sure josh is running.
296
304
let josh = Self :: start_josh ( ) ?;
305
+ let josh_url =
306
+ format ! ( "http://localhost:{JOSH_PORT}/{github_user}/rust.git{JOSH_FILTER}.git" ) ;
297
307
298
308
// Find a repo we can do our preparation in.
299
309
if let Ok ( rustc_git) = env:: var ( "RUSTC_GIT" ) {
@@ -338,20 +348,11 @@ impl Command {
338
348
// Do the actual push.
339
349
sh. change_dir ( miri_dir ( ) ?) ;
340
350
println ! ( "Pushing miri changes..." ) ;
341
- cmd ! (
342
- sh,
343
- "git push http://localhost:{JOSH_PORT}/{github_user}/rust.git{JOSH_FILTER}.git HEAD:{branch}"
344
- )
345
- . run ( ) ?;
351
+ cmd ! ( sh, "git push {josh_url} HEAD:{branch}" ) . run ( ) ?;
346
352
println ! ( ) ;
347
353
348
354
// Do a round-trip check to make sure the push worked as expected.
349
- cmd ! (
350
- sh,
351
- "git fetch http://localhost:{JOSH_PORT}/{github_user}/rust.git{JOSH_FILTER}.git {branch}"
352
- )
353
- . ignore_stderr ( )
354
- . read ( ) ?;
355
+ cmd ! ( sh, "git fetch {josh_url} {branch}" ) . ignore_stderr ( ) . read ( ) ?;
355
356
let head = cmd ! ( sh, "git rev-parse HEAD" ) . read ( ) ?;
356
357
let fetch_head = cmd ! ( sh, "git rev-parse FETCH_HEAD" ) . read ( ) ?;
357
358
if head != fetch_head {
0 commit comments