Skip to content

Commit 10c38b1

Browse files
committed
add prepare step to remove ".cargo/config"
1 parent 2b0d92b commit 10c38b1

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

src/prepare.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{build::CratePatch, Crate, Toolchain, Workspace};
33
use failure::{Error, Fail, ResultExt};
44
use log::info;
55
use std::path::Path;
6+
use std::fs::remove_file;
67
use toml::{
78
value::{Array, Table},
89
Value,
@@ -38,6 +39,7 @@ impl<'a> Prepare<'a> {
3839
pub(crate) fn prepare(&mut self) -> Result<(), Error> {
3940
self.krate.copy_source_to(self.workspace, self.source_dir)?;
4041
self.validate_manifest()?;
42+
self.remove_cargo_config()?;
4143
self.tweak_toml()?;
4244
self.capture_lockfile(false)?;
4345
self.fetch_deps()?;
@@ -68,6 +70,14 @@ impl<'a> Prepare<'a> {
6870
Ok(())
6971
}
7072

73+
fn remove_cargo_config(&self) -> Result<(), Error> {
74+
let path = self.source_dir.join(".cargo").join("config");
75+
if path.exists() {
76+
remove_file(path)?;
77+
}
78+
Ok(())
79+
}
80+
7181
fn tweak_toml(&self) -> Result<(), Error> {
7282
let path = self.source_dir.join("Cargo.toml");
7383
let mut tweaker = TomlTweaker::new(&self.krate, &path, &self.patches)?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "invalid-test-target"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "cargo-config"
3+
version = "0.1.0"
4+
authors = ["Tom Dohrmann <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

tests/buildtest/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ fn test_sandbox_oom() {
7373
});
7474
}
7575

76+
#[test]
77+
fn test_cargo_config() {
78+
runner::run("cargo-config", |run| {
79+
run.build(SandboxBuilder::new().enable_networking(false), |build| {
80+
let storage = rustwide::logging::LogStorage::new(LevelFilter::Info);
81+
rustwide::logging::capture(&storage, || -> Result<_, Error> {
82+
build.cargo().args(&["run"]).run()?;
83+
Ok(())
84+
})?;
85+
Ok(())
86+
})?;
87+
Ok(())
88+
});
89+
}
90+
7691
test_prepare_error!(
7792
test_missing_cargotoml,
7893
"missing-cargotoml",

0 commit comments

Comments
 (0)