Skip to content

Commit 34a2496

Browse files
committed
Support specify timings in .cargo/config
Signed-off-by: hi-rustin <[email protected]>
1 parent 17d4db0 commit 34a2496

37 files changed

+337
-58
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,58 @@ pub trait ArgMatchesExt {
379379
self._values_of("target")
380380
}
381381

382+
fn get_timing_outputs(&self, config: &Config) -> CargoResult<Vec<TimingOutput>> {
383+
let mut timing_outputs = Vec::new();
384+
// If `--timings' flag exists, override the configured timings value.
385+
if self._contains("timings") {
386+
for timing_output in self._values_of("timings") {
387+
for timing_output in timing_output.split(',') {
388+
let timing_output = timing_output.to_ascii_lowercase();
389+
let timing_output = match timing_output.as_str() {
390+
"html" => {
391+
config
392+
.cli_unstable()
393+
.fail_if_stable_opt("--timings=html", 7405)?;
394+
TimingOutput::Html
395+
}
396+
"json" => {
397+
config
398+
.cli_unstable()
399+
.fail_if_stable_opt("--timings=json", 7405)?;
400+
TimingOutput::Json
401+
}
402+
s => bail!("invalid timings output specifier: `{}`", s),
403+
};
404+
timing_outputs.push(timing_output);
405+
}
406+
}
407+
// If there is no timings value, the default value is used.
408+
if timing_outputs.is_empty() {
409+
return Ok(vec![TimingOutput::Html]);
410+
}
411+
} else {
412+
let build_config = config.build_config()?;
413+
if let Some(config_timing_outputs) = &build_config.timings {
414+
for timing_output in config_timing_outputs {
415+
let timing_output = timing_output.to_ascii_lowercase();
416+
let timing_output = match timing_output.as_str() {
417+
"html" => TimingOutput::Html,
418+
"json" => {
419+
config
420+
.cli_unstable()
421+
.fail_if_stable_opt("--timings=json", 7405)?;
422+
TimingOutput::Json
423+
}
424+
s => bail!("invalid timings output configuration: `{}`", s),
425+
};
426+
timing_outputs.push(timing_output);
427+
}
428+
}
429+
}
430+
431+
Ok(timing_outputs)
432+
}
433+
382434
fn get_profile_name(
383435
&self,
384436
config: &Config,
@@ -532,33 +584,7 @@ pub trait ArgMatchesExt {
532584
build_config.build_plan = self.flag("build-plan");
533585
build_config.unit_graph = self.flag("unit-graph");
534586
build_config.future_incompat_report = self.flag("future-incompat-report");
535-
536-
if self._contains("timings") {
537-
for timing_output in self._values_of("timings") {
538-
for timing_output in timing_output.split(',') {
539-
let timing_output = timing_output.to_ascii_lowercase();
540-
let timing_output = match timing_output.as_str() {
541-
"html" => {
542-
config
543-
.cli_unstable()
544-
.fail_if_stable_opt("--timings=html", 7405)?;
545-
TimingOutput::Html
546-
}
547-
"json" => {
548-
config
549-
.cli_unstable()
550-
.fail_if_stable_opt("--timings=json", 7405)?;
551-
TimingOutput::Json
552-
}
553-
s => bail!("invalid timings output specifier: `{}`", s),
554-
};
555-
build_config.timing_outputs.push(timing_output);
556-
}
557-
}
558-
if build_config.timing_outputs.is_empty() {
559-
build_config.timing_outputs.push(TimingOutput::Html);
560-
}
561-
}
587+
build_config.timing_outputs = self.get_timing_outputs(config)?;
562588

563589
if build_config.keep_going {
564590
config

src/cargo/util/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,7 @@ pub struct CargoBuildConfig {
22012201
pub rustc: Option<ConfigRelativePath>,
22022202
pub rustdoc: Option<ConfigRelativePath>,
22032203
pub out_dir: Option<ConfigRelativePath>,
2204+
pub timings: Option<Vec<String>>,
22042205
}
22052206

22062207
/// Configuration for `build.target`.

src/doc/man/generated_txt/cargo-bench.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ OPTIONS
235235
comma-separated list of output formats; --timings without an
236236
argument will default to --timings=html. Specifying an output format
237237
(rather than the default) is unstable and requires
238-
-Zunstable-options. Valid output formats:
238+
-Zunstable-options. May also be specified with the build.timings
239+
config value
240+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
241+
output formats:
239242

240243
o html: Write a human-readable file cargo-timing.html to the
241244
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-build.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ OPTIONS
171171
comma-separated list of output formats; --timings without an
172172
argument will default to --timings=html. Specifying an output format
173173
(rather than the default) is unstable and requires
174-
-Zunstable-options. Valid output formats:
174+
-Zunstable-options. May also be specified with the build.timings
175+
config value
176+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
177+
output formats:
175178

176179
o html: Write a human-readable file cargo-timing.html to the
177180
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-check.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ OPTIONS
175175
comma-separated list of output formats; --timings without an
176176
argument will default to --timings=html. Specifying an output format
177177
(rather than the default) is unstable and requires
178-
-Zunstable-options. Valid output formats:
178+
-Zunstable-options. May also be specified with the build.timings
179+
config value
180+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
181+
output formats:
179182

180183
o html: Write a human-readable file cargo-timing.html to the
181184
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-doc.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ OPTIONS
146146
comma-separated list of output formats; --timings without an
147147
argument will default to --timings=html. Specifying an output format
148148
(rather than the default) is unstable and requires
149-
-Zunstable-options. Valid output formats:
149+
-Zunstable-options. May also be specified with the build.timings
150+
config value
151+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
152+
output formats:
150153

151154
o html: Write a human-readable file cargo-timing.html to the
152155
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-fix.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ OPTIONS
248248
comma-separated list of output formats; --timings without an
249249
argument will default to --timings=html. Specifying an output format
250250
(rather than the default) is unstable and requires
251-
-Zunstable-options. Valid output formats:
251+
-Zunstable-options. May also be specified with the build.timings
252+
config value
253+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
254+
output formats:
252255

253256
o html: Write a human-readable file cargo-timing.html to the
254257
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-install.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ OPTIONS
211211
comma-separated list of output formats; --timings without an
212212
argument will default to --timings=html. Specifying an output format
213213
(rather than the default) is unstable and requires
214-
-Zunstable-options. Valid output formats:
214+
-Zunstable-options. May also be specified with the build.timings
215+
config value
216+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
217+
output formats:
215218

216219
o html: Write a human-readable file cargo-timing.html to the
217220
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-run.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ OPTIONS
9191
comma-separated list of output formats; --timings without an
9292
argument will default to --timings=html. Specifying an output format
9393
(rather than the default) is unstable and requires
94-
-Zunstable-options. Valid output formats:
94+
-Zunstable-options. May also be specified with the build.timings
95+
config value
96+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
97+
output formats:
9598

9699
o html: Write a human-readable file cargo-timing.html to the
97100
target/cargo-timings directory with a report of the compilation.

src/doc/man/generated_txt/cargo-rustc.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ OPTIONS
179179
comma-separated list of output formats; --timings without an
180180
argument will default to --timings=html. Specifying an output format
181181
(rather than the default) is unstable and requires
182-
-Zunstable-options. Valid output formats:
182+
-Zunstable-options. May also be specified with the build.timings
183+
config value
184+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
185+
output formats:
183186

184187
o html: Write a human-readable file cargo-timing.html to the
185188
target/cargo-timings directory with a report of the compilation.

0 commit comments

Comments
 (0)