Skip to content

[beta]: Fixup the 1.30.0 branch #6057

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

Merged
merged 18 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Available unstable (nightly-only) flags:
-Z offline -- Offline mode that does not perform network requests
-Z unstable-options -- Allow the usage of unstable options such as --registry
-Z config-profile -- Read profiles from .cargo/config files
-Z compile-progress -- Display a progress bar while compiling

Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub trait ArgMatchesExt {
),
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
};
Ok(opts)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
deps: !args.is_present("no-deps"),
};
let mut compile_opts = args.compile_options(config, mode)?;
compile_opts.target_rustdoc_args = if args.is_present("document-private-items") {
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
Some(vec!["--document-private-items".to_string()])
} else {
None
Expand Down
17 changes: 4 additions & 13 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ pub struct BuildContext<'a, 'cfg: 'a> {
pub resolve: &'a Resolve,
pub profiles: &'a Profiles,
pub build_config: &'a BuildConfig,
/// This is a workaround to carry the extra compiler args for either
/// `rustc` or `rustdoc` given on the command-line for the commands `cargo
/// rustc` and `cargo rustdoc`. These commands only support one target,
/// but we don't want the args passed to any dependencies, so we include
/// the `Unit` corresponding to the top-level target.
pub extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
/// Extra compiler args for either `rustc` or `rustdoc`.
pub extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
pub packages: &'a PackageSet<'cfg>,

/// Information about the compiler
Expand All @@ -51,7 +47,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
config: &'cfg Config,
build_config: &'a BuildConfig,
profiles: &'a Profiles,
extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
) -> CargoResult<BuildContext<'a, 'cfg>> {
let incremental_env = match env::var("CARGO_INCREMENTAL") {
Ok(v) => Some(v == "1"),
Expand Down Expand Up @@ -200,12 +196,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
}

pub fn extra_args_for(&self, unit: &Unit<'a>) -> Option<&Vec<String>> {
if let Some((ref args_unit, ref args)) = self.extra_compiler_args {
if args_unit == unit {
return Some(args);
}
}
None
self.extra_compiler_args.get(unit)
}

/// Return the list of filenames read by cargo to generate the BuildContext
Expand Down
3 changes: 0 additions & 3 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ impl<'a> JobQueue<'a> {
// currently a pretty big task. This is issue #5695.
let mut error = None;
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
if !cx.bcx.config.cli_unstable().compile_progress {
progress.disable();
}
let total = self.queue.len();
loop {
// Dequeue as much work as we can, learning about everything
Expand Down
32 changes: 11 additions & 21 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use serde_json;

use core::manifest::TargetSourcePath;
use core::profiles::{Lto, Profile};
use core::shell::ColorChoice;
use core::{PackageId, Target};
use util::errors::{CargoResult, CargoResultExt, Internal};
use util::paths;
use util::{self, machine_message, Freshness, ProcessBuilder};
use util::{self, machine_message, Freshness, ProcessBuilder, process};
use util::{internal, join_paths, profile};

use self::build_plan::BuildPlan;
Expand Down Expand Up @@ -241,8 +240,6 @@ fn rustc<'a, 'cfg>(
.unwrap_or_else(|| cx.bcx.config.cwd())
.to_path_buf();

let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;

return Ok(Work::new(move |state| {
// Only at runtime have we discovered what the extra -L and -l
// arguments are for native libraries, so we process those here. We
Expand Down Expand Up @@ -292,12 +289,7 @@ fn rustc<'a, 'cfg>(
} else if build_plan {
state.build_plan(buildkey, rustc.clone(), outputs.clone());
} else {
let exec_result = if should_capture_output {
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
} else {
exec.exec(rustc, &package_id, &target, mode)
};
exec_result
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
.map_err(Internal::new)
.chain_err(|| format!("Could not compile `{}`.", name))?;
}
Expand Down Expand Up @@ -591,7 +583,12 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
add_path_args(bcx, unit, &mut rustdoc);
add_cap_lints(bcx, unit, &mut rustdoc);
add_color(bcx, &mut rustdoc);

let mut can_add_color_process = process(&*bcx.config.rustdoc()?);
can_add_color_process.args(&["--color", "never", "-V"]);
if bcx.rustc.cached_success(&can_add_color_process)? {
add_color(bcx, &mut rustdoc);
}

if unit.kind != Kind::Host {
if let Some(ref target) = bcx.build_config.requested_target {
Expand Down Expand Up @@ -629,8 +626,6 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();

let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;

Ok(Work::new(move |state| {
if let Some(output) = build_state.outputs.lock().unwrap().get(&key) {
for cfg in output.cfgs.iter() {
Expand All @@ -649,10 +644,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
&mut |line| json_stderr(line, &package_id, &target),
false,
).map(drop)
} else if should_capture_output {
state.capture_output(&rustdoc, false).map(drop)
} else {
rustdoc.exec()
state.capture_output(&rustdoc, false).map(drop)
};
exec_result.chain_err(|| format!("Could not document `{}`.", name))?;
Ok(())
Expand Down Expand Up @@ -709,12 +702,9 @@ fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
}

fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
let capture_output = bcx.config.cli_unstable().compile_progress;
let shell = bcx.config.shell();
if capture_output || shell.color_choice() != ColorChoice::CargoAuto {
let color = if shell.supports_color() { "always" } else { "never" };
cmd.args(&["--color", color]);
}
let color = if shell.supports_color() { "always" } else { "never" };
cmd.args(&["--color", color]);
}

fn add_error_format(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ pub struct CliUnstable {
pub package_features: bool,
pub advanced_env: bool,
pub config_profile: bool,
pub compile_progress: bool,
}

impl CliUnstable {
Expand Down Expand Up @@ -355,7 +354,6 @@ impl CliUnstable {
"package-features" => self.package_features = true,
"advanced-env" => self.advanced_env = true,
"config-profile" => self.config_profile = true,
"compile-progress" => self.compile_progress = true,
_ => bail!("unknown `-Z` flag specified: {}", k),
}

Expand Down
37 changes: 35 additions & 2 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,51 @@ mod imp {
extern crate winapi;

use std::mem;
use std::ptr;
use self::winapi::um::fileapi::*;
use self::winapi::um::handleapi::*;
use self::winapi::um::processenv::*;
use self::winapi::um::winbase::*;
use self::winapi::um::wincon::*;
use self::winapi::um::winnt::*;

pub fn stderr_width() -> Option<usize> {
unsafe {
let stdout = GetStdHandle(STD_ERROR_HANDLE);
let mut csbi: CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
if GetConsoleScreenBufferInfo(stdout, &mut csbi) == 0 {
if GetConsoleScreenBufferInfo(stdout, &mut csbi) != 0 {
return Some((csbi.srWindow.Right - csbi.srWindow.Left) as usize)
}

// On mintty/msys/cygwin based terminals, the above fails with
// INVALID_HANDLE_VALUE. Use an alternate method which works
// in that case as well.
let h = CreateFileA("CONOUT$\0".as_ptr() as *const CHAR,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
ptr::null_mut(),
OPEN_EXISTING,
0,
ptr::null_mut()
);
if h == INVALID_HANDLE_VALUE {
return None;
}
Some((csbi.srWindow.Right - csbi.srWindow.Left) as usize)

let mut csbi: CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
let rc = GetConsoleScreenBufferInfo(h, &mut csbi);
CloseHandle(h);
if rc != 0 {
let width = (csbi.srWindow.Right - csbi.srWindow.Left) as usize;
// Some terminals, such as mintty, always return 79 instead of
// the actual width. In that case, use a conservative value.
if width == 79 {
return Some(60);
} else {
return Some(width);
}
}
return None;
}
}
}
22 changes: 18 additions & 4 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl SourceId {
if self.is_default_registry() {
"crates.io index".to_string()
} else {
format!("`{}` index", self.url())
format!("`{}` index", url_display(self.url()))
}
}

Expand Down Expand Up @@ -367,20 +367,34 @@ impl<'de> de::Deserialize<'de> for SourceId {
}
}

fn url_display(url: &Url) -> String {
if url.scheme() == "file" {
if let Ok(path) = url.to_file_path() {
if let Some(path_str) = path.to_str() {
return path_str.to_string();
}
}
}

url.as_str().to_string()
}

impl fmt::Display for SourceId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self.inner {
SourceIdInner {
kind: Kind::Path,
ref url,
..
} => fmt::Display::fmt(url, f),
} => write!(f, "{}", url_display(url)),
SourceIdInner {
kind: Kind::Git(ref reference),
ref url,
ref precise,
..
} => {
// Don't replace the URL display for git references,
// because those are kind of expected to be URLs.
write!(f, "{}", url)?;
if let Some(pretty) = reference.pretty_ref() {
write!(f, "?{}", pretty)?;
Expand All @@ -401,12 +415,12 @@ impl fmt::Display for SourceId {
kind: Kind::LocalRegistry,
ref url,
..
} => write!(f, "registry `{}`", url),
} => write!(f, "registry `{}`", url_display(url)),
SourceIdInner {
kind: Kind::Directory,
ref url,
..
} => write!(f, "dir {}", url),
} => write!(f, "dir {}", url_display(url)),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fs;
use std::path::Path;

Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
opts.config,
&build_config,
profiles,
None,
HashMap::new(),
)?;
let mut cx = Context::new(config, &bcx)?;
cx.prepare_units(None, &units)?;
Expand Down
18 changes: 14 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ pub struct CompileOptions<'a> {
/// Filter to apply to the root package to select which targets will be
/// built.
pub filter: CompileFilter,
/// Extra arguments to be passed to rustdoc (for main crate and dependencies)
/// Extra arguments to be passed to rustdoc (single target only)
pub target_rustdoc_args: Option<Vec<String>>,
/// The specified target will be compiled with all the available arguments,
/// note that this only accounts for the *final* invocation of rustc
pub target_rustc_args: Option<Vec<String>>,
/// Extra arguments passed to all selected targets for rustdoc.
pub local_rustdoc_args: Option<Vec<String>>,
/// The directory to copy final artifacts to. Note that even if `out_dir` is
/// set, a copy of artifacts still could be found a `target/(debug\release)`
/// as usual.
Expand All @@ -80,6 +82,7 @@ impl<'a> CompileOptions<'a> {
},
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
})
}
Expand Down Expand Up @@ -219,6 +222,7 @@ pub fn compile_ws<'a>(
ref filter,
ref target_rustdoc_args,
ref target_rustc_args,
ref local_rustdoc_args,
ref export_dir,
} = *options;

Expand Down Expand Up @@ -265,8 +269,6 @@ pub fn compile_ws<'a>(
let profiles = ws.profiles();
profiles.validate_packages(&mut config.shell(), &packages)?;

let mut extra_compiler_args = None;

let units = generate_targets(
ws,
profiles,
Expand All @@ -277,6 +279,7 @@ pub fn compile_ws<'a>(
build_config,
)?;

let mut extra_compiler_args = HashMap::new();
if let Some(args) = extra_args {
if units.len() != 1 {
bail!(
Expand All @@ -286,7 +289,14 @@ pub fn compile_ws<'a>(
extra_args_name
);
}
extra_compiler_args = Some((units[0], args));
extra_compiler_args.insert(units[0], args);
}
if let Some(args) = local_rustdoc_args {
for unit in &units {
if unit.mode.is_doc() {
extra_compiler_args.insert(*unit, args.clone());
}
}
}

let ret = {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
},
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
},
&exec,
Expand Down
Loading