Skip to content

Commit

Permalink
Merge branch 'master' into fix-allow-staged
Browse files Browse the repository at this point in the history
* master: (25 commits)
  Migrate from tests fom assert_that/execs to .run()
  Wrap ProcessBuilder in Execs & make .cargo return that
  Make old Execs methods take not consume self
  Extract Execs::match_process
  Add #[must_use] to Execs
  Inline Execs::_with_stderr
  Remove an unrun "cargo build" ProcessBuilder
  Add documentation for creating test dependencies.
  Only use non-absolute paths for `path` dependencies
  Fix test failure on nightly due to `codemap::Span` change.
  New metabuild strategy using custom src_path enum.
  Remove unnecessary change.
  Address review comments.
  Metabuild (RFC 2196)
  Handle Window's missing file error message
  Make "cargo uninstall" uninstall the cwd bins
  update comment based on further research
  List URL in HTTP download failures
  Fix compilation error
  Improve the `cargo install` deprecation messaging
  ...
  • Loading branch information
dwijnand committed Aug 28, 2018
2 parents 2bbbca3 + 9ddf75a commit 8c2d0df
Show file tree
Hide file tree
Showing 101 changed files with 9,973 additions and 12,757 deletions.
5 changes: 3 additions & 2 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ By default cargo will refuse to overwrite existing binaries. The `--force` flag
enables overwriting existing binaries. Thus you can reinstall a crate with
`cargo install --force <crate>`.
As a special convenience, omitting the <crate> specification entirely will
Omitting the <crate> specification entirely will
install the crate in the current directory. That is, `install` is equivalent to
the more explicit `install --path .`.
the more explicit `install --path .`. This behaviour is deprecated, and no
longer supported as of the Rust 2018 edition.
If the source is crates.io or `--git` then by default the crate will be built
in a temporary target directory. To avoid this, the target directory can be
Expand Down
36 changes: 36 additions & 0 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
let build_plan = bcx.build_config.build_plan;
let invocation_name = unit.buildkey();

if let Some(deps) = unit.pkg.manifest().metabuild() {
prepare_metabuild(cx, build_script_unit, deps)?;
}

// Building the command to execute
let to_exec = script_output.join(unit.target.name());

Expand Down Expand Up @@ -532,6 +536,38 @@ impl BuildOutput {
}
}

fn prepare_metabuild<'a, 'cfg>(
cx: &Context<'a, 'cfg>,
unit: &Unit<'a>,
deps: &[String],
) -> CargoResult<()> {
let mut output = Vec::new();
let available_deps = cx.dep_targets(unit);
// Filter out optional dependencies, and look up the actual lib name.
let meta_deps: Vec<_> = deps
.iter()
.filter_map(|name| {
available_deps
.iter()
.find(|u| u.pkg.name().as_str() == name.as_str())
.map(|dep| dep.target.crate_name())
})
.collect();
for dep in &meta_deps {
output.push(format!("extern crate {};\n", dep));
}
output.push("fn main() {\n".to_string());
for dep in &meta_deps {
output.push(format!(" {}::metabuild();\n", dep));
}
output.push("}\n".to_string());
let output = output.join("");
let path = unit.pkg.manifest().metabuild_path(cx.bcx.ws.target_dir());
fs::create_dir_all(path.parent().unwrap())?;
paths::write_if_changed(path, &output)?;
Ok(())
}

impl BuildDeps {
pub fn new(output_file: &Path, output: Option<&BuildOutput>) -> BuildDeps {
BuildDeps {
Expand Down
19 changes: 18 additions & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,24 @@ where
return true;
}
};
if mtime2 > mtime {

// Note that equal mtimes are considered "stale". For filesystems with
// not much timestamp precision like 1s this is a conservative approximation
// to handle the case where a file is modified within the same second after
// a build finishes. We want to make sure that incremental rebuilds pick that up!
//
// For filesystems with nanosecond precision it's been seen in the wild that
// its "nanosecond precision" isn't really nanosecond-accurate. It turns out that
// kernels may cache the current time so files created at different times actually
// list the same nanosecond precision. Some digging on #5919 picked up that the
// kernel caches the current time between timer ticks, which could mean that if
// a file is updated at most 10ms after a build finishes then Cargo may not
// pick up the build changes.
//
// All in all, the equality check here is a conservative assumption that,
// if equal, files were changed just after a previous build finished.
// It's hoped this doesn't cause too many issues in practice!
if mtime2 >= mtime {
info!("stale: {} -- {} vs {}", path.display(), mtime2, mtime);
true
} else {
Expand Down
22 changes: 17 additions & 5 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::Arc;
use same_file::is_same_file;
use serde_json;

use core::manifest::TargetSourcePath;
use core::profiles::{Lto, Profile};
use core::shell::ColorChoice;
use core::{PackageId, Target};
Expand Down Expand Up @@ -390,7 +391,6 @@ fn link_targets<'a, 'cfg>(
let outputs = cx.outputs(unit)?;
let export_dir = cx.files().export_dir();
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();
let profile = unit.profile;
let unit_mode = unit.mode;
let features = bcx.resolve
Expand All @@ -399,6 +399,12 @@ fn link_targets<'a, 'cfg>(
.map(|s| s.to_owned())
.collect();
let json_messages = bcx.build_config.json_messages();
let mut target = unit.target.clone();
if let TargetSourcePath::Metabuild = target.src_path() {
// Give it something to serialize.
let path = unit.pkg.manifest().metabuild_path(cx.bcx.ws.target_dir());
target.set_src_path(TargetSourcePath::Path(path));
}

Ok(Work::new(move |_| {
// If we're a "root crate", e.g. the target of this compilation, then we
Expand Down Expand Up @@ -668,12 +674,18 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
// second is the cwd that rustc should operate in.
fn path_args(bcx: &BuildContext, unit: &Unit) -> (PathBuf, PathBuf) {
let ws_root = bcx.ws.root();
let src = unit.target.src_path();
let src = if unit.target.is_custom_build() && unit.pkg.manifest().metabuild().is_some() {
unit.pkg.manifest().metabuild_path(bcx.ws.target_dir())
} else {
unit.target.src_path().path().to_path_buf()
};
assert!(src.is_absolute());
match src.strip_prefix(ws_root) {
Ok(path) => (path.to_path_buf(), ws_root.to_path_buf()),
Err(_) => (src.to_path_buf(), unit.pkg.root().to_path_buf()),
if unit.pkg.package_id().source_id().is_path() {
if let Ok(path) = src.strip_prefix(ws_root) {
return (path.to_path_buf(), ws_root.to_path_buf());
}
}
(src, unit.pkg.root().to_path_buf())
}

fn add_path_args(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ features! {

// "default-run" manifest option,
[unstable] default_run: bool,

// Declarative build scripts.
[unstable] metabuild: bool,
}
}

Expand Down
Loading

0 comments on commit 8c2d0df

Please sign in to comment.