Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metadata] remove support for registry custom section #1941

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 1 addition & 15 deletions crates/wasm-metadata/src/add_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{rewrite_wasm, Author, Description, Licenses, Producers, RegistryMetadata, Source};
use crate::{rewrite_wasm, Author, Description, Licenses, Producers, Source};

use anyhow::Result;

Expand Down Expand Up @@ -41,10 +41,6 @@ pub struct AddMetadata {
/// URL to get source code for building the image
#[cfg_attr(feature = "clap", clap(long, value_name = "NAME"))]
pub source: Option<Source>,

/// Add an registry metadata to the registry-metadata section
#[cfg_attr(feature="clap", clap(long, value_parser = parse_registry_metadata_value, value_name="PATH"))]
pub registry_metadata: Option<RegistryMetadata>,
}

#[cfg(feature = "clap")]
Expand All @@ -54,15 +50,6 @@ pub(crate) fn parse_key_value(s: &str) -> Result<(String, String)> {
.ok_or_else(|| anyhow::anyhow!("expected KEY=VALUE"))
}

#[cfg(feature = "clap")]
pub(crate) fn parse_registry_metadata_value(s: &str) -> Result<RegistryMetadata> {
let contents = std::fs::read(s)?;

let registry_metadata = RegistryMetadata::from_bytes(&contents, 0)?;

Ok(registry_metadata)
}

impl AddMetadata {
/// Process a WebAssembly binary. Supports both core WebAssembly modules, and WebAssembly
/// components. The module and component will have, at very least, an empty name and producers
Expand All @@ -75,7 +62,6 @@ impl AddMetadata {
&self.description,
&self.licenses,
&self.source,
self.registry_metadata.as_ref(),
input,
)
}
Expand Down
2 changes: 0 additions & 2 deletions crates/wasm-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use metadata::Metadata;
pub use names::{ComponentNames, ModuleNames};
pub use oci_annotations::{Author, Description, Licenses, Source};
pub use producers::{Producers, ProducersField};
pub use registry::{CustomLicense, Link, LinkType, RegistryMetadata};

pub(crate) use rewrite::rewrite_wasm;

Expand All @@ -16,7 +15,6 @@ mod metadata;
mod names;
mod oci_annotations;
mod producers;
mod registry;
mod rewrite;

pub(crate) mod utils;
40 changes: 2 additions & 38 deletions crates/wasm-metadata/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use std::fmt;
use std::ops::Range;
use wasmparser::{KnownCustom, Parser, Payload::*};

use crate::{
Author, ComponentNames, Description, Licenses, ModuleNames, Producers, RegistryMetadata, Source,
};
use crate::{Author, ComponentNames, Description, Licenses, ModuleNames, Producers, Source};

/// A tree of the metadata found in a WebAssembly binary.
#[derive(Debug, Serialize)]
Expand All @@ -18,8 +16,6 @@ pub enum Metadata {
name: Option<String>,
/// The component's producers section, if any.
producers: Option<Producers>,
/// The component's registry metadata section, if any.
registry_metadata: Option<RegistryMetadata>,
/// The component's author section, if any.
author: Option<Author>,
/// Human-readable description of the binary
Expand All @@ -39,8 +35,6 @@ pub enum Metadata {
name: Option<String>,
/// The module's producers section, if any.
producers: Option<Producers>,
/// The module's registry metadata section, if any.
registry_metadata: Option<RegistryMetadata>,
/// The component's author section, if any.
author: Option<Author>,
/// Human-readable description of the binary
Expand Down Expand Up @@ -116,14 +110,6 @@ impl Metadata {
.expect("non-empty metadata stack")
.set_producers(producers);
}
KnownCustom::Unknown if c.name() == "registry-metadata" => {
let registry: RegistryMetadata =
RegistryMetadata::from_bytes(&c.data(), 0)?;
metadata
.last_mut()
.expect("non-empty metadata stack")
.set_registry_metadata(registry);
}
KnownCustom::Unknown if c.name() == "author" => {
let a = Author::parse_custom_section(&c)?;
match metadata.last_mut().expect("non-empty metadata stack") {
Expand Down Expand Up @@ -170,7 +156,6 @@ impl Metadata {
description: None,
licenses: None,
source: None,
registry_metadata: None,
children: Vec::new(),
range,
}
Expand All @@ -184,7 +169,6 @@ impl Metadata {
description: None,
licenses: None,
source: None,
registry_metadata: None,
range,
}
}
Expand All @@ -200,16 +184,6 @@ impl Metadata {
Metadata::Component { producers, .. } => *producers = Some(p),
}
}
fn set_registry_metadata(&mut self, r: RegistryMetadata) {
match self {
Metadata::Module {
registry_metadata, ..
} => *registry_metadata = Some(r),
Metadata::Component {
registry_metadata, ..
} => *registry_metadata = Some(r),
}
}
fn push_child(&mut self, child: Self) {
match self {
Metadata::Module { .. } => panic!("module shouldnt have children"),
Expand All @@ -221,10 +195,7 @@ impl Metadata {
let spaces = std::iter::repeat(" ").take(indent).collect::<String>();
match self {
Metadata::Module {
name,
producers,
registry_metadata,
..
name, producers, ..
} => {
if let Some(name) = name {
writeln!(f, "{spaces}module {name}:")?;
Expand All @@ -234,15 +205,11 @@ impl Metadata {
if let Some(producers) = producers {
producers.display(f, indent + 4)?;
}
if let Some(registry_metadata) = registry_metadata {
registry_metadata.display(f, indent + 4)?;
}
Ok(())
}
Metadata::Component {
name,
producers,
registry_metadata,
children,
..
} => {
Expand All @@ -254,9 +221,6 @@ impl Metadata {
if let Some(producers) = producers {
producers.display(f, indent + 4)?;
}
if let Some(registry_metadata) = registry_metadata {
registry_metadata.display(f, indent + 4)?;
}
for c in children {
c.display(f, indent + 4)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-metadata/src/producers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Producers {
/// Merge into an existing wasm module. Rewrites the module with this producers section
/// merged into its existing one, or adds this producers section if none is present.
pub fn add_to_wasm(&self, input: &[u8]) -> Result<Vec<u8>> {
rewrite_wasm(&None, self, &None, &None, &None, &None, None, input)
rewrite_wasm(&None, self, &None, &None, &None, &None, input)
}

pub(crate) fn display(&self, f: &mut fmt::Formatter, indent: usize) -> fmt::Result {
Expand Down
Loading
Loading