mirror of
https://github.com/sagiegurari/cargo-make
synced 2026-06-08 17:20:03 +00:00
More fixes for external dependencies #497
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[tasks.cross-file]
|
||||
dependencies = [
|
||||
# specific file name
|
||||
{ name = "format", path = "simple-example.toml" },
|
||||
{ name = "private", path = "private.toml" },
|
||||
# in a folder
|
||||
{ name = "echo", path = "workspace2" },
|
||||
]
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::types::{
|
||||
Config, CrateInfo, EnvValue, ExecutionPlan, ScriptValue, Step, Task, TaskIdentifier, Workspace,
|
||||
};
|
||||
use envmnt;
|
||||
use fsio::path::{get_basename, get_parent_directory};
|
||||
use glob::Pattern;
|
||||
use indexmap::IndexMap;
|
||||
use std::collections::HashSet;
|
||||
@@ -335,13 +336,26 @@ fn create_for_step(
|
||||
// so we create a proxy task to invoke it
|
||||
let proxy_name = format!("{}_proxy", task.name);
|
||||
|
||||
let mut proxy_task = create_proxy_task(&proxy_name, true, false);
|
||||
proxy_task.cwd = Some(path.to_owned());
|
||||
let path_obj = Path::new(path);
|
||||
let (working_directory, makefile) = if path_obj.is_file() {
|
||||
let filename = get_basename(&path_obj);
|
||||
let working_directory = get_parent_directory(&path_obj);
|
||||
(working_directory, filename)
|
||||
} else {
|
||||
(Some(path.to_string()), Some("Makefile.toml".to_string()))
|
||||
};
|
||||
|
||||
steps.push(Step {
|
||||
name: task.to_string(),
|
||||
let mut proxy_task = create_proxy_task(&task.name, true, false, makefile);
|
||||
proxy_task.cwd = working_directory;
|
||||
|
||||
let step = Step {
|
||||
name: proxy_name,
|
||||
config: proxy_task,
|
||||
});
|
||||
};
|
||||
|
||||
debug!("Created external depedency step: {:#?}", &step);
|
||||
|
||||
steps.push(step);
|
||||
task_names.insert(task.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -897,7 +897,7 @@ fn create_with_dependencies() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_with_foreign_dependencies() {
|
||||
fn create_with_foreign_dependencies_directory() {
|
||||
let mut config_section = ConfigSection::new();
|
||||
config_section.init_task = Some("init".to_string());
|
||||
config_section.end_task = Some("end".to_string());
|
||||
@@ -915,7 +915,7 @@ fn create_with_foreign_dependencies() {
|
||||
let mut task = Task::new();
|
||||
task.dependencies = Some(vec![DependencyIdentifier::Definition(TaskIdentifier {
|
||||
name: "task_dependency".to_string(),
|
||||
path: Some("other_file.toml".to_string()),
|
||||
path: Some("./examples/workspace".to_string()),
|
||||
})]);
|
||||
|
||||
let task_dependency = Task::new();
|
||||
@@ -926,18 +926,100 @@ fn create_with_foreign_dependencies() {
|
||||
.insert("task_dependency".to_string(), task_dependency);
|
||||
|
||||
let execution_plan = create(&config, "test", false, true, false);
|
||||
|
||||
assert_eq!(execution_plan.steps.len(), 4);
|
||||
assert_eq!(execution_plan.steps[0].name, "init");
|
||||
assert_eq!(
|
||||
execution_plan.steps[1].name,
|
||||
"other_file.toml:task_dependency"
|
||||
);
|
||||
assert_eq!(
|
||||
execution_plan.steps[1].config.cwd,
|
||||
Some("other_file.toml".to_string())
|
||||
);
|
||||
assert_eq!(execution_plan.steps[1].name, "task_dependency_proxy");
|
||||
assert_eq!(execution_plan.steps[2].name, "test");
|
||||
assert_eq!(execution_plan.steps[3].name, "end");
|
||||
|
||||
let task_config = execution_plan.steps[1].config.clone();
|
||||
assert_eq!(task_config.cwd, Some("./examples/workspace".to_string()));
|
||||
assert_eq!(task_config.args.unwrap()[7], "Makefile.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_with_foreign_dependencies_filename() {
|
||||
let mut config_section = ConfigSection::new();
|
||||
config_section.init_task = Some("init".to_string());
|
||||
config_section.end_task = Some("end".to_string());
|
||||
let mut config = Config {
|
||||
config: config_section,
|
||||
env_files: vec![],
|
||||
env: IndexMap::new(),
|
||||
env_scripts: vec![],
|
||||
tasks: IndexMap::new(),
|
||||
};
|
||||
|
||||
config.tasks.insert("init".to_string(), Task::new());
|
||||
config.tasks.insert("end".to_string(), Task::new());
|
||||
|
||||
let mut task = Task::new();
|
||||
task.dependencies = Some(vec![DependencyIdentifier::Definition(TaskIdentifier {
|
||||
name: "task_dependency".to_string(),
|
||||
path: Some("Cargo.toml".to_string()),
|
||||
})]);
|
||||
|
||||
let task_dependency = Task::new();
|
||||
|
||||
config.tasks.insert("test".to_string(), task);
|
||||
config
|
||||
.tasks
|
||||
.insert("task_dependency".to_string(), task_dependency);
|
||||
|
||||
let execution_plan = create(&config, "test", false, true, false);
|
||||
|
||||
assert_eq!(execution_plan.steps.len(), 4);
|
||||
assert_eq!(execution_plan.steps[0].name, "init");
|
||||
assert_eq!(execution_plan.steps[1].name, "task_dependency_proxy");
|
||||
assert_eq!(execution_plan.steps[2].name, "test");
|
||||
assert_eq!(execution_plan.steps[3].name, "end");
|
||||
|
||||
let task_config = execution_plan.steps[1].config.clone();
|
||||
assert_eq!(task_config.cwd, None);
|
||||
assert_eq!(task_config.args.unwrap()[7], "Cargo.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_with_foreign_dependencies_file_and_directory() {
|
||||
let mut config_section = ConfigSection::new();
|
||||
config_section.init_task = Some("init".to_string());
|
||||
config_section.end_task = Some("end".to_string());
|
||||
let mut config = Config {
|
||||
config: config_section,
|
||||
env_files: vec![],
|
||||
env: IndexMap::new(),
|
||||
env_scripts: vec![],
|
||||
tasks: IndexMap::new(),
|
||||
};
|
||||
|
||||
config.tasks.insert("init".to_string(), Task::new());
|
||||
config.tasks.insert("end".to_string(), Task::new());
|
||||
|
||||
let mut task = Task::new();
|
||||
task.dependencies = Some(vec![DependencyIdentifier::Definition(TaskIdentifier {
|
||||
name: "task_dependency".to_string(),
|
||||
path: Some("./examples/cross-file.toml".to_string()),
|
||||
})]);
|
||||
|
||||
let task_dependency = Task::new();
|
||||
|
||||
config.tasks.insert("test".to_string(), task);
|
||||
config
|
||||
.tasks
|
||||
.insert("task_dependency".to_string(), task_dependency);
|
||||
|
||||
let execution_plan = create(&config, "test", false, true, false);
|
||||
|
||||
assert_eq!(execution_plan.steps.len(), 4);
|
||||
assert_eq!(execution_plan.steps[0].name, "init");
|
||||
assert_eq!(execution_plan.steps[1].name, "task_dependency_proxy");
|
||||
assert_eq!(execution_plan.steps[2].name, "test");
|
||||
assert_eq!(execution_plan.steps[3].name, "end");
|
||||
|
||||
let task_config = execution_plan.steps[1].config.clone();
|
||||
assert_eq!(task_config.cwd, Some("./examples".to_string()));
|
||||
assert_eq!(task_config.args.unwrap()[7], "cross-file.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+12
-7
@@ -10,6 +10,7 @@ pub(crate) fn create_proxy_task(
|
||||
task: &str,
|
||||
allow_private: bool,
|
||||
skip_init_end_tasks: bool,
|
||||
makefile: Option<String>,
|
||||
) -> Task {
|
||||
//get log level name
|
||||
let log_level = logger::get_log_level();
|
||||
@@ -41,14 +42,18 @@ pub(crate) fn create_proxy_task(
|
||||
}
|
||||
|
||||
//get makefile location
|
||||
match env::var("CARGO_MAKE_MAKEFILE_PATH") {
|
||||
Ok(makefile_path) => {
|
||||
if makefile_path.len() > 0 {
|
||||
args.push("--makefile".to_string());
|
||||
args.push(makefile_path);
|
||||
}
|
||||
let makefile_path_option = match makefile {
|
||||
Some(makefile_path) => Some(makefile_path),
|
||||
None => match env::var("CARGO_MAKE_MAKEFILE_PATH") {
|
||||
Ok(makefile_path) => Some(makefile_path),
|
||||
_ => None,
|
||||
},
|
||||
};
|
||||
if let Some(makefile_path) = makefile_path_option {
|
||||
if makefile_path.len() > 0 {
|
||||
args.push("--makefile".to_string());
|
||||
args.push(makefile_path);
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
args.push(task.to_string());
|
||||
|
||||
+52
-23
@@ -7,7 +7,7 @@ use super::*;
|
||||
fn create_proxy_task_no_makefile() {
|
||||
let makefile = envmnt::get_or("CARGO_MAKE_MAKEFILE_PATH", "EMPTY");
|
||||
envmnt::remove("CARGO_MAKE_MAKEFILE_PATH");
|
||||
let task = create_proxy_task("some_task", false, false);
|
||||
let task = create_proxy_task("some_task", false, false, None);
|
||||
envmnt::set("CARGO_MAKE_MAKEFILE_PATH", &makefile);
|
||||
|
||||
assert_eq!(task.command.unwrap(), "cargo".to_string());
|
||||
@@ -21,12 +21,12 @@ fn create_proxy_task_no_makefile() {
|
||||
|
||||
let args = task.args.unwrap();
|
||||
assert_eq!(args.len(), 6);
|
||||
assert_eq!(args[0], "make".to_string());
|
||||
assert_eq!(args[1], "--disable-check-for-updates".to_string());
|
||||
assert_eq!(args[2], "--no-on-error".to_string());
|
||||
assert_eq!(args[3], log_level_arg.to_string());
|
||||
assert_eq!(args[4], profile_arg.to_string());
|
||||
assert_eq!(args[5], "some_task".to_string());
|
||||
assert_eq!(args[0], "make");
|
||||
assert_eq!(args[1], "--disable-check-for-updates");
|
||||
assert_eq!(args[2], "--no-on-error");
|
||||
assert_eq!(args[3], log_level_arg);
|
||||
assert_eq!(args[4], profile_arg);
|
||||
assert_eq!(args[5], "some_task");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -35,7 +35,7 @@ fn create_proxy_task_no_makefile() {
|
||||
fn create_proxy_task_with_makefile() {
|
||||
let makefile = envmnt::get_or("CARGO_MAKE_MAKEFILE_PATH", "EMPTY");
|
||||
envmnt::set("CARGO_MAKE_MAKEFILE_PATH", &makefile);
|
||||
let task = create_proxy_task("some_task", false, false);
|
||||
let task = create_proxy_task("some_task", false, false, None);
|
||||
|
||||
assert_eq!(task.command.unwrap(), "cargo".to_string());
|
||||
|
||||
@@ -48,14 +48,43 @@ fn create_proxy_task_with_makefile() {
|
||||
|
||||
let args = task.args.unwrap();
|
||||
assert_eq!(args.len(), 8);
|
||||
assert_eq!(args[0], "make".to_string());
|
||||
assert_eq!(args[1], "--disable-check-for-updates".to_string());
|
||||
assert_eq!(args[2], "--no-on-error".to_string());
|
||||
assert_eq!(args[3], log_level_arg.to_string());
|
||||
assert_eq!(args[4], profile_arg.to_string());
|
||||
assert_eq!(args[5], "--makefile".to_string());
|
||||
assert_eq!(args[0], "make");
|
||||
assert_eq!(args[1], "--disable-check-for-updates");
|
||||
assert_eq!(args[2], "--no-on-error");
|
||||
assert_eq!(args[3], log_level_arg);
|
||||
assert_eq!(args[4], profile_arg);
|
||||
assert_eq!(args[5], "--makefile");
|
||||
assert_eq!(args[6], makefile);
|
||||
assert_eq!(args[7], "some_task".to_string());
|
||||
assert_eq!(args[7], "some_task");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn create_proxy_task_with_makefile_argument() {
|
||||
let makefile = envmnt::get_or("CARGO_MAKE_MAKEFILE_PATH", "EMPTY");
|
||||
envmnt::set("CARGO_MAKE_MAKEFILE_PATH", &makefile);
|
||||
let task = create_proxy_task("some_task", false, false, Some("external.toml".to_string()));
|
||||
|
||||
assert_eq!(task.command.unwrap(), "cargo".to_string());
|
||||
|
||||
let log_level = logger::get_log_level();
|
||||
let mut log_level_arg = "--loglevel=".to_string();
|
||||
log_level_arg.push_str(&log_level);
|
||||
|
||||
let mut profile_arg = "--profile=".to_string();
|
||||
profile_arg.push_str(&profile::get());
|
||||
|
||||
let args = task.args.unwrap();
|
||||
assert_eq!(args.len(), 8);
|
||||
assert_eq!(args[0], "make");
|
||||
assert_eq!(args[1], "--disable-check-for-updates");
|
||||
assert_eq!(args[2], "--no-on-error");
|
||||
assert_eq!(args[3], log_level_arg);
|
||||
assert_eq!(args[4], profile_arg);
|
||||
assert_eq!(args[5], "--makefile");
|
||||
assert_eq!(args[6], "external.toml");
|
||||
assert_eq!(args[7], "some_task");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -64,7 +93,7 @@ fn create_proxy_task_with_makefile() {
|
||||
fn create_proxy_task_allow_private() {
|
||||
let makefile = envmnt::get_or("CARGO_MAKE_MAKEFILE_PATH", "EMPTY");
|
||||
envmnt::remove("CARGO_MAKE_MAKEFILE_PATH");
|
||||
let task = create_proxy_task("some_task", true, false);
|
||||
let task = create_proxy_task("some_task", true, false, None);
|
||||
envmnt::set("CARGO_MAKE_MAKEFILE_PATH", &makefile);
|
||||
|
||||
assert_eq!(task.command.unwrap(), "cargo".to_string());
|
||||
@@ -78,11 +107,11 @@ fn create_proxy_task_allow_private() {
|
||||
|
||||
let args = task.args.unwrap();
|
||||
assert_eq!(args.len(), 7);
|
||||
assert_eq!(args[0], "make".to_string());
|
||||
assert_eq!(args[1], "--disable-check-for-updates".to_string());
|
||||
assert_eq!(args[2], "--no-on-error".to_string());
|
||||
assert_eq!(args[3], log_level_arg.to_string());
|
||||
assert_eq!(args[4], profile_arg.to_string());
|
||||
assert_eq!(args[5], "--allow-private".to_string());
|
||||
assert_eq!(args[6], "some_task".to_string());
|
||||
assert_eq!(args[0], "make");
|
||||
assert_eq!(args[1], "--disable-check-for-updates");
|
||||
assert_eq!(args[2], "--no-on-error");
|
||||
assert_eq!(args[3], log_level_arg);
|
||||
assert_eq!(args[4], profile_arg);
|
||||
assert_eq!(args[5], "--allow-private");
|
||||
assert_eq!(args[6], "some_task");
|
||||
}
|
||||
|
||||
+3
-2
@@ -109,7 +109,7 @@ pub(crate) fn get_sub_task_info_for_routing_info(
|
||||
}
|
||||
|
||||
fn create_fork_step(flow_info: &FlowInfo) -> Step {
|
||||
let fork_task = create_proxy_task(&flow_info.task, true, true);
|
||||
let fork_task = create_proxy_task(&flow_info.task, true, true, None);
|
||||
|
||||
Step {
|
||||
name: "cargo_make_run_fork".to_string(),
|
||||
@@ -417,7 +417,7 @@ fn run_task_flow(flow_info: &FlowInfo, flow_state: &mut FlowState, execution_pla
|
||||
}
|
||||
|
||||
fn create_watch_task(task: &str, options: Option<TaskWatchOptions>) -> Task {
|
||||
let mut task_config = create_proxy_task(&task, true, true);
|
||||
let mut task_config = create_proxy_task(&task, true, true, None);
|
||||
|
||||
let mut env_map = task_config.env.unwrap_or(IndexMap::new());
|
||||
env_map.insert(
|
||||
@@ -516,6 +516,7 @@ fn run_protected_flow(flow_info: &FlowInfo, flow_state: &mut FlowState) {
|
||||
&flow_info.task,
|
||||
flow_info.allow_private,
|
||||
flow_info.skip_init_end_tasks,
|
||||
None,
|
||||
);
|
||||
|
||||
let exit_code = command::run_command(&proxy_task.command.unwrap(), &proxy_task.args, false);
|
||||
|
||||
Reference in New Issue
Block a user