Skip to content

Commit

Permalink
chore: add make_relative_to to v1 config
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Jul 31, 2024
1 parent d74ee47 commit 0fd29a2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
34 changes: 18 additions & 16 deletions cargo-dist/src/config/v0_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
49 changes: 46 additions & 3 deletions cargo-dist/src/config/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -274,3 +285,35 @@ pub struct TomlLayer {
#[serde(skip_serializing_if = "Option::is_none")]
pub publishers: Option<PublisherLayer>,
}

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);
}
}
9 changes: 5 additions & 4 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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()?;

Expand Down Expand Up @@ -2569,8 +2570,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
&[
InstallerStyle::Shell,
InstallerStyle::Powershell,
InstallerStyle::Npm,
InstallerStyle::Homebrew,
InstallerStyle::Npm,
InstallerStyle::Msi,
]
} else {
Expand All @@ -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)?,
}
}
Expand Down
3 changes: 0 additions & 3 deletions cargo-dist/tests/snapshots/error_manifest.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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



0 comments on commit 0fd29a2

Please sign in to comment.