diff --git a/tools/codegen/src/main.rs b/tools/codegen/src/main.rs index 55779266..f406a413 100644 --- a/tools/codegen/src/main.rs +++ b/tools/codegen/src/main.rs @@ -431,23 +431,26 @@ fn main() -> Result<()> { None => {} } - download_info.insert(platform, ManifestDownloadInfo { - url: Some(url), - etag, - hash, - bin: base_download_info.bin.as_ref().or(base_info.bin.as_ref()).map(|s| { - s.map(|s| { - replace_vars( - s, - package, - Some(version), - Some(platform), - base_info.rust_crate.as_deref(), - ) - .unwrap() - }) - }), - }); + download_info.insert( + platform, + ManifestDownloadInfo::new( + Some(url), + etag, + hash, + base_download_info.bin.as_ref().or(base_info.bin.as_ref()).map(|s| { + s.map(|s| { + replace_vars( + s, + package, + Some(version), + Some(platform), + base_info.rust_crate.as_deref(), + ) + .unwrap() + }) + }), + ), + ); buf.clear(); } if download_info.is_empty() { @@ -503,10 +506,7 @@ fn main() -> Result<()> { if semver_version.pre.is_empty() { semver_versions.insert(semver_version.clone()); } - manifests.map.insert( - reverse_semver, - ManifestRef::Real(Manifest { previous_stable_version: None, download_info }), - ); + manifests.map.insert(reverse_semver, ManifestRef::Real(Manifest::new(download_info))); // update an existing manifests.json to avoid discarding work done in the event of a fetch error. if existing_manifest.is_some() && !version_req_given { @@ -635,7 +635,7 @@ fn main() -> Result<()> { } let original_manifests = manifests.clone(); - let mut template = Some(ManifestTemplate { download_info: BTreeMap::new() }); + let mut template = Some(ManifestTemplate::default()); 'outer: for (version, manifest) in &mut manifests.map { let ManifestRef::Real(manifest) = manifest else { continue; @@ -652,10 +652,10 @@ fn main() -> Result<()> { break 'outer; } } else { - t.download_info.insert(*platform, ManifestTemplateDownloadInfo { - url: template_url, - bin: template_bin, - }); + t.download_info.insert( + *platform, + ManifestTemplateDownloadInfo::new(template_url, template_bin), + ); } } } diff --git a/tools/manifest-schema/CHANGELOG.md b/tools/manifest-schema/CHANGELOG.md index b1b26219..eb8ee0e3 100644 --- a/tools/manifest-schema/CHANGELOG.md +++ b/tools/manifest-schema/CHANGELOG.md @@ -12,6 +12,12 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com - Rename `ManifestDownloadInfo::checksum` field to `hash` to reduce manifest size. +- Make `Version`, `Manifests`, `Manifest`, `ManifestDownloadInfo`, `ManifestTemplate`, `ManifestTemplateDownloadInfo`, and `HostPlatform` `#[non_exhaustive]`. + +- Add `Manifest::new`, `ManifestDownloadInfo::new`, and `ManifestTemplateDownloadInfo::new`. + +- Implement `Default` for `ManifestTemplate`. + - Remove `BaseManifest` and related types since they are unrelated to public manifests. ## [0.1.1] - 2025-09-20 diff --git a/tools/manifest-schema/src/lib.rs b/tools/manifest-schema/src/lib.rs index 37a19a40..d4bab764 100644 --- a/tools/manifest-schema/src/lib.rs +++ b/tools/manifest-schema/src/lib.rs @@ -19,8 +19,8 @@ Structured access to the install-action manifests. missing_debug_implementations, // missing_docs, clippy::alloc_instead_of_core, - // clippy::exhaustive_enums, - // clippy::exhaustive_structs, + clippy::exhaustive_enums, + clippy::exhaustive_structs, clippy::impl_trait_in_params, clippy::std_instead_of_alloc, clippy::std_instead_of_core, @@ -58,6 +58,7 @@ pub fn get_manifest_schema_branch_name() -> &'static str { } #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub struct Version { pub major: Option, pub minor: Option, @@ -195,6 +196,7 @@ impl<'de> Deserialize<'de> for Version { } #[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[non_exhaustive] pub struct Manifests { pub rust_crate: Option, pub template: Option, @@ -206,12 +208,14 @@ pub struct Manifests { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] +#[allow(clippy::exhaustive_enums)] pub enum ManifestRef { Ref { version: Version }, Real(Manifest), } #[derive(Debug, Clone, Serialize, Deserialize)] +#[non_exhaustive] pub struct Manifest { #[serde(skip_serializing_if = "Option::is_none")] pub previous_stable_version: Option, @@ -219,7 +223,15 @@ pub struct Manifest { pub download_info: BTreeMap, } +impl Manifest { + #[must_use] + pub fn new(download_info: BTreeMap) -> Self { + Self { previous_stable_version: None, download_info } + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] +#[non_exhaustive] pub struct ManifestDownloadInfo { #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, @@ -230,13 +242,27 @@ pub struct ManifestDownloadInfo { pub bin: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +impl ManifestDownloadInfo { + #[must_use] + pub fn new( + url: Option, + etag: String, + hash: String, + bin: Option, + ) -> Self { + Self { url, etag, hash, bin } + } +} + +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[non_exhaustive] pub struct ManifestTemplate { #[serde(flatten)] pub download_info: BTreeMap, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[non_exhaustive] pub struct ManifestTemplateDownloadInfo { pub url: String, /// Path to binaries in archive. Default to `${tool}${exe}`. @@ -244,8 +270,16 @@ pub struct ManifestTemplateDownloadInfo { pub bin: Option, } +impl ManifestTemplateDownloadInfo { + #[must_use] + pub fn new(url: String, bin: Option) -> Self { + Self { url, bin } + } +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] +#[allow(clippy::exhaustive_enums)] pub enum StringOrArray { String(String), Array(Vec), @@ -291,6 +325,7 @@ impl StringOrArray { // TODO: support musl with dynamic linking like wasmtime and cyclonedx's musl binaries. #[allow(non_camel_case_types)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[non_exhaustive] pub enum HostPlatform { x86_64_linux_gnu, x86_64_linux_musl,