Skip to content

Commit

Permalink
Merge pull request #13 from sapporo-wes/enhancement/11
Browse files Browse the repository at this point in the history
Add support for M1 Mac
  • Loading branch information
fmaccha authored Aug 25, 2024
2 parents c8832c1 + 7e797b5 commit 5ac1d83
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 64 deletions.
99 changes: 53 additions & 46 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde_yaml = "0.9.27"
serde_json = "1.0.109"
url = "2.5.0"
reqwest = { version = "0.12.5", features = ["blocking"] }
tempfile = "3.9.0"
tempfile = "3.12.0"
csv = "1.3.0"
log = "0.4.20"
env_logger = "0.11.0"
Expand Down
30 changes: 21 additions & 9 deletions src/ext_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use anyhow::{anyhow, bail, Context, Result};
use log::{debug, info};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use tempfile::{Builder, NamedTempFile, TempDir};

Expand All @@ -17,16 +19,11 @@ pub fn invoke(
cwl_file_path: &Path,
target_file_path: &Path,
cwl_input_file_path: &NamedTempFile,
dummy_docker_path: &NamedTempFile,
_options: &InvokeOptions,
) -> Result<ModuleResult> {
info!("Invoking ext_tools {}", cwl_file_path.display());

let docker_path = docker_path()?;
debug!(
"The path of the docker command in your environment: {:?}.",
docker_path
);

// make sure that the both paths are canonicalized.
let target_file_path = target_file_path.canonicalize().with_context(|| {
format!(
Expand All @@ -50,7 +47,7 @@ pub fn invoke(
"--rm",
"-i",
"-v",
&format!("{}:/usr/bin/docker:ro", docker_path.to_str().unwrap()),
&format!("{}:/usr/bin/docker:ro", dummy_docker_path.path().display()),
"-v",
&format!(
"{}:/workdir/input_file.yaml:ro",
Expand Down Expand Up @@ -141,7 +138,8 @@ pub fn invoke(
Ok(module_result)
}

fn docker_path() -> Result<PathBuf> {
// check whether `which docker` succeeds or not to see the docker binary is in the PATH.
pub fn ensure_docker_presence() -> Result<PathBuf> {
let process = std::process::Command::new("which")
.arg("docker")
.stdout(std::process::Stdio::piped())
Expand All @@ -152,10 +150,24 @@ fn docker_path() -> Result<PathBuf> {
let path = String::from_utf8(process.stdout)?;
Ok(PathBuf::from(path.trim()))
} else {
bail!("Please make sure that the docker command is present in your PATH");
bail!("Please make sure that the docker command is present in your PATH when invoking CWL modules.");
}
}

// create a dummy Docker executable
// - create a empty file in the temporary directory.
// - grant execution permission to the file.
// - return the file as NamedTempFile.
pub fn create_dummy_docker_executable(temp_dir: &TempDir) -> Result<NamedTempFile> {
let read_execution_permission = std::fs::Permissions::from_mode(0o500);
let dummy_docker_file = Builder::new()
.prefix("dummy_docker_")
.permissions(read_execution_permission)
.tempfile_in(temp_dir)?;

Ok(dummy_docker_file)
}

#[derive(Deserialize, Debug)]
struct CwlFields {
#[serde(flatten)]
Expand Down
24 changes: 22 additions & 2 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tempfile::{NamedTempFile, TempDir};
use url::Url;

use crate::args::{Args, OutputFormat};
use crate::ext_tools::{create_dummy_docker_executable, ensure_docker_presence};
use crate::source::{CompressedFormat, Source};

// Struct to store the result of Parser invocation and ExtTools invocation.
Expand Down Expand Up @@ -455,6 +456,13 @@ fn run_modules(
None
};

// create a dummy Docker executable just for cwl-inspecter to work properly in Docker container only if there are one or more CWL module in the config file
let dummy_docker_path = if cwl_module_exists(config)? {
Some(create_dummy_docker_executable(temp_dir)?)
} else {
None
};

let module_result = config
.order
.iter()
Expand All @@ -474,6 +482,7 @@ fn run_modules(
module_path,
target_file_path,
cwl_input_file_path.as_ref().unwrap(),
dummy_docker_path.as_ref().unwrap(),
invoke_options,)
},
_ => Err(anyhow!(
Expand Down Expand Up @@ -552,8 +561,19 @@ fn check_run_condition_cwl_module(
- tidy needed
*/

if cwl_module_exists && stdin_exists && !invoke_options.tidy {
bail!("The `--tidy` option is required when reading from STDIN and invoking CWL modules.");
if cwl_module_exists {
if stdin_exists && !invoke_options.tidy {
bail!(
"The `--tidy` option is required when reading from STDIN and invoking CWL modules."
);
}

// check for existence of docker binary if a CWL module is specified
let docker_path = ensure_docker_presence()?;
debug!(
"The path of the docker command in your environment: {:?}.",
docker_path
);
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn check_and_create_cache_dir() -> io::Result<()> {
}

// whether the current environment is M1 Mac
#[allow(dead_code)]
pub fn is_running_on_m1_mac() -> bool {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
Expand Down
6 changes: 0 additions & 6 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ fn can_be_verbose() {
#[test]
// 9. -c cwl.conf
fn can_run_cwl() {
// TEMPORARY: skip this test on M1 Mac due (issue #9)
// This will be removed when tataki supports M1 Mac.
if is_running_on_m1_mac() {
return;
}

check_and_create_cache_dir().expect("Failed to create the cache directory");

let out = tataki(
Expand Down

0 comments on commit 5ac1d83

Please sign in to comment.