Skip to content

Remove rust-toolchain before running builds #60

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 1 commit into from
Apr 20, 2021
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 @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[ghcr-linux]: https://github.com/orgs/rust-lang/packages/container/package/crates-build-env/linux

### Fixed

- Rustwide now removes `.cargo/config.toml`, `rust-toolchain`, and `rust-toolchain.toml` before running a build.

## [0.12.0] - 2021-01-28

### Added
Expand Down
20 changes: 14 additions & 6 deletions src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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.remove_override_files()?;
self.tweak_toml()?;
self.capture_lockfile(false)?;
self.fetch_deps()?;
Expand Down Expand Up @@ -69,11 +69,19 @@ impl<'a> Prepare<'a> {
Ok(())
}

fn remove_cargo_config(&self) -> Result<(), Error> {
let path = self.source_dir.join(".cargo").join("config");
if path.exists() {
crate::utils::remove_file(&path)?;
info!("removed {}", path.display());
fn remove_override_files(&self) -> Result<(), Error> {
let paths = [
&Path::new(".cargo").join("config"),
&Path::new(".cargo").join("config.toml"),
Path::new("rust-toolchain"),
Path::new("rust-toolchain.toml"),
];
for path in &paths {
let path = self.source_dir.join(path);
if path.exists() {
crate::utils::remove_file(&path)?;
info!("removed {}", path.display());
}
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/buildtest/crates/cargo-config/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
8 changes: 6 additions & 2 deletions tests/buildtest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ fn test_sandbox_oom() {
}

#[test]
fn test_cargo_config() {
fn test_override_files() {
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()?;
build.cargo().args(&["--version"]).run()?;
Copy link
Member

Choose a reason for hiding this comment

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

Can you run both cargo run and cargo version? You can do that in two different log captures if that makes the test easier to write. Otherwise here you're not testing the .cargo/config with the invalid target in it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok(())
})?;
let output = storage.to_string();
assert!(output.contains("cargo 1."));
assert!(!output.contains("1.0.0"));
build.cargo().args(&["run"]).run()?;
Ok(())
})?;
Ok(())
Expand Down