Skip to content

Commit

Permalink
Resolve merge conflicts with rust-lang#10330
Browse files Browse the repository at this point in the history
  • Loading branch information
kennystrawnmusic committed Feb 12, 2022
2 parents c99ca79 + 1b59cda commit af0d0a1
Show file tree
Hide file tree
Showing 91 changed files with 1,269 additions and 248 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ strip-ansi-escapes = "0.1.0"
tar = { version = "0.4.36", default-features = false }
tempfile = "3.0"
termcolor = "1.1"
toml_edit = { version = "0.13", features = ["serde", "easy"] }
toml_edit = { version = "0.13.4", features = ["serde", "easy"] }
unicode-xid = "0.2.0"
url = "2.2.2"
walkdir = "2.2"
clap = "3.0.5"
clap = "3.0.13"
unicode-width = "0.1.5"
openssl = { version = '0.10.11', optional = true }
im-rc = "15.0.0"
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Learn more at https://doc.rust-lang.org/cargo/

## Code Status

[![Build Status](https://dev.azure.com/rust-lang/cargo/_apis/build/status/rust-lang.cargo?branchName=auto-cargo)](https://dev.azure.com/rust-lang/cargo/_build?definitionId=18)

Code documentation: https://docs.rs/cargo/

## Installing Cargo
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn cli() -> App {
"Run all benchmarks regardless of failure",
))
.arg_unit_graph()
.arg_timings()
.after_help("Run `cargo help bench` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn cli() -> App {
.arg_build_plan()
.arg_unit_graph()
.arg_future_incompat_report()
.arg_timings()
.after_help("Run `cargo help build` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_unit_graph()
.arg_future_incompat_report()
.arg_timings()
.after_help("Run `cargo help check` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_ignore_rust_version()
.arg_unit_graph()
.arg_timings()
.after_help("Run `cargo help doc` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn cli() -> App {
.help("Fix code even if the working directory has staged changes"),
)
.arg_ignore_rust_version()
.arg_timings()
.after_help("Run `cargo help fix` for more detailed information.\n")
}

Expand Down
27 changes: 21 additions & 6 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::command_prelude::*;

use cargo::core::{GitReference, SourceId};
use cargo::core::{GitReference, SourceId, Workspace};
use cargo::ops;
use cargo::util::IntoUrl;

use cargo_util::paths;

pub fn cli() -> App {
subcommand("install")
.about("Install a Rust binary. Default location is $HOME/.cargo/bin")
Expand Down Expand Up @@ -76,17 +78,25 @@ pub fn cli() -> App {
.conflicts_with_all(&["git", "path", "index"]),
)
.arg_message_format()
.arg_timings()
.after_help("Run `cargo help install` for more detailed information.\n")
}

pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
if let Some(path) = args.value_of_path("path", config) {
let path = args.value_of_path("path", config);
if let Some(path) = &path {
config.reload_rooted_at(path)?;
} else {
// TODO: Consider calling set_search_stop_path(home).
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
}

// In general, we try to avoid normalizing paths in Cargo,
// but in these particular cases we need it to fix rust-lang/cargo#10283.
// (Handle `SourceId::for_path` and `Workspace::new`,
// but not `Config::reload_rooted_at` which is always cwd)
let path = path.map(|p| paths::normalize_path(&p));

let krates = args
.values_of("crate")
.unwrap_or_default()
Expand All @@ -106,8 +116,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
GitReference::DefaultBranch
};
SourceId::for_git(&url, gitref)?
} else if let Some(path) = args.value_of_path("path", config) {
SourceId::for_path(&path)?
} else if let Some(path) = &path {
SourceId::for_path(path)?
} else if krates.is_empty() {
from_cwd = true;
SourceId::for_path(config.cwd())?
Expand All @@ -125,9 +135,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
// We only provide workspace information for local crate installation from
// one of the following sources:
// - From current working directory (only work for edition 2015).
// - From a specific local file path.
let workspace = if from_cwd || args.is_present("path") {
// - From a specific local file path (from `--path` arg).
//
// This workspace information is for emitting helpful messages from
// `ArgMatchesExt::compile_options` and won't affect the actual compilation.
let workspace = if from_cwd {
args.workspace(config).ok()
} else if let Some(path) = &path {
Workspace::new(&path.join("Cargo.toml"), config).ok()
} else {
None
};
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_unit_graph()
.arg_ignore_rust_version()
.arg_timings()
.after_help("Run `cargo help run` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn cli() -> App {
.arg_unit_graph()
.arg_ignore_rust_version()
.arg_future_incompat_report()
.arg_timings()
.after_help("Run `cargo help rustc` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_unit_graph()
.arg_ignore_rust_version()
.arg_timings()
.after_help("Run `cargo help rustdoc` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_unit_graph()
.arg_future_incompat_report()
.arg_timings()
.after_help(
"Run `cargo help test` for more detailed information.\n\
Run `cargo test -- --help` for test binary options.\n",
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct BuildConfig {
pub export_dir: Option<PathBuf>,
/// `true` to output a future incompatibility report at the end of the build
pub future_incompat_report: bool,
/// Which kinds of build timings to output (empty if none).
pub timing_outputs: Vec<TimingOutput>,
}

impl BuildConfig {
Expand Down Expand Up @@ -86,6 +88,7 @@ impl BuildConfig {
rustfix_diagnostic_server: RefCell::new(None),
export_dir: None,
future_incompat_report: false,
timing_outputs: Vec::new(),
})
}

Expand Down Expand Up @@ -231,3 +234,12 @@ impl CompileMode {
)
}
}

/// Kinds of build timings we can output.
#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord)]
pub enum TimingOutput {
/// Human-readable HTML report
Html,
/// Machine-readable JSON (unstable)
Json,
}
36 changes: 26 additions & 10 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,22 @@ impl BuildOutput {
script_out_dir.to_str().unwrap(),
);

macro_rules! check_and_add_target {
($target_kind: expr, $is_target_kind: expr, $link_type: expr) => {
if !targets.iter().any(|target| $is_target_kind(target)) {
bail!(
"invalid instruction `cargo:{}` from {}\n\
The package {} does not have a {} target.",
key,
whence,
pkg_descr,
$target_kind
);
}
linker_args.push(($link_type, value));
};
}

// Keep in sync with TargetConfig::parse_links_overrides.
match key {
"rustc-flags" => {
Expand All @@ -604,16 +620,7 @@ impl BuildOutput {
linker_args.push((LinkType::Cdylib, value))
}
"rustc-link-arg-bins" => {
if !targets.iter().any(|target| target.is_bin()) {
bail!(
"invalid instruction `cargo:{}` from {}\n\
The package {} does not have a bin target.",
key,
whence,
pkg_descr
);
}
linker_args.push((LinkType::Bin, value));
check_and_add_target!("bin", Target::is_bin, LinkType::Bin);
}
"rustc-link-arg-bin" => {
let mut parts = value.splitn(2, '=');
Expand Down Expand Up @@ -643,6 +650,15 @@ impl BuildOutput {
}
linker_args.push((LinkType::SingleBin(bin_name), arg.to_string()));
}
"rustc-link-arg-tests" => {
check_and_add_target!("test", Target::is_test, LinkType::Test);
}
"rustc-link-arg-benches" => {
check_and_add_target!("benchmark", Target::is_bench, LinkType::Bench);
}
"rustc-link-arg-examples" => {
check_and_add_target!("example", Target::is_example, LinkType::Example);
}
"rustc-link-arg" => {
linker_args.push((LinkType::All, value));
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ impl<'cfg> DrainState<'cfg> {
}

let time_elapsed = util::elapsed(cx.bcx.config.creation_time().elapsed());
if let Err(e) = self.timings.finished(cx.bcx, &error) {
if let Err(e) = self.timings.finished(cx, &error) {
if error.is_some() {
crate::display_error(&e, &mut cx.bcx.config.shell());
} else {
Expand Down Expand Up @@ -906,7 +906,7 @@ impl<'cfg> DrainState<'cfg> {
// this as often as we spin on the events receiver (at least every 500ms or
// so).
fn tick_progress(&mut self) {
// Record some timing information if `-Ztimings` is enabled, and
// Record some timing information if `--timings` is enabled, and
// this'll end up being a noop if we're not recording this
// information.
self.timings.mark_concurrency(
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use anyhow::{Context as _, Error};
use lazycell::LazyCell;
use log::{debug, trace};

pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat, TimingOutput};
pub use self::build_context::{
BuildContext, FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo,
};
Expand Down
51 changes: 14 additions & 37 deletions src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! long it takes for different units to compile.
use super::{CompileMode, Unit};
use crate::core::compiler::job_queue::JobId;
use crate::core::compiler::BuildContext;
use crate::core::compiler::{BuildContext, Context, TimingOutput};
use crate::core::PackageId;
use crate::util::cpu::State;
use crate::util::machine_message::{self, Message};
Expand All @@ -21,8 +21,6 @@ pub struct Timings<'cfg> {
enabled: bool,
/// If true, saves an HTML report to disk.
report_html: bool,
/// If true, reports unit completion to stderr.
report_info: bool,
/// If true, emits JSON information with timing information.
report_json: bool,
/// When Cargo started.
Expand Down Expand Up @@ -94,17 +92,10 @@ struct Concurrency {

impl<'cfg> Timings<'cfg> {
pub fn new(bcx: &BuildContext<'_, 'cfg>, root_units: &[Unit]) -> Timings<'cfg> {
let has_report = |what| {
bcx.config
.cli_unstable()
.timings
.as_ref()
.map_or(false, |t| t.iter().any(|opt| opt == what))
};
let report_html = has_report("html");
let report_info = has_report("info");
let report_json = has_report("json");
let enabled = report_html | report_info | report_json;
let has_report = |what| bcx.build_config.timing_outputs.contains(&what);
let report_html = has_report(TimingOutput::Html);
let report_json = has_report(TimingOutput::Json);
let enabled = report_html | report_json;

let mut root_map: HashMap<PackageId, Vec<String>> = HashMap::new();
for unit in root_units {
Expand Down Expand Up @@ -139,7 +130,6 @@ impl<'cfg> Timings<'cfg> {
config: bcx.config,
enabled,
report_html,
report_info,
report_json,
start: bcx.config.creation_time(),
start_str,
Expand Down Expand Up @@ -227,18 +217,6 @@ impl<'cfg> Timings<'cfg> {
unit_time
.unlocked_units
.extend(unlocked.iter().cloned().cloned());
if self.report_info {
let msg = format!(
"{}{} in {:.1}s",
unit_time.name_ver(),
unit_time.target,
unit_time.duration
);
let _ = self
.config
.shell()
.status_with_color("Completed", msg, termcolor::Color::Cyan);
}
if self.report_json {
let msg = machine_message::TimingInfo {
package_id: unit_time.unit.pkg.package_id(),
Expand Down Expand Up @@ -315,7 +293,7 @@ impl<'cfg> Timings<'cfg> {
/// Call this when all units are finished.
pub fn finished(
&mut self,
bcx: &BuildContext<'_, '_>,
cx: &Context<'_, '_>,
error: &Option<anyhow::Error>,
) -> CargoResult<()> {
if !self.enabled {
Expand All @@ -325,29 +303,27 @@ impl<'cfg> Timings<'cfg> {
self.unit_times
.sort_unstable_by(|a, b| a.start.partial_cmp(&b.start).unwrap());
if self.report_html {
self.report_html(bcx, error)
self.report_html(cx, error)
.with_context(|| "failed to save timing report")?;
}
Ok(())
}

/// Save HTML report to disk.
fn report_html(
&self,
bcx: &BuildContext<'_, '_>,
error: &Option<anyhow::Error>,
) -> CargoResult<()> {
fn report_html(&self, cx: &Context<'_, '_>, error: &Option<anyhow::Error>) -> CargoResult<()> {
let duration = self.start.elapsed().as_secs_f64();
let timestamp = self.start_str.replace(&['-', ':'][..], "");
let filename = format!("cargo-timing-{}.html", timestamp);
let timings_path = cx.files().host_root().join("cargo-timings");
paths::create_dir_all(&timings_path)?;
let filename = timings_path.join(format!("cargo-timing-{}.html", timestamp));
let mut f = BufWriter::new(paths::create(&filename)?);
let roots: Vec<&str> = self
.root_targets
.iter()
.map(|(name, _targets)| name.as_str())
.collect();
f.write_all(HTML_TMPL.replace("{ROOTS}", &roots.join(", ")).as_bytes())?;
self.write_summary_table(&mut f, duration, bcx, error)?;
self.write_summary_table(&mut f, duration, cx.bcx, error)?;
f.write_all(HTML_CANVAS.as_bytes())?;
self.write_unit_table(&mut f)?;
// It helps with pixel alignment to use whole numbers.
Expand Down Expand Up @@ -375,7 +351,8 @@ impl<'cfg> Timings<'cfg> {
.join(&filename)
.display()
);
paths::link_or_copy(&filename, "cargo-timing.html")?;
let unstamped_filename = timings_path.join("cargo-timing.html");
paths::link_or_copy(&filename, &unstamped_filename)?;
self.config
.shell()
.status_with_color("Timing", msg, termcolor::Color::Cyan)?;
Expand Down
Loading

0 comments on commit af0d0a1

Please sign in to comment.