Skip to content

Commit

Permalink
Fix Windows depfile paths in Phylum project files (#1500)
Browse files Browse the repository at this point in the history
The changes made here are emulating those made in #1496, but for the
`phylum_project` crate. This allows for more natural paths on Windows
systems. Other changes made include:

* Update `.phylum_project` file for this repo
  * Include the output/format from the current `phylum init` command
* Ensure `all-features` job in `Test` workflow has matching strategy
  • Loading branch information
maxrake authored Sep 20, 2024
1 parent 48325b6 commit 6a72fc6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
# Skip this job when the secret is unavailable
if: github.secret_source == 'Actions'
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-14]
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 3 additions & 3 deletions .phylum_project
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id: d84b0bb3-fb64-43cb-a473-dc96b54db662
name: cli
created_at: 2023-01-26T20:02:11.276987834+01:00
created_at: 2024-09-20T12:27:33.762071-05:00
group_name: integrations
lockfiles:
- path: Cargo.lock
depfiles:
- path: ./Cargo.lock
type: cargo
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Extensions for Windows release artifacts

### Fixed

- Phylum project file paths on Windows

## 7.0.0 - 2024-09-17

### Added
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions phylum_project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ edition = "2021"
rust-version = "1.64.0"

[dependencies]
phylum_types = { git = "https://github.com/phylum-dev/phylum-types", branch = "development" }
chrono = { version = "^0.4", default-features = false, features = ["serde", "clock"] }
dunce = "1.0.5"
log = "0.4.6"
phylum_types = { git = "https://github.com/phylum-dev/phylum-types", branch = "development" }
serde = { version = "1.0.144", features = ["derive"] }
serde_yaml = "0.9.2"
log = "0.4.6"

[dev-dependencies]
tempfile = "3.4.0"
Expand Down
31 changes: 20 additions & 11 deletions phylum_project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ProjectConfig {
.iter()
.map(|depfile| {
let path = self.root.join(&depfile.path);
DepfileConfig::new(path, depfile.depfile_type.clone())
DepfileConfig::new(dunce::simplified(&path), depfile.depfile_type.clone())
})
.collect();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn find_project_conf(
// If `path` is like `.`, `path.parent()` is `None`.
// Convert to a canonicalized path so removing components navigates up the
// directory hierarchy.
let mut path = starting_directory.as_ref().canonicalize().ok()?;
let mut path = dunce::canonicalize(starting_directory.as_ref()).ok()?;

for _ in 0..max_depth {
let conf_path = path.join(PROJ_CONF_FILE);
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
let mut config =
ProjectConfig::new(PROJECT_ID, PROJECT_NAME.to_owned(), Some(GROUP_NAME.to_owned()));
config.set_depfiles(vec![DepfileConfig {
path: PathBuf::from("Cargo.lock"),
path: PathBuf::from("./Cargo.lock"),
depfile_type: "cargo".to_owned(),
}]);

Expand All @@ -166,15 +166,15 @@ mod tests {
panic!("Expected to get exactly one depfile but got {depfiles:?}");
};

assert_eq!(&PathBuf::from("Cargo.lock"), &depfile.path);
assert_eq!(&PathBuf::from("./Cargo.lock"), &depfile.path);
}

#[test]
fn deserialized_config_has_correct_depfile_paths() {
let mut config =
ProjectConfig::new(PROJECT_ID, PROJECT_NAME.to_owned(), Some(GROUP_NAME.to_owned()));
config.set_depfiles(vec![DepfileConfig {
path: PathBuf::from("Cargo.lock"),
path: PathBuf::from("./Cargo.lock"),
depfile_type: "cargo".to_owned(),
}]);

Expand All @@ -186,25 +186,35 @@ mod tests {
panic!("Expected to get exactly one depfile but got {depfiles:?}");
};

assert_eq!(&PathBuf::from("Cargo.lock"), &depfile.path);
assert_eq!(&PathBuf::from("./Cargo.lock"), &depfile.path);
}

#[test]
fn when_root_set_has_correct_depfile_paths() {
let mut config =
ProjectConfig::new(PROJECT_ID, PROJECT_NAME.to_owned(), Some(GROUP_NAME.to_owned()));
config.set_depfiles(vec![DepfileConfig {
path: PathBuf::from("Cargo.lock"),
path: PathBuf::from("./Cargo.lock"),
depfile_type: "cargo".to_owned(),
}]);
config.root = PathBuf::from("/home/user/project");
#[cfg(not(windows))]
{
config.root = PathBuf::from("/home/user/project");
}
#[cfg(windows)]
{
config.root = PathBuf::from(r"C:\home\user\project");
}

let depfiles = config.depfiles();
let [depfile] = &depfiles[..] else {
panic!("Expected to get exactly one depfile but got {depfiles:?}");
};

#[cfg(not(windows))]
assert_eq!(&PathBuf::from("/home/user/project/Cargo.lock"), &depfile.path);
#[cfg(windows)]
assert_eq!(&PathBuf::from(r"C:\home\user\project\Cargo.lock"), &depfile.path);
}

#[cfg(any(unix, windows))]
Expand Down Expand Up @@ -246,9 +256,8 @@ mod tests {

let found = find_project_conf(&cwd, true);
assert_eq!(
Some(file.canonicalize().unwrap()),
found.map(|f| f
.canonicalize()
Some(dunce::canonicalize(file).unwrap()),
found.map(|f| dunce::canonicalize(f)
.expect("Found configuration should be a canonicalizable path"))
);
}
Expand Down

0 comments on commit 6a72fc6

Please sign in to comment.