diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b109ac..728db57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- The file `.cargo/config` will be removed before starting the build + ## [0.6.1] - 2020-05-04 ### Fixed diff --git a/src/prepare.rs b/src/prepare.rs index 52477e2..9b7fc04 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -2,6 +2,7 @@ use crate::cmd::Command; use crate::{build::CratePatch, Crate, Toolchain, Workspace}; use failure::{Error, Fail, ResultExt}; use log::info; +use std::fs::remove_file; use std::path::Path; use toml::{ value::{Array, Table}, @@ -38,6 +39,7 @@ impl<'a> Prepare<'a> { pub(crate) fn prepare(&mut self) -> Result<(), Error> { self.krate.copy_source_to(self.workspace, self.source_dir)?; self.validate_manifest()?; + self.remove_cargo_config()?; self.tweak_toml()?; self.capture_lockfile(false)?; self.fetch_deps()?; @@ -68,6 +70,15 @@ impl<'a> Prepare<'a> { Ok(()) } + fn remove_cargo_config(&self) -> Result<(), Error> { + let path = self.source_dir.join(".cargo").join("config"); + if path.exists() { + remove_file(path.clone())?; + info!("removed {}", path.as_path().display()); + } + Ok(()) + } + fn tweak_toml(&self) -> Result<(), Error> { let path = self.source_dir.join("Cargo.toml"); let mut tweaker = TomlTweaker::new(&self.krate, &path, &self.patches)?; diff --git a/tests/buildtest/crates/cargo-config/.cargo/config b/tests/buildtest/crates/cargo-config/.cargo/config new file mode 100644 index 0000000..92be13f --- /dev/null +++ b/tests/buildtest/crates/cargo-config/.cargo/config @@ -0,0 +1,2 @@ +[build] +target = "invalid-test-target" \ No newline at end of file diff --git a/tests/buildtest/crates/cargo-config/Cargo.toml b/tests/buildtest/crates/cargo-config/Cargo.toml new file mode 100644 index 0000000..e8c40d9 --- /dev/null +++ b/tests/buildtest/crates/cargo-config/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cargo-config" +version = "0.1.0" +authors = ["Tom Dohrmann "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/buildtest/crates/cargo-config/src/main.rs b/tests/buildtest/crates/cargo-config/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/tests/buildtest/crates/cargo-config/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/buildtest/mod.rs b/tests/buildtest/mod.rs index 1adf5f7..668b440 100644 --- a/tests/buildtest/mod.rs +++ b/tests/buildtest/mod.rs @@ -73,6 +73,21 @@ fn test_sandbox_oom() { }); } +#[test] +fn test_cargo_config() { + runner::run("cargo-config", |run| { + run.build(SandboxBuilder::new().enable_networking(false), |build| { + let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); + rustwide::logging::capture(&storage, || -> Result<_, Error> { + build.cargo().args(&["run"]).run()?; + Ok(()) + })?; + Ok(()) + })?; + Ok(()) + }); +} + test_prepare_error!( test_missing_cargotoml, "missing-cargotoml",