From c5a7ad7bf453a5c4660bfe94234a6a7047d7e979 Mon Sep 17 00:00:00 2001 From: maciektr Date: Sun, 5 Nov 2023 12:57:34 +0100 Subject: [PATCH] Add edition field to PackageMetadata --- scarb-metadata/src/lib.rs | 4 ++++ scarb/Cargo.toml | 2 +- scarb/src/ops/metadata.rs | 3 +++ scarb/tests/metadata.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scarb-metadata/src/lib.rs b/scarb-metadata/src/lib.rs index 55cee2130..2c5fe4dbc 100644 --- a/scarb-metadata/src/lib.rs +++ b/scarb-metadata/src/lib.rs @@ -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, + /// The source of the package. pub source: SourceId, diff --git a/scarb/Cargo.toml b/scarb/Cargo.toml index a71a4efc7..544d5c599 100644 --- a/scarb/Cargo.toml +++ b/scarb/Cargo.toml @@ -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 diff --git a/scarb/src/ops/metadata.rs b/scarb/src/ops/metadata.rs index 68058433b..b338e410b 100644 --- a/scarb/src/ops/metadata.rs +++ b/scarb/src/ops/metadata.rs @@ -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()) diff --git a/scarb/tests/metadata.rs b/scarb/tests/metadata.rs index 72a4c9637..319d48517 100644 --- a/scarb/tests/metadata.rs +++ b/scarb/tests/metadata.rs @@ -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::(); + + 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!"); +}