Skip to content

Commit 8dd0b1c

Browse files
committed
Auto merge of #6057 - alexcrichton:beta-next, r=ehuss
[beta]: Fixup the 1.30.0 branch Reconciles data found in this comment rust-lang/rust#54342 (comment) by merging the cargo submodule's commit of the original beta for 1.30.0 into the current 1.30.0 branch. Includes stabilization of `-Z compile-progress` as well as a number of other nice fixes! r? @ehuss
2 parents 308b1ea + a62aadb commit 8dd0b1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+924
-811
lines changed

src/bin/cargo/cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Available unstable (nightly-only) flags:
3434
-Z offline -- Offline mode that does not perform network requests
3535
-Z unstable-options -- Allow the usage of unstable options such as --registry
3636
-Z config-profile -- Read profiles from .cargo/config files
37-
-Z compile-progress -- Display a progress bar while compiling
3837
3938
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
4039
);

src/bin/cargo/command_prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ pub trait ArgMatchesExt {
315315
),
316316
target_rustdoc_args: None,
317317
target_rustc_args: None,
318+
local_rustdoc_args: None,
318319
export_dir: None,
319320
};
320321
Ok(opts)

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
5151
deps: !args.is_present("no-deps"),
5252
};
5353
let mut compile_opts = args.compile_options(config, mode)?;
54-
compile_opts.target_rustdoc_args = if args.is_present("document-private-items") {
54+
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
5555
Some(vec!["--document-private-items".to_string()])
5656
} else {
5757
None

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ pub struct BuildContext<'a, 'cfg: 'a> {
2424
pub resolve: &'a Resolve,
2525
pub profiles: &'a Profiles,
2626
pub build_config: &'a BuildConfig,
27-
/// This is a workaround to carry the extra compiler args for either
28-
/// `rustc` or `rustdoc` given on the command-line for the commands `cargo
29-
/// rustc` and `cargo rustdoc`. These commands only support one target,
30-
/// but we don't want the args passed to any dependencies, so we include
31-
/// the `Unit` corresponding to the top-level target.
32-
pub extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
27+
/// Extra compiler args for either `rustc` or `rustdoc`.
28+
pub extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
3329
pub packages: &'a PackageSet<'cfg>,
3430

3531
/// Information about the compiler
@@ -51,7 +47,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
5147
config: &'cfg Config,
5248
build_config: &'a BuildConfig,
5349
profiles: &'a Profiles,
54-
extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
50+
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
5551
) -> CargoResult<BuildContext<'a, 'cfg>> {
5652
let incremental_env = match env::var("CARGO_INCREMENTAL") {
5753
Ok(v) => Some(v == "1"),
@@ -200,12 +196,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
200196
}
201197

202198
pub fn extra_args_for(&self, unit: &Unit<'a>) -> Option<&Vec<String>> {
203-
if let Some((ref args_unit, ref args)) = self.extra_compiler_args {
204-
if args_unit == unit {
205-
return Some(args);
206-
}
207-
}
208-
None
199+
self.extra_compiler_args.get(unit)
209200
}
210201

211202
/// Return the list of filenames read by cargo to generate the BuildContext

src/cargo/core/compiler/job_queue.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@ impl<'a> JobQueue<'a> {
237237
// currently a pretty big task. This is issue #5695.
238238
let mut error = None;
239239
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
240-
if !cx.bcx.config.cli_unstable().compile_progress {
241-
progress.disable();
242-
}
243240
let total = self.queue.len();
244241
loop {
245242
// Dequeue as much work as we can, learning about everything

src/cargo/core/compiler/mod.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use serde_json;
1010

1111
use core::manifest::TargetSourcePath;
1212
use core::profiles::{Lto, Profile};
13-
use core::shell::ColorChoice;
1413
use core::{PackageId, Target};
1514
use util::errors::{CargoResult, CargoResultExt, Internal};
1615
use util::paths;
17-
use util::{self, machine_message, Freshness, ProcessBuilder};
16+
use util::{self, machine_message, Freshness, ProcessBuilder, process};
1817
use util::{internal, join_paths, profile};
1918

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

244-
let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;
245-
246243
return Ok(Work::new(move |state| {
247244
// Only at runtime have we discovered what the extra -L and -l
248245
// arguments are for native libraries, so we process those here. We
@@ -292,12 +289,7 @@ fn rustc<'a, 'cfg>(
292289
} else if build_plan {
293290
state.build_plan(buildkey, rustc.clone(), outputs.clone());
294291
} else {
295-
let exec_result = if should_capture_output {
296-
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
297-
} else {
298-
exec.exec(rustc, &package_id, &target, mode)
299-
};
300-
exec_result
292+
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
301293
.map_err(Internal::new)
302294
.chain_err(|| format!("Could not compile `{}`.", name))?;
303295
}
@@ -591,7 +583,12 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
591583
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
592584
add_path_args(bcx, unit, &mut rustdoc);
593585
add_cap_lints(bcx, unit, &mut rustdoc);
594-
add_color(bcx, &mut rustdoc);
586+
587+
let mut can_add_color_process = process(&*bcx.config.rustdoc()?);
588+
can_add_color_process.args(&["--color", "never", "-V"]);
589+
if bcx.rustc.cached_success(&can_add_color_process)? {
590+
add_color(bcx, &mut rustdoc);
591+
}
595592

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

632-
let should_capture_output = cx.bcx.config.cli_unstable().compile_progress;
633-
634629
Ok(Work::new(move |state| {
635630
if let Some(output) = build_state.outputs.lock().unwrap().get(&key) {
636631
for cfg in output.cfgs.iter() {
@@ -649,10 +644,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
649644
&mut |line| json_stderr(line, &package_id, &target),
650645
false,
651646
).map(drop)
652-
} else if should_capture_output {
653-
state.capture_output(&rustdoc, false).map(drop)
654647
} else {
655-
rustdoc.exec()
648+
state.capture_output(&rustdoc, false).map(drop)
656649
};
657650
exec_result.chain_err(|| format!("Could not document `{}`.", name))?;
658651
Ok(())
@@ -709,12 +702,9 @@ fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
709702
}
710703

711704
fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
712-
let capture_output = bcx.config.cli_unstable().compile_progress;
713705
let shell = bcx.config.shell();
714-
if capture_output || shell.color_choice() != ColorChoice::CargoAuto {
715-
let color = if shell.supports_color() { "always" } else { "never" };
716-
cmd.args(&["--color", color]);
717-
}
706+
let color = if shell.supports_color() { "always" } else { "never" };
707+
cmd.args(&["--color", color]);
718708
}
719709

720710
fn add_error_format(bcx: &BuildContext, cmd: &mut ProcessBuilder) {

src/cargo/core/features.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ pub struct CliUnstable {
318318
pub package_features: bool,
319319
pub advanced_env: bool,
320320
pub config_profile: bool,
321-
pub compile_progress: bool,
322321
}
323322

324323
impl CliUnstable {
@@ -355,7 +354,6 @@ impl CliUnstable {
355354
"package-features" => self.package_features = true,
356355
"advanced-env" => self.advanced_env = true,
357356
"config-profile" => self.config_profile = true,
358-
"compile-progress" => self.compile_progress = true,
359357
_ => bail!("unknown `-Z` flag specified: {}", k),
360358
}
361359

src/cargo/core/shell.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,51 @@ mod imp {
359359
extern crate winapi;
360360

361361
use std::mem;
362+
use std::ptr;
363+
use self::winapi::um::fileapi::*;
364+
use self::winapi::um::handleapi::*;
362365
use self::winapi::um::processenv::*;
363366
use self::winapi::um::winbase::*;
364367
use self::winapi::um::wincon::*;
368+
use self::winapi::um::winnt::*;
365369

366370
pub fn stderr_width() -> Option<usize> {
367371
unsafe {
368372
let stdout = GetStdHandle(STD_ERROR_HANDLE);
369373
let mut csbi: CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
370-
if GetConsoleScreenBufferInfo(stdout, &mut csbi) == 0 {
374+
if GetConsoleScreenBufferInfo(stdout, &mut csbi) != 0 {
375+
return Some((csbi.srWindow.Right - csbi.srWindow.Left) as usize)
376+
}
377+
378+
// On mintty/msys/cygwin based terminals, the above fails with
379+
// INVALID_HANDLE_VALUE. Use an alternate method which works
380+
// in that case as well.
381+
let h = CreateFileA("CONOUT$\0".as_ptr() as *const CHAR,
382+
GENERIC_READ | GENERIC_WRITE,
383+
FILE_SHARE_READ | FILE_SHARE_WRITE,
384+
ptr::null_mut(),
385+
OPEN_EXISTING,
386+
0,
387+
ptr::null_mut()
388+
);
389+
if h == INVALID_HANDLE_VALUE {
371390
return None;
372391
}
373-
Some((csbi.srWindow.Right - csbi.srWindow.Left) as usize)
392+
393+
let mut csbi: CONSOLE_SCREEN_BUFFER_INFO = mem::zeroed();
394+
let rc = GetConsoleScreenBufferInfo(h, &mut csbi);
395+
CloseHandle(h);
396+
if rc != 0 {
397+
let width = (csbi.srWindow.Right - csbi.srWindow.Left) as usize;
398+
// Some terminals, such as mintty, always return 79 instead of
399+
// the actual width. In that case, use a conservative value.
400+
if width == 79 {
401+
return Some(60);
402+
} else {
403+
return Some(width);
404+
}
405+
}
406+
return None;
374407
}
375408
}
376409
}

src/cargo/core/source/source_id.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl SourceId {
213213
if self.is_default_registry() {
214214
"crates.io index".to_string()
215215
} else {
216-
format!("`{}` index", self.url())
216+
format!("`{}` index", url_display(self.url()))
217217
}
218218
}
219219

@@ -367,20 +367,34 @@ impl<'de> de::Deserialize<'de> for SourceId {
367367
}
368368
}
369369

370+
fn url_display(url: &Url) -> String {
371+
if url.scheme() == "file" {
372+
if let Ok(path) = url.to_file_path() {
373+
if let Some(path_str) = path.to_str() {
374+
return path_str.to_string();
375+
}
376+
}
377+
}
378+
379+
url.as_str().to_string()
380+
}
381+
370382
impl fmt::Display for SourceId {
371383
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
372384
match *self.inner {
373385
SourceIdInner {
374386
kind: Kind::Path,
375387
ref url,
376388
..
377-
} => fmt::Display::fmt(url, f),
389+
} => write!(f, "{}", url_display(url)),
378390
SourceIdInner {
379391
kind: Kind::Git(ref reference),
380392
ref url,
381393
ref precise,
382394
..
383395
} => {
396+
// Don't replace the URL display for git references,
397+
// because those are kind of expected to be URLs.
384398
write!(f, "{}", url)?;
385399
if let Some(pretty) = reference.pretty_ref() {
386400
write!(f, "?{}", pretty)?;
@@ -401,12 +415,12 @@ impl fmt::Display for SourceId {
401415
kind: Kind::LocalRegistry,
402416
ref url,
403417
..
404-
} => write!(f, "registry `{}`", url),
418+
} => write!(f, "registry `{}`", url_display(url)),
405419
SourceIdInner {
406420
kind: Kind::Directory,
407421
ref url,
408422
..
409-
} => write!(f, "dir {}", url),
423+
} => write!(f, "dir {}", url_display(url)),
410424
}
411425
}
412426
}

src/cargo/ops/cargo_clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::fs;
23
use std::path::Path;
34

@@ -97,7 +98,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
9798
opts.config,
9899
&build_config,
99100
profiles,
100-
None,
101+
HashMap::new(),
101102
)?;
102103
let mut cx = Context::new(config, &bcx)?;
103104
cx.prepare_units(None, &units)?;

src/cargo/ops/cargo_compile.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ pub struct CompileOptions<'a> {
5353
/// Filter to apply to the root package to select which targets will be
5454
/// built.
5555
pub filter: CompileFilter,
56-
/// Extra arguments to be passed to rustdoc (for main crate and dependencies)
56+
/// Extra arguments to be passed to rustdoc (single target only)
5757
pub target_rustdoc_args: Option<Vec<String>>,
5858
/// The specified target will be compiled with all the available arguments,
5959
/// note that this only accounts for the *final* invocation of rustc
6060
pub target_rustc_args: Option<Vec<String>>,
61+
/// Extra arguments passed to all selected targets for rustdoc.
62+
pub local_rustdoc_args: Option<Vec<String>>,
6163
/// The directory to copy final artifacts to. Note that even if `out_dir` is
6264
/// set, a copy of artifacts still could be found a `target/(debug\release)`
6365
/// as usual.
@@ -80,6 +82,7 @@ impl<'a> CompileOptions<'a> {
8082
},
8183
target_rustdoc_args: None,
8284
target_rustc_args: None,
85+
local_rustdoc_args: None,
8386
export_dir: None,
8487
})
8588
}
@@ -219,6 +222,7 @@ pub fn compile_ws<'a>(
219222
ref filter,
220223
ref target_rustdoc_args,
221224
ref target_rustc_args,
225+
ref local_rustdoc_args,
222226
ref export_dir,
223227
} = *options;
224228

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

268-
let mut extra_compiler_args = None;
269-
270272
let units = generate_targets(
271273
ws,
272274
profiles,
@@ -277,6 +279,7 @@ pub fn compile_ws<'a>(
277279
build_config,
278280
)?;
279281

282+
let mut extra_compiler_args = HashMap::new();
280283
if let Some(args) = extra_args {
281284
if units.len() != 1 {
282285
bail!(
@@ -286,7 +289,14 @@ pub fn compile_ws<'a>(
286289
extra_args_name
287290
);
288291
}
289-
extra_compiler_args = Some((units[0], args));
292+
extra_compiler_args.insert(units[0], args);
293+
}
294+
if let Some(args) = local_rustdoc_args {
295+
for unit in &units {
296+
if unit.mode.is_doc() {
297+
extra_compiler_args.insert(*unit, args.clone());
298+
}
299+
}
290300
}
291301

292302
let ret = {

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
444444
},
445445
target_rustdoc_args: None,
446446
target_rustc_args: None,
447+
local_rustdoc_args: None,
447448
export_dir: None,
448449
},
449450
&exec,

0 commit comments

Comments
 (0)