Skip to content
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

fix issue with windows local manifest paths being absolute #2842

Merged
merged 2 commits into from
Mar 30, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
assigned to the wrong definition in the doc site.
- Fixed a bug where the code blocks in the generated documentation's site would
have a wrong indentation.
- Fixed a bug where on windows local packages had absolute paths in the manifest
instead of relative.

### Language Server

Expand Down
2 changes: 1 addition & 1 deletion compiler-cli/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ fn resolve_versions<Telem: Telemetry>(
&locked,
)?;

// Convert the hex packages and local packages into manliest packages
// Convert the hex packages and local packages into manifest packages
let manifest_packages = runtime.block_on(future::try_join_all(
resolved
.into_iter()
Expand Down
9 changes: 9 additions & 0 deletions compiler-core/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ use camino::{Utf8Path, Utf8PathBuf};
/// The provided source path should be absolute, otherwise will panic.
pub fn make_relative(source_path: &Utf8Path, target_path: &Utf8Path) -> Utf8PathBuf {
assert!(source_path.is_absolute());
// Input target will always be canonicalised whereas source will not
// This causes problems with diffing on windows since canonicalised paths have a special root
// As such we are attempting to strip the target path
// Based on https://github.com/rust-lang/rust/issues/42869#issuecomment-1712317081
#[cfg(target_family = "windows")]
let binding = target_path.to_string();
#[cfg(target_family = "windows")]
let target_path = Utf8Path::new(binding.trim_start_matches(r"\\?\"));

match target_path.is_absolute() {
true => pathdiff::diff_utf8_paths(target_path, source_path)
.expect("Should not fail on two absolute paths"),
Expand Down
113 changes: 113 additions & 0 deletions compiler-core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ mod tests {
#[cfg(windows)]
const PACKAGE: &'static str = "C:\\home\\louis\\packages\\path\\to\\package";

#[cfg(windows)]
const PACKAGE_WITH_UNC: &'static str = "\\\\?\\C:\\home\\louis\\packages\\path\\to\\package";

#[cfg(not(windows))]
const HOME: &str = "/home/louis/packages/some_folder";

Expand Down Expand Up @@ -318,6 +321,116 @@ packages = [
{ name = "zzz", version = "0.4.0", build_tools = ["mix"], requirements = [], source = "hex", outer_checksum = "0316" },
]

[requirements]
aaa = { version = "> 0.0.0" }
awsome_local1 = { path = "../path/to/package" }
awsome_local2 = { git = "https://github.com/gleam-lang/gleam.git" }
gleam_stdlib = { version = "~> 0.17" }
gleeunit = { version = "~> 0.1" }
zzz = { version = "> 0.0.0" }
"#
);
}

#[cfg(windows)]
#[test]
fn manifest_toml_format_with_unc() {
let manifest = Manifest {
requirements: [
("zzz".into(), Requirement::hex("> 0.0.0")),
("aaa".into(), Requirement::hex("> 0.0.0")),
(
"awsome_local2".into(),
Requirement::git("https://github.com/gleam-lang/gleam.git"),
),
(
"awsome_local1".into(),
Requirement::path("../path/to/package"),
),
("gleam_stdlib".into(), Requirement::hex("~> 0.17")),
("gleeunit".into(), Requirement::hex("~> 0.1")),
]
.into(),
packages: vec![
ManifestPackage {
name: "gleam_stdlib".into(),
version: Version::new(0, 17, 1),
build_tools: ["gleam".into()].into(),
otp_app: None,
requirements: vec![],
source: ManifestPackageSource::Hex {
outer_checksum: Base16Checksum(vec![1, 22]),
},
},
ManifestPackage {
name: "aaa".into(),
version: Version::new(0, 4, 0),
build_tools: ["rebar3".into(), "make".into()].into(),
otp_app: Some("aaa_app".into()),
requirements: vec!["zzz".into(), "gleam_stdlib".into()],
source: ManifestPackageSource::Hex {
outer_checksum: Base16Checksum(vec![3, 22]),
},
},
ManifestPackage {
name: "zzz".into(),
version: Version::new(0, 4, 0),
build_tools: ["mix".into()].into(),
otp_app: None,
requirements: vec![],
source: ManifestPackageSource::Hex {
outer_checksum: Base16Checksum(vec![3, 22]),
},
},
ManifestPackage {
name: "awsome_local2".into(),
version: Version::new(1, 2, 3),
build_tools: ["gleam".into()].into(),
otp_app: None,
requirements: vec![],
source: ManifestPackageSource::Git {
repo: "https://github.com/gleam-lang/gleam.git".into(),
commit: "bd9fe02f72250e6a136967917bcb1bdccaffa3c8".into(),
},
},
ManifestPackage {
name: "awsome_local1".into(),
version: Version::new(1, 2, 3),
build_tools: ["gleam".into()].into(),
otp_app: None,
requirements: vec![],
source: ManifestPackageSource::Local {
path: PACKAGE_WITH_UNC.into(),
},
},
ManifestPackage {
name: "gleeunit".into(),
version: Version::new(0, 4, 0),
build_tools: ["gleam".into()].into(),
otp_app: None,
requirements: vec!["gleam_stdlib".into()],
source: ManifestPackageSource::Hex {
outer_checksum: Base16Checksum(vec![3, 46]),
},
},
],
};

let buffer = manifest.to_toml(HOME.into());
assert_eq!(
buffer,
r#"# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
{ name = "aaa", version = "0.4.0", build_tools = ["rebar3", "make"], requirements = ["gleam_stdlib", "zzz"], otp_app = "aaa_app", source = "hex", outer_checksum = "0316" },
{ name = "awsome_local1", version = "1.2.3", build_tools = ["gleam"], requirements = [], source = "local", path = "../path/to/package" },
{ name = "awsome_local2", version = "1.2.3", build_tools = ["gleam"], requirements = [], source = "git", repo = "https://github.com/gleam-lang/gleam.git", commit = "bd9fe02f72250e6a136967917bcb1bdccaffa3c8" },
{ name = "gleam_stdlib", version = "0.17.1", build_tools = ["gleam"], requirements = [], source = "hex", outer_checksum = "0116" },
{ name = "gleeunit", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "hex", outer_checksum = "032E" },
{ name = "zzz", version = "0.4.0", build_tools = ["mix"], requirements = [], source = "hex", outer_checksum = "0316" },
]

[requirements]
aaa = { version = "> 0.0.0" }
awsome_local1 = { path = "../path/to/package" }
Expand Down
Loading