-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Xtask #2688
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
Xtask #2688
Changes from all commits
645c5d3
eeffce0
2cafbcd
d816202
00bacc5
c9fef6e
7839923
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,6 @@ members = [ | |
"src/unsafe-rust", | ||
"src/user-defined-types", | ||
"third_party/cxx/blobstore", | ||
"xtask", | ||
] | ||
resolver = "2" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "xtask" | ||
version = "0.1.0" | ||
edition = "2021" | ||
egithinji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{env, process::Command}; | ||
egithinji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
type DynError = Box<dyn std::error::Error>; | ||
egithinji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fn main() { | ||
if let Err(e) = execute_task() { | ||
eprintln!("{e}"); | ||
std::process::exit(-1); | ||
} | ||
} | ||
|
||
fn execute_task() -> Result<(), DynError> { | ||
let task = env::args().nth(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already depend on Clap, so you could use it here (feel free to do this in a later PR!). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have pushed a new PR (#2707) for this and the other suggestions. |
||
match task.as_deref() { | ||
Some("install-tools") => install_tools()?, | ||
_ => { | ||
return Err(Box::from(get_help_string(task.as_deref()))); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn install_tools() -> Result<(), DynError> { | ||
println!("Installing project tools..."); | ||
|
||
let install_args: Vec<Vec<&str>> = vec![ | ||
egithinji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// The --locked flag is important for reproducible builds. It also | ||
// avoids breakage due to skews between mdbook and mdbook-svgbob. | ||
vec!["mdbook", "--locked", "--version", "0.4.44"], | ||
vec!["mdbook-svgbob", "--locked", "--version", "0.2.1"], | ||
vec!["mdbook-pandoc", "--locked", "--version", "0.9.3"], | ||
vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.5"], | ||
vec!["i18n-report", "--locked", "--version", "0.2.0"], | ||
// These packages are located in this repository | ||
vec!["--path", "mdbook-exerciser", "--locked"], | ||
vec!["--path", "mdbook-course", "--locked"], | ||
]; | ||
|
||
for args in &install_args { | ||
let status = Command::new(env!("CARGO")) | ||
.arg("install") | ||
.args(args) | ||
.status() | ||
.expect("Failed to execute cargo install"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious: have you tested how the errors look if you provoke an error? Like by installing something which doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I tested manually the various scenarios (missing task, unkown task, and internal error e.g. typo 'mdbok instead of mdbook' in the install-tools logic). We get appropriate error messages and behaviour in each case. |
||
|
||
if !status.success() { | ||
let error_message = format!( | ||
"Command 'cargo install {}' exited with status code: {}", | ||
args.join(" "), | ||
status.code().unwrap() | ||
); | ||
return Err(Box::from(error_message)); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_help_string(task: Option<&str>) -> String { | ||
if let Some(t) = task { | ||
format!( | ||
"Unrecognized task '{t}'. Available tasks: | ||
|
||
install-tools Installs the tools the project depends on." | ||
) | ||
} else { | ||
"Missing task. To execute a task run `cargo xtask [task]`.".to_string() | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.