Skip to content

Commit

Permalink
Fix path issue for Windows (use-ink#313)
Browse files Browse the repository at this point in the history
* Run tests for Windows

* Add test to reproduce error

* Canonicalize paths in test

* Revert me: Run only necessary tests

* Join `Path`'s to avoid OS-specific separators

* Revert me: Debug output

* Fix workflow

* Revert me: Debugging

* Windows debugging

* More debugging

* Debugging

* Debugging

* Add nightly

* Debugging

* Debugging

* Debugging

* Debugging

* Debugging

* Fix commands

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Debug path

* Remove eprintln's

* Test should fail

* Test should run

* Test should run

* Restore Windows testing

* Apply `cargo fmt`

* Fix default

* Remove debug stuff

* Run tests only `master`

* Update changelog
  • Loading branch information
Michael Müller authored Aug 3, 2021
1 parent 1d743e2 commit c76ffc6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
19 changes: 18 additions & 1 deletion src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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<Option<toml::Value>> {
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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c76ffc6

Please sign in to comment.