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

Centralize custom cargo arguments in ./tools #231

Open
tcr opened this issue Dec 21, 2018 · 0 comments
Open

Centralize custom cargo arguments in ./tools #231

tcr opened this issue Dec 21, 2018 · 0 comments

Comments

@tcr
Copy link
Owner

tcr commented Dec 21, 2018

The source code of the ./tools command that runs build steps is found in "build-tools/src/main.rs". There are two variables, release and force_color, which are set at the beginning of the script. They are used to set the color output and release mode flags for all invocations to cargo that the build script performs. But repeating each of these arguments each time cargo is called is verbose and error-prone.

There's already a function that is called to generate arguments to be passed on to cargo, cargo_args_for_crate, which is used right now to load features options from the Configuration.toml file. If the logic for adding the "--release" flag and the "--color=always" flag were added to the vector of arguments cargo_args_for_crate returns, then there can be just one set of arguments injected into each cargo call in the script, and the variables release and force_color (and all the places where they are used) can be deleted.

let mut args = ::std::env::args().collect::<Vec<_>>();
// Extract the --release flag from the args list. We'll reuse the --release
// flag by injecting it into argumets for cargo.
let release = args.iter().find(|x| *x == "--release").is_some();
args = args.into_iter().filter(|x| *x != "--release").collect();
// Respect the CLICOLOR env variable.
let force_color = ::std::env::var("CLICOLOR")
.map(|x| x == "1")
.unwrap_or(false);
let force_color_flag = if force_color {
Some("--color=always")
} else {
None
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant