Skip to content

Commit a321c71

Browse files
committed
update
1 parent 6249a2e commit a321c71

File tree

1 file changed

+13
-11
lines changed
  • library/compiler-builtins/crates/josh-sync/src

1 file changed

+13
-11
lines changed

library/compiler-builtins/crates/josh-sync/src/sync.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::net::{SocketAddr, TcpStream};
2-
use std::path::PathBuf;
32
use std::process::{Command, Stdio, exit};
43
use std::time::Duration;
54
use std::{env, fs, process, thread};
65

76
const DEFAULT_PR_BRANCH: &str = "update-builtins";
87

98
pub struct GitSync {
10-
dir: PathBuf,
119
upstream_repo: String,
1210
upstream_ref: String,
1311
upstream_url: String,
@@ -16,16 +14,15 @@ pub struct GitSync {
1614
josh_url_base: String,
1715
}
1816

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)
2119
impl GitSync {
2220
pub fn from_current_dir() -> anyhow::Result<Self> {
2321
let upstream_repo =
2422
env::var("UPSTREAM_ORG").unwrap_or_else(|_| "rust-lang".to_owned()) + "/rust";
2523
let josh_port = 42042;
2624

2725
Ok(Self {
28-
dir: std::env::current_dir()?,
2926
upstream_url: format!("https://github.com/{upstream_repo}/"),
3027
upstream_repo,
3128
upstream_ref: env::var("UPSTREAM_REF").unwrap_or_else(|_| "HEAD".to_owned()),
@@ -260,6 +257,7 @@ impl GitSync {
260257
)
261258
}
262259

260+
/// Fail if there are files that need to be checked in.
263261
fn ensure_clean(&self) {
264262
let read = self.read(["git", "status", "--untracked-files=no", "--porcelain"]);
265263
assert!(
@@ -268,24 +266,28 @@ impl GitSync {
268266
)
269267
}
270268

269+
/// Run a command from an array, passing its output through.
271270
fn run<'a, Args: AsRef<[&'a str]>>(&self, l: Args) {
272271
let l = l.as_ref();
273272
self.run_args(l[0], |c| c.args(&l[1..]))
274273
}
275274

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.
281276
fn read<'a, Args: AsRef<[&'a str]>>(&self, l: Args) -> String {
282277
let l = l.as_ref();
283278
self.read_args(l[0], |c| c.args(&l[1..]))
284279
}
285280

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.
286288
fn read_args(&self, prog: &str, f: impl FnOnce(&mut Command) -> &mut Command) -> String {
287289
let mut cmd = Command::new(prog);
288-
cmd.current_dir(&self.dir).stderr(Stdio::inherit());
290+
cmd.stderr(Stdio::inherit());
289291
f(&mut cmd);
290292
eprintln!("+ {cmd:?}");
291293
let out = cmd.output().expect("command failed");

0 commit comments

Comments
 (0)