diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index ab7b403383dfccfd255f803981186e416f48e52f..6ba9530199e82b05969552214eaf368556342001 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -56,3 +56,10 @@ jobs: cargo run -- contract new foobar echo "[workspace]" >> foobar/Cargo.toml cargo run -- contract build --manifest-path=foobar/Cargo.toml + + - name: Run tests on {{ matrix.platform }}-${{ matrix.toolchain }} + # The tests take a long time in the GitHub Actions runner (~30 mins), + # hence we run them only on `master`. + if: github.ref == 'refs/heads/master' + run: | + cargo test --verbose --workspace --all-features diff --git a/CHANGELOG.md b/CHANGELOG.md index c62a161d0003a9fe2ba4e09c33482c8c6499c985..4e68e7b173ee7af3c4921830f574dd56e2a3b42e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed a Windows issue with contract files in sub-folders - [#313](https://github.com/paritytech/cargo-contract/pull/313) + ## [0.13.0] - 2021-07-22 ### Added diff --git a/src/cmd/build.rs b/src/cmd/build.rs index cf2ef906f6ecb8338284d227fa83380d39df24e0..bafa1d31372fbc8ae18a567f443b8dcced5a6d1a 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -1109,6 +1109,41 @@ mod tests_ci_only { }) } + #[test] + fn building_contract_with_source_file_in_subfolder_must_work() { + with_new_contract_project(|manifest_path| { + // given + let path = manifest_path.directory().expect("dir must exist"); + let old_lib_path = path.join(Path::new("lib.rs")); + let new_lib_path = path.join(Path::new("srcfoo")).join(Path::new("lib.rs")); + let new_dir_path = path.join(Path::new("srcfoo")); + std::fs::create_dir_all(new_dir_path).expect("creating dir must work"); + std::fs::rename(old_lib_path, new_lib_path).expect("moving file must work"); + + let mut manifest = + Manifest::new(manifest_path.clone()).expect("creating manifest must work"); + manifest + .set_lib_path("srcfoo/lib.rs") + .expect("setting lib path must work"); + manifest.write(&manifest_path).expect("writing must work"); + + // when + let res = super::execute( + &manifest_path, + Verbosity::Default, + BuildMode::default(), + BuildArtifacts::CheckOnly, + UnstableFlags::default(), + OptimizationPasses::default(), + Default::default(), + ); + + // then + assert!(res.is_ok(), "building contract failed!"); + Ok(()) + }) + } + #[test] fn keep_debug_symbols_in_debug_mode() { with_new_contract_project(|manifest_path| { diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index fba2d0b052014e8f1e8b6da9cb2a0543bc6e5ce8..24f47c0368443c9348c51caa878901da6d7dcc7e 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -19,9 +19,9 @@ use anyhow::{Context, Result}; use super::{metadata, Profile}; use crate::OptimizationPasses; -use std::convert::TryFrom; use std::{ collections::HashSet, + convert::TryFrom, fs, path::{Path, PathBuf}, }; @@ -248,6 +248,19 @@ impl Manifest { .insert("name".into(), value::Value::String(name.into()))) } + /// Set the `lib` path to `path`. + #[cfg(feature = "test-ci-only")] + #[cfg(test)] + pub fn set_lib_path(&mut self, path: &str) -> Result> { + Ok(self + .toml + .get_mut("lib") + .ok_or_else(|| anyhow::anyhow!("[lib] section not found"))? + .as_table_mut() + .ok_or_else(|| anyhow::anyhow!("[lib] should be a table"))? + .insert("path".into(), value::Value::String(path.into()))) + } + /// Set `[profile.release]` lto flag pub fn with_profile_release_lto(&mut self, enabled: bool) -> Result<&mut Self> { let lto = self @@ -355,6 +368,10 @@ impl Manifest { let path_str = existing_path .as_str() .ok_or_else(|| anyhow::anyhow!("{} should be a string", value_id))?; + #[cfg(windows)] + // On Windows path separators are `\`, hence we need to replace the `/` in + // e.g. `src/lib.rs`. + let path_str = &path_str.replace("/", "\\"); let path = PathBuf::from(path_str); if path.is_relative() { let lib_abs = abs_dir.join(path);