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 daa9df7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ serde-value = "0.7"
serde_json = "1"
serde_repr = "0.1"
serde_test = "1"
serde_variant = "0.1"
sha2 = "0.10"
similar-asserts = { version = "1", features = ["serde"] }
smallvec = "1"
Expand Down
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
3 changes: 2 additions & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ serde-untagged.workspace = true
serde-value.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
serde_repr.workspace = true
serde_variant.workspace = true
sha2.workspace = true
smallvec.workspace = true
smol_str.workspace = true
tar.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions scarb/src/ops/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::{BTreeMap, HashMap};
use anyhow::{bail, Result};
use itertools::Itertools;
use semver::{Version, VersionReq};
use serde_variant::to_variant_name;
use smol_str::SmolStr;

use scarb_metadata as m;
Expand Down Expand Up @@ -125,10 +126,13 @@ fn collect_package_metadata(package: &Package) -> m::PackageMetadata {
.build()
.unwrap();

let edition = to_variant_name(&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 daa9df7

Please sign in to comment.