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.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ OPTIONS
162162
comma-separated list of output formats; --timings without an
163163
argument will default to --timings=html. Specifying an output format
164164
(rather than the default) is unstable and requires
165-
-Zunstable-options. Valid output formats:
165+
-Zunstable-options. May also be specified with the build.timings
166+
config value
167+
<https://doc.rust-lang.org/cargo/reference/config.html>. Valid
168+
output formats:
166169

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

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

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

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

src/doc/man/includes/options-timings.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Output information how long each compilation takes, and track concurrency
33
information over time. Accepts an optional comma-separated list of output
44
formats; `--timings` without an argument will default to `--timings=html`.
55
Specifying an output format (rather than the default) is unstable and requires
6-
`-Zunstable-options`. Valid output formats:
6+
`-Zunstable-options`.
7+
May also be specified with the `build.timings` [config value](../reference/config.html).
8+
Valid output formats:
79

810
- `html`: Write a human-readable file `cargo-timing.html` to the
911
`target/cargo-timings` directory with a report of the compilation. Also write

src/doc/src/commands/cargo-bench.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
281281
information over time. Accepts an optional comma-separated list of output
282282
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
283283
Specifying an output format (rather than the default) is unstable and requires
284-
<code>-Zunstable-options</code>. Valid output formats:</p>
284+
<code>-Zunstable-options</code>.
285+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
286+
Valid output formats:</p>
285287
<ul>
286288
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
287289
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-build.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
215215
information over time. Accepts an optional comma-separated list of output
216216
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
217217
Specifying an output format (rather than the default) is unstable and requires
218-
<code>-Zunstable-options</code>. Valid output formats:</p>
218+
<code>-Zunstable-options</code>.
219+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
220+
Valid output formats:</p>
219221
<ul>
220222
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
221223
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-check.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
214214
information over time. Accepts an optional comma-separated list of output
215215
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
216216
Specifying an output format (rather than the default) is unstable and requires
217-
<code>-Zunstable-options</code>. Valid output formats:</p>
217+
<code>-Zunstable-options</code>.
218+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
219+
Valid output formats:</p>
218220
<ul>
219221
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
220222
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-doc.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
188188
information over time. Accepts an optional comma-separated list of output
189189
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
190190
Specifying an output format (rather than the default) is unstable and requires
191-
<code>-Zunstable-options</code>. Valid output formats:</p>
191+
<code>-Zunstable-options</code>.
192+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
193+
Valid output formats:</p>
192194
<ul>
193195
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
194196
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-fix.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
294294
information over time. Accepts an optional comma-separated list of output
295295
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
296296
Specifying an output format (rather than the default) is unstable and requires
297-
<code>-Zunstable-options</code>. Valid output formats:</p>
297+
<code>-Zunstable-options</code>.
298+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
299+
Valid output formats:</p>
298300
<ul>
299301
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
300302
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-install.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ See the <a href="../reference/profiles.html">the reference</a> for more details
241241
information over time. Accepts an optional comma-separated list of output
242242
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
243243
Specifying an output format (rather than the default) is unstable and requires
244-
<code>-Zunstable-options</code>. Valid output formats:</p>
244+
<code>-Zunstable-options</code>.
245+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
246+
Valid output formats:</p>
245247
<ul>
246248
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
247249
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-run.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
123123
information over time. Accepts an optional comma-separated list of output
124124
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
125125
Specifying an output format (rather than the default) is unstable and requires
126-
<code>-Zunstable-options</code>. Valid output formats:</p>
126+
<code>-Zunstable-options</code>.
127+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
128+
Valid output formats:</p>
127129
<ul>
128130
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
129131
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-rustc.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
212212
information over time. Accepts an optional comma-separated list of output
213213
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
214214
Specifying an output format (rather than the default) is unstable and requires
215-
<code>-Zunstable-options</code>. Valid output formats:</p>
215+
<code>-Zunstable-options</code>.
216+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
217+
Valid output formats:</p>
216218
<ul>
217219
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
218220
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-rustdoc.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
207207
information over time. Accepts an optional comma-separated list of output
208208
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
209209
Specifying an output format (rather than the default) is unstable and requires
210-
<code>-Zunstable-options</code>. Valid output formats:</p>
210+
<code>-Zunstable-options</code>.
211+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
212+
Valid output formats:</p>
211213
<ul>
212214
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
213215
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

src/doc/src/commands/cargo-test.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ required Rust version as configured in the project's <code>rust-version</code> f
302302
information over time. Accepts an optional comma-separated list of output
303303
formats; <code>--timings</code> without an argument will default to <code>--timings=html</code>.
304304
Specifying an output format (rather than the default) is unstable and requires
305-
<code>-Zunstable-options</code>. Valid output formats:</p>
305+
<code>-Zunstable-options</code>.
306+
May also be specified with the <code>build.timings</code> <a href="../reference/config.html">config value</a>.
307+
Valid output formats:</p>
306308
<ul>
307309
<li><code>html</code>: Write a human-readable file <code>cargo-timing.html</code> to the
308310
<code>target/cargo-timings</code> directory with a report of the compilation. Also write

0 commit comments

Comments
 (0)