diff --git a/cargo-dist/src/config/v0_to_v1.rs b/cargo-dist/src/config/v0_to_v1.rs index 8377fd184..725e8a2b5 100644 --- a/cargo-dist/src/config/v0_to_v1.rs +++ b/cargo-dist/src/config/v0_to_v1.rs @@ -328,22 +328,24 @@ impl DistMetadata { }; // TODO: remove this debug code - eprintln!("!!!!!!"); - eprintln!("{}", axoasset::toml::to_string_pretty(&layer).unwrap()); - eprintln!("------"); - let layer2: TomlLayer = match axoasset::SourceFile::new( - "temp.toml", - axoasset::toml::to_string_pretty(&layer).unwrap(), - ) - .deserialize_toml() - { - Ok(l) => l, - Err(e) => { - eprintln!("{:?}", miette::Report::new(e)); - panic!("aaa"); - } - }; - eprintln!("{}", axoasset::toml::to_string_pretty(&layer2).unwrap()); + if cfg!(gankra_debug) { + eprintln!("!!!!!!"); + eprintln!("{}", axoasset::toml::to_string_pretty(&layer).unwrap()); + eprintln!("------"); + let layer2: TomlLayer = match axoasset::SourceFile::new( + "temp.toml", + axoasset::toml::to_string_pretty(&layer).unwrap(), + ) + .deserialize_toml() + { + Ok(l) => l, + Err(e) => { + eprintln!("{:?}", miette::Report::new(e)); + panic!("aaa"); + } + }; + eprintln!("{}", axoasset::toml::to_string_pretty(&layer2).unwrap()); + } layer } } diff --git a/cargo-dist/src/config/v1/mod.rs b/cargo-dist/src/config/v1/mod.rs index 5808c9511..6eab7cdaa 100644 --- a/cargo-dist/src/config/v1/mod.rs +++ b/cargo-dist/src/config/v1/mod.rs @@ -22,7 +22,13 @@ use installers::*; use publishers::*; /// Compute the workspace-level config -pub fn workspace_config(workspaces: &WorkspaceGraph, global_config: TomlLayer) -> WorkspaceConfig { +pub fn workspace_config( + workspaces: &WorkspaceGraph, + mut global_config: TomlLayer, +) -> WorkspaceConfig { + // Rewrite config-file-relative paths + global_config.make_relative_to(&workspaces.root_workspace().workspace_dir); + let mut config = WorkspaceConfigInheritable::defaults_for_workspace(workspaces); config.apply_layer(global_config); config.apply_inheritance_for_workspace(workspaces) @@ -32,9 +38,14 @@ pub fn workspace_config(workspaces: &WorkspaceGraph, global_config: TomlLayer) - pub fn app_config( workspaces: &WorkspaceGraph, pkg_idx: PackageIdx, - global_config: TomlLayer, - local_config: TomlLayer, + mut global_config: TomlLayer, + mut local_config: TomlLayer, ) -> AppConfig { + // Rewrite config-file-relative paths + let package = workspaces.package(pkg_idx); + global_config.make_relative_to(&workspaces.root_workspace().workspace_dir); + local_config.make_relative_to(&package.package_root); + let mut config = AppConfigInheritable::defaults_for_package(workspaces, pkg_idx); config.apply_layer(global_config); config.apply_layer(local_config); @@ -274,3 +285,35 @@ pub struct TomlLayer { #[serde(skip_serializing_if = "Option::is_none")] pub publishers: Option, } + +impl TomlLayer { + /// TODO + fn make_relative_to(&mut self, base_path: &Utf8Path) { + // It's kind of unfortunate that we don't exhaustively match this to + // force you to update it BUT almost no config is ever applicable for + // this so even when we used to, everyone just skimmed over this so + // whatever just Get Good and remember this transform is necessary + // if you every add another config-file-relative path to the config + if let Some(artifacts) = &mut self.artifacts { + if let Some(archives) = &mut artifacts.archives { + if let Some(include) = &mut archives.include { + for path in include { + make_path_relative_to(path, base_path); + } + } + } + if let Some(extras) = &mut artifacts.extra { + for extra in extras { + make_path_relative_to(&mut extra.working_dir, base_path); + } + } + } + } +} + +fn make_path_relative_to(path: &mut Utf8PathBuf, base_path: &Utf8Path) { + // TODO: should absolute paths be a hard error? Or should we force them relative? + if !path.is_absolute() { + *path = base_path.join(&path); + } +} diff --git a/cargo-dist/src/tasks.rs b/cargo-dist/src/tasks.rs index e277d8d51..91ad85593 100644 --- a/cargo-dist/src/tasks.rs +++ b/cargo-dist/src/tasks.rs @@ -839,9 +839,9 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { root_workspace.cargo_metadata_table.as_ref(), )?; - workspace_metadata.make_relative_to(&root_workspace.workspace_dir); let workspace_layer = workspace_metadata.to_toml_layer(true); let config = workspace_config(workspaces, workspace_layer.clone()); + workspace_metadata.make_relative_to(&root_workspace.workspace_dir); // This is intentionally written awkwardly to make you update this // @@ -961,13 +961,14 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { &package.manifest_path, package.cargo_metadata_table.as_ref(), )?; - package_metadata.make_relative_to(&package.package_root); package_configs.push(app_config( workspaces, pkg_idx, workspace_layer.clone(), package_metadata.to_toml_layer(false), )); + + package_metadata.make_relative_to(&package.package_root); package_metadata.merge_workspace_config(&workspace_metadata, &package.manifest_path); package_metadata.validate_install_paths()?; @@ -2569,8 +2570,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { &[ InstallerStyle::Shell, InstallerStyle::Powershell, - InstallerStyle::Npm, InstallerStyle::Homebrew, + InstallerStyle::Npm, InstallerStyle::Msi, ] } else { @@ -2581,8 +2582,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> { match installer { InstallerStyle::Shell => self.add_shell_installer(release)?, InstallerStyle::Powershell => self.add_powershell_installer(release)?, - InstallerStyle::Npm => self.add_npm_installer(release)?, InstallerStyle::Homebrew => self.add_homebrew_installer(release)?, + InstallerStyle::Npm => self.add_npm_installer(release)?, InstallerStyle::Msi => self.add_msi_installer(release)?, } } diff --git a/cargo-dist/tests/snapshots/error_manifest.snap b/cargo-dist/tests/snapshots/error_manifest.snap index 9ed4dd144..88424f7a1 100644 --- a/cargo-dist/tests/snapshots/error_manifest.snap +++ b/cargo-dist/tests/snapshots/error_manifest.snap @@ -18,6 +18,3 @@ If you haven't yet signed up, please join our discord --tag=v1.0.0-FAKEVERSION will Announce: cargo-dist you can also request any single package with --tag=cargo-dist-v1.0.0-FAKEVERSION - - -