1
1
use std:: net:: { SocketAddr , TcpStream } ;
2
- use std:: path:: PathBuf ;
3
2
use std:: process:: { Command , Stdio , exit} ;
4
3
use std:: time:: Duration ;
5
4
use std:: { env, fs, process, thread} ;
6
5
7
6
const DEFAULT_PR_BRANCH : & str = "update-builtins" ;
8
7
9
8
pub struct GitSync {
10
- dir : PathBuf ,
11
9
upstream_repo : String ,
12
10
upstream_ref : String ,
13
11
upstream_url : String ,
@@ -16,16 +14,15 @@ pub struct GitSync {
16
14
josh_url_base : String ,
17
15
}
18
16
19
- /// This code was adapted from the miri repository
20
- /// (https://github.com/rust-lang/miri/blob/6a68a79f38064c3bc30617cca4bdbfb2c336b140/miri-script/src/commands.rs#L236).
17
+ /// This code was adapted from the miri repository, via the rustc-dev-guide
18
+ /// (https://github.com/rust-lang/rustc-dev-guide/tree/c51adbd12d/josh-sync)
21
19
impl GitSync {
22
20
pub fn from_current_dir ( ) -> anyhow:: Result < Self > {
23
21
let upstream_repo =
24
22
env:: var ( "UPSTREAM_ORG" ) . unwrap_or_else ( |_| "rust-lang" . to_owned ( ) ) + "/rust" ;
25
23
let josh_port = 42042 ;
26
24
27
25
Ok ( Self {
28
- dir : std:: env:: current_dir ( ) ?,
29
26
upstream_url : format ! ( "https://github.com/{upstream_repo}/" ) ,
30
27
upstream_repo,
31
28
upstream_ref : env:: var ( "UPSTREAM_REF" ) . unwrap_or_else ( |_| "HEAD" . to_owned ( ) ) ,
@@ -260,6 +257,7 @@ impl GitSync {
260
257
)
261
258
}
262
259
260
+ /// Fail if there are files that need to be checked in.
263
261
fn ensure_clean ( & self ) {
264
262
let read = self . read ( [ "git" , "status" , "--untracked-files=no" , "--porcelain" ] ) ;
265
263
assert ! (
@@ -268,24 +266,28 @@ impl GitSync {
268
266
)
269
267
}
270
268
269
+ /// Run a command from an array, passing its output through.
271
270
fn run < ' a , Args : AsRef < [ & ' a str ] > > ( & self , l : Args ) {
272
271
let l = l. as_ref ( ) ;
273
272
self . run_args ( l[ 0 ] , |c| c. args ( & l[ 1 ..] ) )
274
273
}
275
274
276
- fn run_args ( & self , prog : & str , f : impl FnOnce ( & mut Command ) -> & mut Command ) {
277
- // self.read(l.as_ref());
278
- self . read_args ( prog, |c| f ( c. stdout ( Stdio :: inherit ( ) ) ) ) ;
279
- }
280
-
275
+ /// Run a command from an array, collecting its output.
281
276
fn read < ' a , Args : AsRef < [ & ' a str ] > > ( & self , l : Args ) -> String {
282
277
let l = l. as_ref ( ) ;
283
278
self . read_args ( l[ 0 ] , |c| c. args ( & l[ 1 ..] ) )
284
279
}
285
280
281
+ /// [`run`] with configuration.
282
+ fn run_args ( & self , prog : & str , f : impl FnOnce ( & mut Command ) -> & mut Command ) {
283
+ // self.read(l.as_ref());
284
+ self . read_args ( prog, |c| f ( c. stdout ( Stdio :: inherit ( ) ) ) ) ;
285
+ }
286
+
287
+ /// [`read`] with configuration. All shell helpers print the command and pass stderr.
286
288
fn read_args ( & self , prog : & str , f : impl FnOnce ( & mut Command ) -> & mut Command ) -> String {
287
289
let mut cmd = Command :: new ( prog) ;
288
- cmd. current_dir ( & self . dir ) . stderr ( Stdio :: inherit ( ) ) ;
290
+ cmd. stderr ( Stdio :: inherit ( ) ) ;
289
291
f ( & mut cmd) ;
290
292
eprintln ! ( "+ {cmd:?}" ) ;
291
293
let out = cmd. output ( ) . expect ( "command failed" ) ;
0 commit comments