-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(cli/rustup-mode): add rustup ci subcommand
#5021
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?
Changes from all commits
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,54 @@ | ||
| use std::{fmt, io::Write}; | ||
|
|
||
| use anyhow::Result; | ||
| use clap::{ValueEnum, builder::PossibleValue}; | ||
|
|
||
| use crate::{config::Cfg, utils::ExitCode}; | ||
|
|
||
| pub(crate) fn env(cfg: &Cfg<'_>) -> Result<ExitCode> { | ||
| print_str(include_str!("ci/base.env"), cfg) | ||
| } | ||
|
|
||
| pub(crate) fn problem_matcher(flavor: Flavor, cfg: &Cfg<'_>) -> Result<ExitCode> { | ||
| print_str(flavor.problem_matcher(), cfg) | ||
| } | ||
|
|
||
| fn print_str(s: &str, cfg: &Cfg<'_>) -> Result<ExitCode> { | ||
| let stdout = cfg.process.stdout(); | ||
| write!(stdout.lock(), "{s}")?; | ||
| Ok(ExitCode::SUCCESS) | ||
| } | ||
|
|
||
| #[derive(Copy, Clone, Debug, PartialEq)] | ||
| pub(crate) enum Flavor { | ||
| Github, | ||
| } | ||
|
|
||
| impl Flavor { | ||
| fn problem_matcher(&self) -> &'static str { | ||
| match self { | ||
| Self::Github => include_str!("ci/matcher/github.json"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl ValueEnum for Flavor { | ||
| fn value_variants<'a>() -> &'a [Self] { | ||
| &[Self::Github] | ||
| } | ||
|
|
||
| fn to_possible_value<'a>(&self) -> Option<PossibleValue> { | ||
| Some(match self { | ||
| Self::Github => PossibleValue::new("github"), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for Flavor { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self.to_possible_value() { | ||
| Some(v) => write!(f, "{}", v.get_name()), | ||
| None => unreachable!(), | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| CARGO_INCREMENTAL=0 | ||
| CARGO_PROFILE_DEV_DEBUG=0 | ||
| CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse | ||
| CARGO_TERM_COLOR=always | ||
|
Member
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. Will this command be used outside GitHub Actions? I know that GitHub Actions is good with ANSI color. |
||
| CARGO_UNSTABLE_SPARSE_REGISTRY=true | ||
|
Member
Author
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. As per https://github.com/actions-rust-lang/setup-rust-toolchain/blob/8439c15d249cd2e2a5c80ad3da200c3d8c553ae4/action.yml#L145-L149 this will be a no-op on cargo versions that don't support this flag. |
||
| RUST_BACKTRACE=short | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "problemMatcher": [ | ||
| { | ||
| "owner": "rust-compiler", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^(?:\\x1B\\[[0-9;]*[a-zA-Z])*(warning|warn|error)(\\[(\\S*)\\])?(?:\\x1B\\[[0-9;]*[a-zA-Z])*: (.*?)(?:\\x1B\\[[0-9;]*[a-zA-Z])*$", | ||
| "severity": 1, | ||
| "message": 4, | ||
| "code": 3 | ||
| }, | ||
| { | ||
| "regexp": "^(?:\\x1B\\[[0-9;]*[a-zA-Z])*\\s+(?:\\x1B\\[[0-9;]*[a-zA-Z])*-->\\s(?:\\x1B\\[[0-9;]*[a-zA-Z])*(\\S+):(\\d+):(\\d+)(?:\\x1B\\[[0-9;]*[a-zA-Z])*$", | ||
| "file": 1, | ||
| "line": 2, | ||
| "column": 3 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "owner": "rust-formatter", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^(Diff in (\\S+)) at line (\\d+):", | ||
| "message": 1, | ||
| "file": 2, | ||
| "line": 3 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "owner": "rust-panic", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^.*panicked\\s+at\\s+'(.*)',\\s+(.*):(\\d+):(\\d+)$", | ||
| "message": 1, | ||
| "file": 2, | ||
| "line": 3, | ||
| "column": 4 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle}; | |
|
|
||
| use crate::{ | ||
| cli::{ | ||
| ci, | ||
| common::{self, PackageUpdate, update_console_filter}, | ||
| docs, | ||
| errors::CliError, | ||
|
|
@@ -296,6 +297,13 @@ enum RustupSubcmd { | |
| #[arg(default_value = "rustup")] | ||
| command: CompletionCommand, | ||
| }, | ||
|
|
||
| /// Generate CI-specific configurations | ||
| #[command(hide = true)] | ||
| Ci { | ||
| #[command(subcommand)] | ||
| subcmd: CiSubcmd, | ||
| }, | ||
| } | ||
|
|
||
| fn update_toolchain_value_parser(s: &str) -> Result<PartialToolchainDesc> { | ||
|
|
@@ -318,6 +326,7 @@ impl RustupSubcmd { | |
| // These subcommands don't require the active toolchain, so auto-installing it should be | ||
| // disabled to avoid surprises. | ||
| Self::Check { .. } | ||
| | Self::Ci { .. } | ||
| | Self::Completions { .. } | ||
| | Self::Component { .. } | ||
| | Self::Default { .. } | ||
|
|
@@ -344,6 +353,7 @@ impl RustupSubcmd { | |
| // For all other subcommands, the hint may be useful if rustup is still unusable after | ||
| // the command has completed. | ||
| Self::Check { .. } | ||
| | Self::Ci { .. } | ||
|
Contributor
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. I believe that this new sub-command should belong to the If I am not overlooking anything, it seems that one can run
Member
Author
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. @FranciscoTGouveia Good catch! Actually, however, it depends on how https://github.com/rust-lang/rustup/pull/5021/changes#r3843602435 should be addressed so it's still a bit hard to say... If it involves determining the active |
||
| | Self::Component { .. } | ||
| | Self::Default { .. } | ||
| | Self::Doc { .. } | ||
|
|
@@ -666,6 +676,20 @@ enum SetSubcmd { | |
| }, | ||
| } | ||
|
|
||
| #[derive(Debug, Subcommand)] | ||
| #[command(arg_required_else_help = true, subcommand_required = true)] | ||
| enum CiSubcmd { | ||
| /// Show the recommended environment variables in `.env` format | ||
| Env, | ||
|
|
||
| /// Show the example problem matcher for the given CI flavor | ||
| #[command(alias = "matcher")] | ||
| ProblemMatcher { | ||
| #[arg(value_enum)] | ||
| flavor: ci::Flavor, | ||
| }, | ||
| } | ||
|
|
||
| #[tracing::instrument(level = "trace", fields(args = format!("{:?}", process.args_os().collect::<Vec<_>>())), skip(process, console_filter))] | ||
| pub async fn main( | ||
| current_dir: PathBuf, | ||
|
|
@@ -857,6 +881,10 @@ pub async fn main( | |
| RustupSubcmd::Completions { shell, command } => { | ||
| output_completion_script(shell, command, process) | ||
| } | ||
| RustupSubcmd::Ci { subcmd } => match subcmd { | ||
| CiSubcmd::Env => ci::env(cfg), | ||
| CiSubcmd::ProblemMatcher { flavor } => ci::problem_matcher(flavor, cfg), | ||
| }, | ||
| }?; | ||
|
|
||
| if should_warn && cfg.list_toolchains()?.is_empty() && cfg.get_default()?.is_none() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
@weihanglo Is it safe to always set this flag similarly to #5021 (comment)?
View changes since the review
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.
For incremental I think so. Cargo shipped a similar thing recently: rust-lang/cargo#17220
For profile dev debug, Cargo will have a new debug profile and we planned to turn off debug for dev profile:
rust-lang/cargo#17214. So, the direction looks pretty aligned.
For registry protocol, we may want to test if there is any version treating it as a hard error if not recognized. I believe no but worth a double check.
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.
probably could test pre-1.61 1.61 to 1.68, and post 1.68