Skip to content

Commit cf53ef5

Browse files
committed
remove shell handling for unix/windows, use shellwords instead and dont invoke a shell
1 parent a5eb1a1 commit cf53ef5

6 files changed

Lines changed: 39 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pocket-ic = "9.0.0"
2323
serde = { version = "1.0", features = ["derive"] }
2424
serde_json = "1.0"
2525
serde_yaml = "0.9.34"
26+
shellwords = "1.1.0"
2627
snafu = "0.8.5"
2728
tempfile = "3"
2829
time = "0.3.9"

lib/icp-adapter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ edition = "2024"
77
async-trait = { workspace = true }
88
camino = { workspace = true }
99
serde = { workspace = true }
10+
shellwords = { workspace = true }
1011
snafu = { workspace = true }

lib/icp-adapter/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use snafu::Snafu;
88
pub mod motoko;
99
pub mod rust;
1010
pub mod script;
11-
pub mod shell;
1211

1312
#[async_trait]
1413
pub trait Adapter {

lib/icp-adapter/src/script.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::process::{Command, Stdio};
2-
3-
use crate::{Adapter, AdapterCompileError, shell::SHELL};
1+
use crate::{Adapter, AdapterCompileError};
42
use async_trait::async_trait;
53
use camino::Utf8PathBuf;
64
use serde::Deserialize;
7-
use snafu::{ResultExt, Snafu};
5+
use snafu::{OptionExt, ResultExt, Snafu};
6+
use std::process::{Command, Stdio};
87

98
/// Configuration for a custom canister build adapter.
109
#[derive(Debug, Deserialize)]
@@ -16,11 +15,22 @@ pub struct ScriptAdapter {
1615
#[async_trait]
1716
impl Adapter for ScriptAdapter {
1817
async fn compile(&self, path: Utf8PathBuf) -> Result<(), AdapterCompileError> {
18+
// Parse command input
19+
let input = shellwords::split(&self.command).context(CommandParseSnafu {
20+
command: &self.command,
21+
})?;
22+
23+
// Separate command and args
24+
let (cmd, args) = input.split_first().context(InvalidCommandSnafu {
25+
command: &self.command,
26+
reason: "command must include at least one element".to_string(),
27+
})?;
28+
1929
// Command
20-
let mut cmd = Command::new(SHELL.binary());
30+
let mut cmd = Command::new(cmd);
2131

22-
// Script
23-
cmd.arg(SHELL.exec_flag()).arg(&self.command);
32+
// Args
33+
cmd.args(args);
2434

2535
// Set directory
2636
cmd.current_dir(&path);
@@ -53,6 +63,15 @@ impl Adapter for ScriptAdapter {
5363

5464
#[derive(Debug, Snafu)]
5565
pub enum ScriptAdapterCompileError {
66+
#[snafu(display("failed to parse command {command}: {source}"))]
67+
CommandParse {
68+
command: String,
69+
source: shellwords::MismatchedQuotes,
70+
},
71+
72+
#[snafu(display("invalid command {command}: {reason}"))]
73+
InvalidCommand { command: String, reason: String },
74+
5675
#[snafu(display("failed to execute command {command}: {source}"))]
5776
CommandInvoke {
5877
command: String,

lib/icp-adapter/src/shell.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)