diff --git a/CHANGELOG.md b/CHANGELOG.md index 6235f44298a..3061e3464b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler-cli/src/dependencies.rs b/compiler-cli/src/dependencies.rs index 3269c71460f..1497978d7c1 100644 --- a/compiler-cli/src/dependencies.rs +++ b/compiler-cli/src/dependencies.rs @@ -724,7 +724,7 @@ fn resolve_versions( &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() diff --git a/compiler-core/src/io.rs b/compiler-core/src/io.rs index af349c38089..36927bceeae 100644 --- a/compiler-core/src/io.rs +++ b/compiler-core/src/io.rs @@ -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"), diff --git a/compiler-core/src/manifest.rs b/compiler-core/src/manifest.rs index f6a354a60c6..d0b9f2336b1 100644 --- a/compiler-core/src/manifest.rs +++ b/compiler-core/src/manifest.rs @@ -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"; @@ -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" }