Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

68 changes: 62 additions & 6 deletions framework/meta-lib/src/cargo_toml/cargo_toml_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,78 @@ impl CargoTomlContents {
pub fn package_name(&self) -> String {
self.toml_value
.get(PACKAGE)
.expect("missing package in Cargo.toml")
.unwrap_or_else(|| {
panic!(
"missing [package] section in Cargo.toml: {}",
self.path.display()
)
})
.get("name")
.expect("missing package name in Cargo.toml")
.unwrap_or_else(|| {
panic!(
"missing package name in Cargo.toml: {}",
self.path.display()
)
})
.as_str()
.expect("package name not a string value")
.unwrap_or_else(|| {
panic!(
"package name is not a string in Cargo.toml: {}",
self.path.display()
)
})
.to_string()
}

pub fn package_version(&self) -> String {
self.toml_value
.get(PACKAGE)
.unwrap_or_else(|| {
panic!(
"missing [package] section in Cargo.toml: {}",
self.path.display()
)
})
.get("version")
.unwrap_or_else(|| {
panic!(
"missing package version in Cargo.toml: {}",
self.path.display()
)
})
.as_str()
.unwrap_or_else(|| {
panic!(
"package version is not a string in Cargo.toml: {}",
self.path.display()
)
})
.to_string()
}

pub fn package_edition(&self) -> String {
self.toml_value
.get(PACKAGE)
.expect("missing package in Cargo.toml")
.unwrap_or_else(|| {
panic!(
"missing [package] section in Cargo.toml: {}",
self.path.display()
)
})
.get("edition")
.expect("missing package name in Cargo.toml")
.unwrap_or_else(|| {
panic!(
"missing package edition in Cargo.toml: {}",
self.path.display()
)
})
.as_str()
.expect("package name not a string value")
.unwrap_or_else(|| {
panic!(
"package edition is not a string in Cargo.toml: {}",
self.path.display()
)
})
.to_string()
}

Expand Down
1 change: 1 addition & 0 deletions framework/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ common-path = "1.0.0"
bip39 = { version = "2.0", features = ["rand"] }
anyhow = "1.0"
hex = "0.4.3"
base64 = "0.22"
# warning: newer versions require Rust 1.88, hence we are not upgrading yet
zip = { version = "7.2", features = ["deflate"], default-features = false }

Expand Down
40 changes: 40 additions & 0 deletions framework/meta/src/cli/cli_args_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ pub enum StandaloneCliAction {
)]
LocalDeps(LocalDepsArgs),

#[command(
name = "source",
about = "Source code packaging and local dependency analysis."
)]
Source(SourceArgs),

#[command(
name = "wallet",
about = "Generates a new wallet or performs actions on an existing wallet."
Expand Down Expand Up @@ -360,6 +366,40 @@ pub struct UpgradeArgs {
pub no_check: bool,
}

#[derive(Clone, PartialEq, Eq, Debug, Args)]
pub struct SourceArgs {
#[command(subcommand)]
pub command: SourceCliAction,
}

#[derive(Clone, PartialEq, Eq, Debug, Subcommand)]
pub enum SourceCliAction {
#[command(
name = "local-deps",
about = "Generates a report on the local dependencies of the contract."
)]
LocalDeps(LocalDepsArgs),

#[command(
name = "pack",
about = "Packages the contract source code into a self-contained JSON file, suitable for reproducible builds."
)]
Pack(PackArgs),
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct PackArgs {
/// Project folder (workspace root or single contract folder).
/// Will be current directory if not specified.
#[arg(long, verbatim_doc_comment)]
pub path: Option<String>,

/// Only pack the contract with this name (as found in Cargo.toml).
/// If not specified, all contracts under the project folder are packed.
#[arg(long, verbatim_doc_comment)]
pub contract: Option<String>,
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct LocalDepsArgs {
/// Target directory where to generate local deps reports.
Expand Down
9 changes: 8 additions & 1 deletion framework/meta/src/cli/cli_standalone_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::{StandaloneCliAction, StandaloneCliArgs};
use crate::cli::{SourceCliAction, StandaloneCliAction, StandaloneCliArgs};
use crate::cmd::chain_simulator::chain_simulator;
use crate::cmd::retrieve_address::retrieve_address;
use crate::cmd::scen_blackbox::scen_blackbox_tool;
Expand All @@ -11,6 +11,7 @@
use crate::cmd::install::install;
use crate::cmd::local_deps::local_deps;
use crate::cmd::scen_test_gen::test_gen_tool;
use crate::cmd::source::source_pack;
use crate::cmd::template::{create_contract, print_template_names};
use crate::cmd::test::test;
use crate::cmd::test_coverage::test_coverage;
Expand Down Expand Up @@ -57,9 +58,15 @@
args.validate_args();
retrieve_address(args).await;
}
Some(StandaloneCliAction::LocalDeps(args)) => {

Check warning on line 61 in framework/meta/src/cli/cli_standalone_main.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/mx-sdk-rs/mx-sdk-rs/framework/meta/src/cli/cli_standalone_main.rs
local_deps(args);
}
Some(StandaloneCliAction::Source(source_args)) => {
match &source_args.command {
SourceCliAction::LocalDeps(args) => local_deps(args),
SourceCliAction::Pack(args) => source_pack(args),
}
}
Some(StandaloneCliAction::Wallet(args)) => {
wallet(args);
}
Expand Down
1 change: 1 addition & 0 deletions framework/meta/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod print_util;
pub mod retrieve_address;
pub mod scen_blackbox;
pub mod scen_test_gen;
pub mod source;
pub mod template;
pub mod test;
pub mod test_coverage;
Expand Down
24 changes: 21 additions & 3 deletions framework/meta/src/cmd/local_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
path::{Path, PathBuf},
};

pub const LOCAL_DEPS_FILE_NAME: &str = "local_deps.txt";

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct LocalDeps {
Expand Down Expand Up @@ -49,6 +51,22 @@
perform_local_deps(path, args.ignore.as_slice());
}

pub fn compute_local_deps(contract_dir: &Path) -> LocalDeps {
let contract_dir = contract_dir.canonicalize().unwrap();
let mut dep_map: BTreeMap<PathBuf, LocalDep> = BTreeMap::new();
expand_deps(&contract_dir, contract_dir.clone(), &mut dep_map);

let common_dependency_path = common_path_all(dep_map.keys().map(|p| p.as_path()));

LocalDeps {

Check warning on line 61 in framework/meta/src/cmd/local_deps.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/mx-sdk-rs/mx-sdk-rs/framework/meta/src/cmd/local_deps.rs
root: contract_dir.clone(),
Comment on lines +56 to +62

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute_local_deps calls expand_deps(&contract_dir, ...), but expand_deps computes child_path = pathdiff::diff_paths(&full_path, root_path).unwrap(). If any local dependency resolves outside contract_dir (common with path = "../..."), this will panic and break source pack. Either make expand_deps tolerate diff_paths == None (e.g. store absolute paths / a separate canonical path field) or allow compute_local_deps to accept a workspace root and use that as root_path.

Suggested change
let mut dep_map: BTreeMap<PathBuf, LocalDep> = BTreeMap::new();
expand_deps(&contract_dir, contract_dir.clone(), &mut dep_map);
let common_dependency_path = common_path_all(dep_map.keys().map(|p| p.as_path()));
LocalDeps {
root: contract_dir.clone(),
let root_path = contract_dir
.ancestors()
.last()
.unwrap_or(contract_dir.as_path())
.to_path_buf();
let mut dep_map: BTreeMap<PathBuf, LocalDep> = BTreeMap::new();
expand_deps(&root_path, contract_dir.clone(), &mut dep_map);
let common_dependency_path = common_path_all(dep_map.keys().map(|p| p.as_path()));
LocalDeps {
root: root_path,

Copilot uses AI. Check for mistakes.
contract_path: contract_dir,
common_dependency_path: common_dependency_path
.map(|p| p.to_string_lossy().to_string()),
dependencies: dep_map.values().cloned().collect(),
}
}

fn perform_local_deps(root_path: &Path, ignore: &[String]) {
let dirs = RelevantDirectories::find_all(root_path, ignore);
dir_pretty_print(dirs.iter_contract_crates(), "", &|_| {});
Expand All @@ -71,12 +89,12 @@
dependencies: dep_map.values().cloned().collect(),
};

let mut deps_file = File::create(output_dir_path.join("local_deps.txt")).unwrap();
let mut deps_file = File::create(output_dir_path.join(LOCAL_DEPS_FILE_NAME)).unwrap();
writeln!(deps_file, "{}", serialize_local_deps_json(&deps_contents)).unwrap();
}
}

fn expand_deps(
pub fn expand_deps(
root_path: &Path,
starting_path: PathBuf,
dep_map: &mut BTreeMap<PathBuf, LocalDep>,
Expand Down Expand Up @@ -111,7 +129,7 @@
}
}

fn serialize_local_deps_json(deps_contents: &LocalDeps) -> String {
pub fn serialize_local_deps_json(deps_contents: &LocalDeps) -> String {
let buf = Vec::new();
let formatter = serde_json::ser::PrettyFormatter::with_indent(b" ");
let mut ser = serde_json::Serializer::with_formatter(buf, formatter);
Expand Down
Loading
Loading