Skip to content

Commit

Permalink
Support specify timings in .cargo/config
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Jun 18, 2022
1 parent 17d4db0 commit 34a2496
Show file tree
Hide file tree
Showing 37 changed files with 337 additions and 58 deletions.
80 changes: 53 additions & 27 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,58 @@ pub trait ArgMatchesExt {
self._values_of("target")
}

fn get_timing_outputs(&self, config: &Config) -> CargoResult<Vec<TimingOutput>> {
let mut timing_outputs = Vec::new();
// If `--timings' flag exists, override the configured timings value.
if self._contains("timings") {
for timing_output in self._values_of("timings") {
for timing_output in timing_output.split(',') {
let timing_output = timing_output.to_ascii_lowercase();
let timing_output = match timing_output.as_str() {
"html" => {
config
.cli_unstable()
.fail_if_stable_opt("--timings=html", 7405)?;
TimingOutput::Html
}
"json" => {
config
.cli_unstable()
.fail_if_stable_opt("--timings=json", 7405)?;
TimingOutput::Json
}
s => bail!("invalid timings output specifier: `{}`", s),
};
timing_outputs.push(timing_output);
}
}
// If there is no timings value, the default value is used.
if timing_outputs.is_empty() {
return Ok(vec![TimingOutput::Html]);
}
} else {
let build_config = config.build_config()?;
if let Some(config_timing_outputs) = &build_config.timings {
for timing_output in config_timing_outputs {
let timing_output = timing_output.to_ascii_lowercase();
let timing_output = match timing_output.as_str() {
"html" => TimingOutput::Html,
"json" => {
config
.cli_unstable()
.fail_if_stable_opt("--timings=json", 7405)?;
TimingOutput::Json
}
s => bail!("invalid timings output configuration: `{}`", s),
};
timing_outputs.push(timing_output);
}
}
}

Ok(timing_outputs)
}

fn get_profile_name(
&self,
config: &Config,
Expand Down Expand Up @@ -532,33 +584,7 @@ pub trait ArgMatchesExt {
build_config.build_plan = self.flag("build-plan");
build_config.unit_graph = self.flag("unit-graph");
build_config.future_incompat_report = self.flag("future-incompat-report");

if self._contains("timings") {
for timing_output in self._values_of("timings") {
for timing_output in timing_output.split(',') {
let timing_output = timing_output.to_ascii_lowercase();
let timing_output = match timing_output.as_str() {
"html" => {
config
.cli_unstable()
.fail_if_stable_opt("--timings=html", 7405)?;
TimingOutput::Html
}
"json" => {
config
.cli_unstable()
.fail_if_stable_opt("--timings=json", 7405)?;
TimingOutput::Json
}
s => bail!("invalid timings output specifier: `{}`", s),
};
build_config.timing_outputs.push(timing_output);
}
}
if build_config.timing_outputs.is_empty() {
build_config.timing_outputs.push(TimingOutput::Html);
}
}
build_config.timing_outputs = self.get_timing_outputs(config)?;

if build_config.keep_going {
config
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,7 @@ pub struct CargoBuildConfig {
pub rustc: Option<ConfigRelativePath>,
pub rustdoc: Option<ConfigRelativePath>,
pub out_dir: Option<ConfigRelativePath>,
pub timings: Option<Vec<String>>,
}

/// Configuration for `build.target`.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-rustdoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:
-Zunstable-options. May also be specified with the build.timings
config value
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
output formats:

o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/includes/options-timings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma-separated list of output
formats; `--timings` without an argument will default to `--timings=html`.
Specifying an output format (rather than the default) is unstable and requires
`-Zunstable-options`. Valid output formats:
`-Zunstable-options`.
May also be specified with the `build.timings` [config value](../reference/config.html).
Valid output formats:

- `html`: Write a human-readable file `cargo-timing.html` to the
`target/cargo-timings` directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ See the <a href="../reference/profiles.html">the reference</a> for more details
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
information over time. Accepts an optional comma-separated list of output
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
Specifying an output format (rather than the default) is unstable and requires
<code>-Zunstable-options</code>. Valid output formats:</p>
<code>-Zunstable-options</code>.
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
Valid output formats:</p>
<ul>
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
<code>target/cargo-timings</code> directory with a report of the compilation. Also write
Expand Down
Loading

0 comments on commit 34a2496

Please sign in to comment.