Skip to content

Commit

Permalink
feat(cli): Pull in cargo-script-mvs core logic
Browse files Browse the repository at this point in the history
This is no where near the implementation we want but I think we should
develop incrementally on top of what we already have.

See https://github.com/epage/cargo-script-mvs/tree/main
  • Loading branch information
epage committed Jun 10, 2023
1 parent c421e0b commit 33c9d8e
Show file tree
Hide file tree
Showing 7 changed files with 1,322 additions and 34 deletions.
65 changes: 58 additions & 7 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exclude = [
[workspace.dependencies]
anyhow = "1.0.47"
base64 = "0.21.0"
blake3 = "1.3.3"
bytesize = "1.0"
cargo = { path = "" }
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
Expand Down Expand Up @@ -66,6 +67,7 @@ pretty_env_logger = "0.4"
proptest = "1.1.0"
pulldown-cmark = { version = "0.9.2", default-features = false }
rand = "0.8.5"
regex = "1.8.3"
rustfix = "0.6.0"
same-file = "1.0.6"
security-framework = "2.0.0"
Expand All @@ -79,6 +81,7 @@ sha2 = "0.10.6"
shell-escape = "0.1.4"
snapbox = { version = "0.4.0", features = ["diff", "path"] }
strip-ansi-escapes = "0.1.0"
syn = { version = "2.0.14", features = ["extra-traits", "full"] }
tar = { version = "0.4.38", default-features = false }
tempfile = "3.1.0"
termcolor = "1.1.2"
Expand Down Expand Up @@ -112,6 +115,7 @@ path = "src/cargo/lib.rs"
[dependencies]
anyhow.workspace = true
base64.workspace = true
blake3.workspace = true
bytesize.workspace = true
cargo-platform.workspace = true
cargo-util.workspace = true
Expand Down Expand Up @@ -147,7 +151,9 @@ os_info.workspace = true
pasetors.workspace = true
pathdiff.workspace = true
pretty_env_logger = { workspace = true, optional = true }
pulldown-cmark.workspace = true
rand.workspace = true
regex.workspace = true
rustfix.workspace = true
semver.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand All @@ -157,6 +163,7 @@ serde_json = { workspace = true, features = ["raw_value"] }
sha1.workspace = true
shell-escape.workspace = true
strip-ansi-escapes.workspace = true
syn.workspace = true
tar.workspace = true
tempfile.workspace = true
termcolor.workspace = true
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ allow = [
"MIT-0",
"Apache-2.0",
"BSD-3-Clause",
"BSD-2-Clause",
"MPL-2.0",
"Unicode-DFS-2016",
"CC0-1.0",
Expand Down
18 changes: 16 additions & 2 deletions src/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,26 @@ pub fn is_manifest_command(arg: &str) -> bool {
1 < path.components().count() || path.extension() == Some(OsStr::new("rs"))
}

pub fn exec_manifest_command(config: &Config, cmd: &str, _args: &[OsString]) -> CliResult {
pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> CliResult {
if !config.cli_unstable().script {
return Err(anyhow::anyhow!("running `{cmd}` requires `-Zscript`").into());
}

todo!("support for running manifest-commands is not yet implemented")
let manifest_path = Path::new(cmd);
if !manifest_path.exists() {
return Err(
anyhow::anyhow!("manifest `{}` does not exist", manifest_path.display()).into(),
);
}
let manifest_path = crate::util::try_canonicalize(manifest_path)?;
let script = cargo::util::toml::embedded::RawScript::parse_from(&manifest_path)?;
let ws = script.to_workspace(config)?;

let mut compile_opts =
cargo::ops::CompileOptions::new(config, cargo::core::compiler::CompileMode::Build)?;
compile_opts.spec = cargo::ops::Packages::Default;

cargo::ops::run(&ws, &compile_opts, args).map_err(|err| to_run_error(config, err))
}

fn to_run_error(config: &cargo::util::Config, err: anyhow::Error) -> CliError {
Expand Down
Loading

0 comments on commit 33c9d8e

Please sign in to comment.