Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change argument handling in remote-test-server and add new flags #102193

Merged
merged 4 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Change the names for `dist` commands to match the component they generate. [#90684](https://github.com/rust-lang/rust/pull/90684)
- The `build.fast-submodules` option has been removed. Fast submodule checkouts are enabled unconditionally. Automatic submodule handling can still be disabled with `build.submodules = false`.
- Several unsupported `./configure` options have been removed: `optimize`, `parallel-compiler`. These can still be enabled with `--set`, although it isn't recommended.
- `remote-test-server`'s `verbose` argument has been removed in favor of the `--verbose` flag
- `remote-test-server`'s `remote` argument has been removed in favor of the `--bind` flag. Use `--bind 0.0.0.0:12345` to replicate the behavior of the `remote` argument.

### Non-breaking changes

Expand Down
48 changes: 31 additions & 17 deletions src/tools/remote-test-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#[cfg(not(windows))]
use std::fs::Permissions;
use std::net::SocketAddr;
#[cfg(not(windows))]
use std::os::unix::prelude::*;

Expand Down Expand Up @@ -41,30 +42,44 @@ static TEST: AtomicUsize = AtomicUsize::new(0);

#[derive(Copy, Clone)]
struct Config {
pub remote: bool,
pub verbose: bool,
verbose: bool,
sequential: bool,
bind: SocketAddr,
}

impl Config {
pub fn default() -> Config {
Config { remote: false, verbose: false }
Config {
verbose: false,
sequential: false,
bind: if cfg!(target_os = "android") || cfg!(windows) {
([0, 0, 0, 0], 12345).into()
} else {
([10, 0, 2, 15], 12345).into()
},
}
}

pub fn parse_args() -> Config {
let mut config = Config::default();

let args = env::args().skip(1);
let mut next_is_bind = false;
for argument in args {
match &argument[..] {
"remote" => {
config.remote = true;
}
"verbose" | "-v" => {
config.verbose = true;
bind if next_is_bind => {
config.bind = t!(bind.parse());
next_is_bind = false;
}
"--bind" => next_is_bind = true,
"--sequential" => config.sequential = true,
"--verbose" | "-v" => config.verbose = true,
arg => panic!("unknown argument: {}", arg),
}
}
if next_is_bind {
panic!("missing value for --bind");
}

config
}
Expand All @@ -81,13 +96,7 @@ fn main() {

let config = Config::parse_args();

let bind_addr = if cfg!(target_os = "android") || cfg!(windows) || config.remote {
"0.0.0.0:12345"
} else {
"10.0.2.15:12345"
};

let listener = t!(TcpListener::bind(bind_addr));
let listener = t!(TcpListener::bind(config.bind));
let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") {
("/data/tmp/work".into(), "/data/tmp/work/tmp".into())
} else {
Expand All @@ -97,7 +106,7 @@ fn main() {
tmp_dir.push("tmp");
(work_dir, tmp_dir)
};
println!("listening on {}!", bind_addr);
println!("listening on {}!", config.bind);

t!(fs::create_dir_all(&work));
t!(fs::create_dir_all(&tmp));
Expand All @@ -119,7 +128,12 @@ fn main() {
let lock = lock.clone();
let work = work.clone();
let tmp = tmp.clone();
thread::spawn(move || handle_run(socket, &work, &tmp, &lock, config));
let f = move || handle_run(socket, &work, &tmp, &lock, config);
if config.sequential {
f();
} else {
thread::spawn(f);
}
} else {
panic!("unknown command {:?}", buf);
}
Expand Down