Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
953b2db
Have "dist init" only migrate from Cargo.toml configs to v0 generic c…
duckinator Dec 18, 2024
e1576c3
Make "dist migrate" convert from v0 to v1 config.
duckinator Dec 18, 2024
0b7f6d8
[WIP, BROKEN] start making "dist init" use v1 config
duckinator Dec 20, 2024
9f39ac6
[WIP, BROKEN] apply_*() at least seem like they'll compile now
duckinator Jan 7, 2025
1d9f415
Add BoolOr::truthy() to simplify logic elsewhere.
duckinator Jan 8, 2025
0999c3a
derive Default for InstallerLayer.
duckinator Jan 8, 2025
f9527bf
Migrate first chunk of get_new_dist_metadata() to v1 config
duckinator Jan 8, 2025
b0ff20a
derive Default for PublisherLayer.
duckinator Jan 8, 2025
942ec4e
made enough progress on get_new_dist_metadata() that i'm getting owne…
duckinator Jan 8, 2025
05867a5
[formatting cleanup] clean up /* and */ indentation levels, and white…
duckinator Jan 9, 2025
4cf359e
formatting cleanup
duckinator Jan 9, 2025
441902c
initial stab at cleaning up ownership etc
mistydemeo Jan 9, 2025
3434474
Have "dist init" run do_migrate() if using a v0 config.
duckinator Jan 9, 2025
c376686
Have "dist generate" print an error if you have a v0 config.
duckinator Jan 9, 2025
25eab8c
[WIP] attempt to migrate "dist generate" to v1 config
duckinator Jan 9, 2025
46dc61d
have is_v0_config() return false when trying to load v1 configs.
duckinator Jan 9, 2025
9abf07c
Revert "have is_v0_config() return false when trying to load v1 confi…
duckinator Jan 9, 2025
ddef86e
Use try_load_config() instead of parse_metadata_table_or_manifest() i…
duckinator Jan 9, 2025
77872aa
??? third ??? attempt at making is_v0_config work right
duckinator Jan 9, 2025
d833cd9
Try being more precise about config versions
mistydemeo Jan 10, 2025
931ba50
Fix package config handling
mistydemeo Jan 10, 2025
37b251a
init: handle CLI hosting options
mistydemeo Jan 10, 2025
dfdec22
init: update installers to use orig_meta
mistydemeo Jan 10, 2025
20b9a88
Make "dist init" automatically migrate from v0 to v1 config.
duckinator Jan 10, 2025
495726f
Have init perform migrations before everything else.
duckinator Jan 10, 2025
230eed5
Have apply_dist_to_metadata() handle targets field.
duckinator Jan 10, 2025
152e1fa
add some ... plumbing?... related code to apply_dist_to_metadata()
duckinator Jan 10, 2025
083daaa
v1: remove duplicate hosts.github handler
mistydemeo Jan 10, 2025
29b2df1
config: remove unused functions
mistydemeo Jan 10, 2025
983610d
More dist init TOML formatting.
duckinator Jan 10, 2025
107e212
Have dist init add most of the comments for [dist.installers]
duckinator Jan 10, 2025
83a7619
Have "dist init" add comments under [dist.installers] for things in C…
duckinator Jan 10, 2025
99d1d02
add TODO(migration) comments for tracking what work needs to be done
duckinator Jan 13, 2025
52d1caf
Remove dead code.
duckinator Jan 13, 2025
3e6c407
Only have "dist init" show online installers if we have somewhere to …
duckinator Jan 13, 2025
6ddf8a0
removed now-unused argument to apply_dist_to_workspace_toml().
duckinator Jan 13, 2025
19b73f6
move pkg to offline/bundled installers; remove now-unneeded apply_opt…
duckinator Jan 13, 2025
61765c2
Remove unneeded code.
duckinator Jan 13, 2025
896a4f8
Finish apply_installers_homebrew().
duckinator Jan 13, 2025
849b1b5
remove commented-out code
duckinator Jan 13, 2025
86292bc
apply_artifacts()
duckinator Jan 13, 2025
6bc0d1c
fix apply_installers_homebrew()
duckinator Jan 13, 2025
0dd9e54
resolve clippy warnings
duckinator Jan 13, 2025
8061922
Rename BoolOr::truthy() to BoolOr::not_false()
duckinator Jan 14, 2025
1684847
Add BoolOrOptExt, implementing Option<BoolOr<T>>::none_or_false()
duckinator Jan 14, 2025
8f76407
re-enable inlining the default install_path if not specified
duckinator Jan 14, 2025
7f746ba
minor cleanup
duckinator Jan 14, 2025
9ef9e4e
finish implementing apply_installers_npm()
duckinator Jan 14, 2025
b045a9d
finish apply_installers_msi()
duckinator Jan 14, 2025
b9489c8
Add Option<BoolOr<T>>::is_some_and_not_false(), use get_or_insert{,_w…
duckinator Jan 14, 2025
3901685
use is_some_and_not_false() more
duckinator Jan 14, 2025
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
81 changes: 73 additions & 8 deletions cargo-dist/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cargo_dist_schema::{
use serde::{Deserialize, Serialize};

use crate::announce::TagSettings;
use crate::config::v1::{DistWorkspaceConfig, TomlLayer};
use crate::SortedMap;
use crate::{
errors::{DistError, DistResult},
Expand All @@ -22,7 +23,7 @@ pub mod v0;
pub mod v0_to_v1;
pub mod v1;

pub use v0::{DistMetadata, GenericConfig};
pub use v0::{DistMetadata, GenericConfig, V0WorkspaceConfig};

/// values of the form `permission-name: read`
pub type GithubPermissionMap = SortedMap<String, GithubPermission>;
Expand Down Expand Up @@ -678,6 +679,12 @@ impl ChecksumStyle {
}
}

impl std::fmt::Display for ChecksumStyle {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.ext())
}
}

/// Which style(s) of configuration to generate
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum GenerateMode {
Expand Down Expand Up @@ -929,25 +936,79 @@ impl std::fmt::Display for ProductionMode {
}
}

pub(crate) fn try_load_config(
dist_manifest_path: Option<&Utf8PathBuf>,
) -> DistResult<DistWorkspaceConfig> {
let path = dist_manifest_path.ok_or(DistError::NoDistManifest {})?;
load_config(path)
}

pub(crate) fn try_load_package_config(
dist_manifest_path: Option<&Utf8PathBuf>,
) -> DistResult<TomlLayer> {
if let Some(dist_manifest_path) = dist_manifest_path {
let src = SourceFile::load_local(dist_manifest_path)?;
Ok(parse_config(src)?.dist)
} else {
Ok(Default::default())
}
}

pub(crate) fn load_config(dist_manifest_path: &Utf8PathBuf) -> DistResult<DistWorkspaceConfig> {
let src = SourceFile::load_local(dist_manifest_path.as_path())?;
parse_config(src)
}

pub(crate) fn parse_config(src: SourceFile) -> DistResult<DistWorkspaceConfig> {
let config: DistWorkspaceConfig = src.deserialize_toml()?;
Ok(config)
}

pub(crate) fn parse_metadata_table_or_manifest(
manifest_path: &Utf8Path,
dist_manifest_path: Option<&Utf8Path>,
metadata_table: Option<&serde_json::Value>,
) -> DistResult<DistMetadata> {
) -> DistResult<TomlLayer> {
if let Some(dist_manifest_path) = dist_manifest_path {
reject_metadata_table(manifest_path, dist_manifest_path, metadata_table)?;
// Generic dist.toml
let src = SourceFile::load_local(dist_manifest_path)?;
parse_generic_config(src)
Ok(parse_config(src)?.dist)
} else {
// Pre-parsed Rust metadata table
parse_metadata_table(manifest_path, metadata_table)
}
}

pub(crate) fn parse_generic_config(src: SourceFile) -> DistResult<DistMetadata> {
let config: GenericConfig = src.deserialize_toml()?;
Ok(config.dist.unwrap_or_default())
// Extremely minimal struct designed to catch the most visible difference
// between V0 and V1 config.
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
struct FauxV0 {
#[allow(dead_code)]
cargo_dist_version: String,
}

#[derive(Deserialize)]
struct FauxConfigV0 {
#[allow(dead_code)]
dist: FauxV0,
}

pub(crate) fn looks_like_v0_config(dist_manifest_path: &Utf8Path) -> bool {
let Ok(src) = SourceFile::load_local(dist_manifest_path) else {
return false;
};
src.deserialize_toml::<FauxConfigV0>().is_ok()
}

pub(crate) fn load_v0_config(dist_manifest_path: &Utf8Path) -> DistResult<V0WorkspaceConfig> {
let src = SourceFile::load_local(dist_manifest_path)?;
parse_v0_config(src)
}

pub(crate) fn parse_v0_config(src: SourceFile) -> DistResult<V0WorkspaceConfig> {
Ok(src.deserialize_toml()?)
}

pub(crate) fn reject_metadata_table(
Expand All @@ -969,10 +1030,14 @@ pub(crate) fn reject_metadata_table(
pub(crate) fn parse_metadata_table(
manifest_path: &Utf8Path,
metadata_table: Option<&serde_json::Value>,
) -> DistResult<DistMetadata> {
) -> DistResult<TomlLayer> {
if looks_like_v0_config(manifest_path) {
return Err(DistError::OldConfigFormat {});
}

Ok(metadata_table
.and_then(|t| t.get(METADATA_DIST))
.map(DistMetadata::deserialize)
.map(TomlLayer::deserialize)
.transpose()
.map_err(|cause| DistError::CargoTomlParse {
manifest_path: manifest_path.to_owned(),
Expand Down
13 changes: 13 additions & 0 deletions cargo-dist/src/config/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ use super::*;
use crate::platform::MinGlibcVersion;
use crate::SortedMap;

use crate::config::v1::{PackageTable, WorkspaceTable};

/// A container to assist deserializing the entirety of `dist-workspace.toml`.
#[derive(Debug, Deserialize)]
pub struct V0WorkspaceConfig {
/// the `[workspace]` table.
pub workspace: Option<WorkspaceTable>,
/// the `[package]` table.
pub package: Option<PackageTable>,
/// the `[dist]` table.
pub dist: Option<DistMetadata>,
}

/// A container to assist deserializing metadata from dist(-workspace).tomls
#[derive(Debug, Deserialize)]
pub struct GenericConfig {
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/config/v1/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct WorkspaceArtifactConfig {
pub checksum: ChecksumStyle,
}
/// artifact config (raw from file)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct ArtifactLayer {
/// archive config
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/config/v1/installers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct InstallerConfigInheritable {
}

/// installer config (raw from file)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct InstallerLayer {
/// inheritable fields
Expand Down
41 changes: 41 additions & 0 deletions cargo-dist/src/config/v1/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,44 @@ pub enum BoolOr<T> {
/// They gave a more interesting value
Val(T),
}

impl<T> BoolOr<T> {
/// Returns true if it is `BoolOr::Bool(true)`, or if it contains a value.
pub fn not_false(&self) -> bool {
match self {
BoolOr::Bool(b) => *b,
BoolOr::Val(_v) => true,
}
}
}

/// Extension trait to provide Option<BoolOr<T>>::none_or_false()
pub trait BoolOrOptExt
where
Self: Sized,
{
/// Given an Option<BoolOr<T>>, returns `true` if the value is
/// `None` or `Some(BoolOr::Bool(false))`.
fn none_or_false(&self) -> bool;

/// Given an Option<BoolOr<T>>, returns `true` if the value is
/// a `Some(BoolOr::Val(...))` or `Some(BoolOr::Bool(true))`.
fn is_some_and_not_false(&self) -> bool;
}
impl<T> BoolOrOptExt for Option<BoolOr<T>> {
fn none_or_false(&self) -> bool {
if let Some(item) = self {
!item.not_false()
} else {
true
}
}

fn is_some_and_not_false(&self) -> bool {
if let Some(item) = self {
item.not_false()
} else {
false
}
}
}
Loading