Skip to content
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

Add message caching. #6933

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ matrix:

before_script:
- rustup target add $ALT
- rustup component add clippy || echo "clippy not available"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do echo "clippy not available" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the question. That's what it is doing. Or maybe you meant to comment on the appveyor changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean is it necessary to have echo "clippy not available"? Usually I only saw rustup component add clippy without the other part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, the command may fail because of missing clippy, and the build will stop.

script:
- cargo test --features=deny-warnings

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ serde = { version = "1.0.82", features = ['derive'] }
serde_ignored = "0.0.4"
serde_json = { version = "1.0.30", features = ["raw_value"] }
shell-escape = "0.1.4"
strip-ansi-escapes = "0.1.0"
tar = { version = "0.4.18", default-features = false }
tempfile = "3.0"
termcolor = "1.0"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ install:
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- if defined OTHER_TARGET rustup target add %OTHER_TARGET%
- rustup component add clippy || exit 0
alexcrichton marked this conversation as resolved.
Show resolved Hide resolved
- rustc -V
- cargo -V
- git submodule update --init
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Available unstable (nightly-only) flags:
-Z unstable-options -- Allow the usage of unstable options such as --registry
-Z config-profile -- Read profiles from .cargo/config files
-Z install-upgrade -- `cargo install` will upgrade instead of failing
-Z cache-messages -- Cache compiler messages

Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
Expand Down
13 changes: 12 additions & 1 deletion src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct BuildConfig {
/// An optional wrapper, if any, used to wrap rustc invocations
pub rustc_wrapper: Option<ProcessBuilder>,
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
/// Whether or not Cargo should cache compiler output on disk.
cache_messages: bool,
}

impl BuildConfig {
Expand Down Expand Up @@ -87,6 +89,7 @@ impl BuildConfig {
}
let cfg_jobs: Option<u32> = config.get("build.jobs")?;
let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32);

Ok(BuildConfig {
requested_target: target,
jobs,
Expand All @@ -97,10 +100,18 @@ impl BuildConfig {
build_plan: false,
rustc_wrapper: None,
rustfix_diagnostic_server: RefCell::new(None),
cache_messages: config.cli_unstable().cache_messages,
})
}

pub fn json_messages(&self) -> bool {
/// Whether or not Cargo should cache compiler messages on disk.
pub fn cache_messages(&self) -> bool {
self.cache_messages
}

/// Whether or not the *user* wants JSON output. Whether or not rustc
/// actually uses JSON is decided in `add_error_format`.
pub fn emit_json(&self) -> bool {
self.message_format == MessageFormat::Json
}

Expand Down
5 changes: 5 additions & 0 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
self.layout(unit.kind).fingerprint().join(dir)
}

/// Path where compiler output is cached.
pub fn message_cache_path(&self, unit: &Unit<'a>) -> PathBuf {
self.fingerprint_dir(unit).join("output")
}

/// Returns the directory where a compiled build script is stored.
/// `/path/to/target/{debug,release}/build/PKG-HASH`
pub fn build_script_dir(&self, unit: &Unit<'a>) -> PathBuf {
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: Pac
env: &output.env,
}
.to_json_string();
state.stdout(&msg);
state.stdout(msg);
}

fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult<Job> {
Expand Down Expand Up @@ -248,7 +248,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
);
let build_scripts = super::load_build_deps(cx, unit);
let kind = unit.kind;
let json_messages = bcx.build_config.json_messages();
let json_messages = bcx.build_config.emit_json();
let extra_verbose = bcx.config.extra_verbose();
let (prev_output, prev_script_out_dir) = prev_build_output(cx, unit);

Expand Down Expand Up @@ -315,13 +315,13 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
.exec_with_streaming(
&mut |stdout| {
if extra_verbose {
state.stdout(&format!("{}{}", prefix, stdout));
state.stdout(format!("{}{}", prefix, stdout));
}
Ok(())
},
&mut |stderr| {
if extra_verbose {
state.stderr(&format!("{}{}", prefix, stderr));
state.stderr(format!("{}{}", prefix, stderr));
}
Ok(())
},
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ impl<'a> JobState<'a> {
.send(Message::BuildPlanMsg(module_name, cmd, filenames));
}

pub fn stdout(&self, stdout: &str) {
drop(self.tx.send(Message::Stdout(stdout.to_string())));
pub fn stdout(&self, stdout: String) {
alexcrichton marked this conversation as resolved.
Show resolved Hide resolved
drop(self.tx.send(Message::Stdout(stdout)));
}

pub fn stderr(&self, stderr: &str) {
drop(self.tx.send(Message::Stderr(stderr.to_string())));
pub fn stderr(&self, stderr: String) {
drop(self.tx.send(Message::Stderr(stderr)));
}

/// A method used to signal to the coordinator thread that the rmeta file
Expand Down
Loading