Skip to content

Commit 0703bc6

Browse files
committed
update
1 parent 2939459 commit 0703bc6

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

library/compiler-builtins/crates/josh-sync/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ edition = "2024"
44
publish = false
55

66
[dependencies]
7-
anyhow = "1.0.98"
87
directories = "6.0.0"

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::env;
1+
use std::io::{Read, Write};
22
use std::process::exit;
3+
use std::{env, io};
34

4-
use crate::sync::GitSync;
5+
use crate::sync::{GitSync, Josh};
56

67
mod sync;
78

@@ -19,7 +20,7 @@ Usage:
1920
Create a branch off of rust-lang/rust updating compiler-builtins.
2021
"#;
2122

22-
fn main() -> anyhow::Result<()> {
23+
fn main() {
2324
let sync = GitSync::from_current_dir()?;
2425

2526
// Collect args, then recollect as str refs so we can match on them
@@ -30,10 +31,15 @@ fn main() -> anyhow::Result<()> {
3031
["rustc-pull"] => sync.rustc_pull(None),
3132
["rustc-push", github_user, branch] => sync.rustc_push(github_user, Some(branch)),
3233
["rustc-push", github_user] => sync.rustc_push(github_user, None),
34+
["start-josh"] => {
35+
let _josh = Josh::start();
36+
println!("press enter to stop");
37+
io::stdout().flush().unwrap();
38+
let _ = io::stdin().read(&mut [0u8]).unwrap();
39+
}
3340
_ => {
3441
println!("{USAGE}");
3542
exit(1);
3643
}
3744
}
38-
Ok(())
3945
}

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use std::process::{Command, Stdio, exit};
33
use std::time::Duration;
44
use std::{env, fs, process, thread};
55

6+
const JOSH_PORT: u16 = 42042;
67
const DEFAULT_PR_BRANCH: &str = "update-builtins";
78

89
pub 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

306300
impl 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

Comments
 (0)