Skip to content

add prepare step to remove ".cargo/config" #22

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

Merged
merged 3 commits into from
May 7, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 2 additions & 0 deletions tests/buildtest/crates/cargo-config/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "invalid-test-target"
9 changes: 9 additions & 0 deletions tests/buildtest/crates/cargo-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "cargo-config"
version = "0.1.0"
authors = ["Tom Dohrmann <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions tests/buildtest/crates/cargo-config/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
15 changes: 15 additions & 0 deletions tests/buildtest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down