Skip to content

Commit

Permalink
Add edition field to PackageMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr committed Nov 6, 2023
1 parent 28d74ca commit c5a7ad7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions scarb-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ pub struct PackageMetadata {
/// Package version as given in `Scarb.toml`.
pub version: Version,

/// Package edition as given in `Scarb.toml`.
#[serde(skip_serializing_if = "Option::is_none")]
pub edition: Option<String>,

/// The source of the package.
pub source: SourceId,

Expand Down
2 changes: 1 addition & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ serde-untagged.workspace = true
serde-value.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
serde_repr.workspace = true
sha2.workspace = true
smallvec.workspace = true
smol_str.workspace = true
tar.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions scarb/src/ops/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ fn collect_package_metadata(package: &Package) -> m::PackageMetadata {
.build()
.unwrap();

let edition = serde_json::to_value(package.manifest.edition).unwrap();

m::PackageMetadataBuilder::default()
.id(wrap_package_id(package.id))
.name(package.id.name.clone())
.version(package.id.version.clone())
.edition(Some(edition.to_string()))
.source(wrap_source_id(package.id.source_id))
.manifest_path(package.manifest_path())
.root(package.root())
Expand Down
26 changes: 26 additions & 0 deletions scarb/tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,3 +1112,29 @@ fn infer_readme_workspace() {
assert_eq!(packages.get("t5").unwrap().manifest_metadata.readme, None);
assert_eq!(packages.get("t6").unwrap().manifest_metadata.readme, None);
}

#[test]
fn includes_edition() {
let t = assert_fs::TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.version("0.1.0")
.edition("2023_10")
.build(&t);

let metadata = Scarb::quick_snapbox()
.arg("--json")
.arg("metadata")
.arg("--format-version")
.arg("1")
.current_dir(&t)
.stdout_json::<Metadata>();

for package in metadata.packages {
if package.name == "hello" {
assert_eq!(package.edition, Some("2023_10".to_string()));
return;
}
}
panic!("Package not found in metadata!");
}

0 comments on commit c5a7ad7

Please sign in to comment.