-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support setting language and output directory in cargo xtask #2776
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
base: main
Are you sure you want to change the base?
Conversation
…serve commands. In addition to simplifying building locally (no need to set an environment variable), this makes it possible to use the `cargo xtask build` command in the CI and specify any output location, rather than relying on the build.sh script.
xtask/src/main.rs
Outdated
|
||
/// Directory to place the build. If not provided, defaults to the book/ directory (or the book/xx directory if a language is provided). | ||
#[arg(short, long)] | ||
output: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use an Option<PathBuf>
for better semantics. If we want to do anything with the provided path we would get a lot of methods for free if we have the correct semantic type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks didn't know Clap could accept PathBuf! This is much better.
xtask/src/main.rs
Outdated
if let Some(d) = output { | ||
command.arg(d); | ||
} else { | ||
command.arg(format!("book/{}", language.unwrap_or("".to_string()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good candidate for a Path
otherwise we have directory separator issues e.g. with Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
xtask/src/main.rs
Outdated
@@ -176,15 +204,29 @@ fn start_web_server() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
fn build() -> Result<()> { | |||
fn build(language: Option<String>, output: Option<String>) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PathBuf for consistency with the commandline args
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
xtask/src/main.rs
Outdated
@@ -156,15 +170,29 @@ fn run_rust_tests() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
fn start_web_server() -> Result<()> { | |||
fn start_web_server(language: Option<String>, output: Option<String>) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output: Option<Pathbuf>
for consistency with the PathBuf in the arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
In addition to simplifying building locally (no need to set an environment variable), this makes it possible to use the
cargo xtask build
command in the CI and specify any output location, rather than relying on the build.sh script.