Skip to content

Commit

Permalink
Emit metadata using data structures defined in scarb-metadata crate
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaput committed Mar 15, 2023
1 parent 3ba669c commit 6a21fb1
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 373 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ license.workspace = true
readme.workspace = true
repository.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
Expand Down Expand Up @@ -44,6 +42,7 @@ itertools.workspace = true
once_cell.workspace = true
pathdiff.workspace = true
petgraph.workspace = true
scarb-metadata = { path = "../scarb-metadata" }
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions scarb/src/bin/scarb/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use std::collections::BTreeMap;
use std::ffi::OsString;

use anyhow::{anyhow, Result};
use camino::Utf8PathBuf;
use clap::{CommandFactory, Parser, Subcommand};
use tracing::level_filters::LevelFilter;
use tracing_log::AsTrace;

use anyhow::{anyhow, Result};
use scarb::core::{Package, PackageName, Workspace};
use scarb::manifest_editor::DepId;
use scarb::metadata::MetadataVersion;
use scarb::ui;
use scarb::ui::OutputFormat;
use scarb::version;
Expand Down Expand Up @@ -156,7 +155,7 @@ pub struct InitArgs {
pub struct MetadataArgs {
// Format version.
#[arg(long, value_name = "VERSION")]
pub format_version: MetadataVersion,
pub format_version: u64,
/// Output information only about the workspace members and don't fetch dependencies.
#[arg(long)]
pub no_deps: bool,
Expand Down
5 changes: 2 additions & 3 deletions scarb/src/bin/scarb/commands/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;

use scarb::core::Config;
use scarb::metadata::{Metadata, MetadataOptions};
use scarb::ops;
use scarb::ui::MachineMessage;

Expand All @@ -11,12 +10,12 @@ use crate::args::MetadataArgs;
pub fn run(args: MetadataArgs, config: &Config) -> Result<()> {
let ws = ops::read_workspace(config.manifest_path(), config)?;

let opts = MetadataOptions {
let opts = ops::MetadataOptions {
version: args.format_version,
no_deps: args.no_deps,
};

let metadata = Metadata::collect(&ws, &opts)?;
let metadata = ops::collect_metadata(&opts, &ws)?;

config.ui().print(MachineMessage(metadata));

Expand Down
16 changes: 10 additions & 6 deletions scarb/src/core/package/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ impl PackageId {

Ok(PackageId::new(name, version, source_id))
}

pub fn to_serialized_string(&self) -> String {
format!(
"{} {} ({})",
self.name,
self.version,
self.source_id.to_pretty_url(),
)
}
}

impl Deref for PackageId {
Expand All @@ -80,12 +89,7 @@ impl Deref for PackageId {

impl Serialize for PackageId {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.collect_str(&format_args!(
"{} {} ({})",
self.name,
self.version,
self.source_id.to_pretty_url(),
))
s.collect_str(&self.to_serialized_string())
}
}

Expand Down
1 change: 0 additions & 1 deletion scarb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod core;
pub mod flock;
mod internal;
pub mod manifest_editor;
pub mod metadata;
pub mod ops;
pub mod process;
mod resolver;
Expand Down
104 changes: 0 additions & 104 deletions scarb/src/metadata/metadata_version.rs

This file was deleted.

Loading

0 comments on commit 6a21fb1

Please sign in to comment.