Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Fix conflict for git path dep to repo root

A path dependency of a git package that resolves to the repository
root produced an empty repo-relative path, stored as path: Some("").
This conflicted with the same package declared directly as a git
dependency with no path (path: None).

+71 -1
+11 -1
compiler-cli/src/dependencies.rs
··· 1524 1524 } => { 1525 1525 let (child_path, child_repo_path) = 1526 1526 resolve_git_path_package(&name, &path, repo, &package_path, repo_root)?; 1527 + // A path dependency resolving to the repository root has an 1528 + // empty repo-relative path. Normalise it to `None` so it 1529 + // matches a package declared directly as a git dependency 1530 + // with no path. 1531 + let child_repo_path = if child_repo_path.as_str().is_empty() { 1532 + None 1533 + } else { 1534 + Some(child_repo_path) 1535 + }; 1536 + 1527 1537 provide_package( 1528 1538 name.clone(), 1529 1539 child_path, 1530 1540 SourceContext::Git { 1531 1541 repo: repo.clone(), 1532 1542 commit: commit.clone(), 1533 - path: Some(child_repo_path), 1543 + path: child_repo_path, 1534 1544 repo_root, 1535 1545 }, 1536 1546 project_paths,
+60
compiler-cli/src/dependencies/tests.rs
··· 891 891 } 892 892 893 893 #[test] 894 + fn provided_git_path_package_to_repo_root_has_no_path() { 895 + let tmp = tempfile::tempdir().unwrap(); 896 + let base = Utf8PathBuf::from_path_buf(tmp.path().to_path_buf()).unwrap(); 897 + let repo = base.join("repo"); 898 + fs::mkdir(&repo.join("backends").join("package_a")).unwrap(); 899 + fs::write( 900 + &repo.join("gleam.toml"), 901 + r#" 902 + name = "package_b" 903 + version = "0.2.0" 904 + "#, 905 + ) 906 + .unwrap(); 907 + fs::write( 908 + &repo.join("backends").join("package_a").join("gleam.toml"), 909 + r#" 910 + name = "package_a" 911 + version = "0.1.0" 912 + 913 + [dependencies] 914 + package_b = { path = "../.." } 915 + "#, 916 + ) 917 + .unwrap(); 918 + 919 + let mut provided = HashMap::new(); 920 + let project_paths = crate::project_paths_at_current_directory_without_toml(); 921 + let repo_root = fs::canonicalise(&repo).unwrap(); 922 + let result = provide_package( 923 + "package_a".into(), 924 + fs::canonicalise(&repo.join("backends").join("package_a")).unwrap(), 925 + SourceContext::Git { 926 + repo: "https://github.com/gleam-lang/wibble.git".into(), 927 + commit: "95cd2c2f45907e5571e9b5fcdfb27ff35cdcdd29".into(), 928 + path: Some("backends/package_a".into()), 929 + repo_root: &repo_root, 930 + }, 931 + &project_paths, 932 + &mut provided, 933 + &mut vec!["root".into()], 934 + ); 935 + assert_eq!( 936 + result, 937 + Ok(hexpm::version::Range::new("== 0.1.0".into()).unwrap()) 938 + ); 939 + // A path dependency resolving to the repository root must match how the 940 + // same package is provided when declared directly as a git dependency 941 + // with no path (`None`), otherwise it is reported as a conflict. 942 + let package = provided.get("package_b").unwrap(); 943 + assert_eq!( 944 + package.source, 945 + ProvidedPackageSource::Git { 946 + repo: "https://github.com/gleam-lang/wibble.git".into(), 947 + commit: "95cd2c2f45907e5571e9b5fcdfb27ff35cdcdd29".into(), 948 + path: None, 949 + } 950 + ); 951 + } 952 + 953 + #[test] 894 954 fn provided_git_path_package_rejects_missing_directory() { 895 955 let tmp = tempfile::tempdir().unwrap(); 896 956 let base = Utf8PathBuf::from_path_buf(tmp.path().to_path_buf()).unwrap();