这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(turborepo): pass through arguments only for root tasks #8089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
16 changes: 0 additions & 16 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
cli::{
Command, DryRunMode, EnvMode, ExecutionArgs, LogOrder, LogPrefix, OutputLogsMode, RunArgs,
},
run::task_id::TaskId,
Args,
};

Expand Down Expand Up @@ -157,21 +156,6 @@ pub struct RunOpts {
pub is_github_actions: bool,
}

impl RunOpts {
pub fn args_for_task(&self, task_id: &TaskId) -> Option<Vec<String>> {
if !self.pass_through_args.is_empty()
&& self
.tasks
.iter()
.any(|task| task.as_str() == task_id.task())
{
Some(self.pass_through_args.clone())
} else {
None
}
}
}

#[derive(Debug)]
pub enum GraphOpts {
Stdout,
Expand Down
7 changes: 6 additions & 1 deletion crates/turborepo-lib/src/run/summary/task_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ impl<'a> TaskSummaryFactory<'a> {
.env_vars(task_id)
.expect("env var map is inserted at the same time as hash");

let cli_arguments = self
.hash_tracker
.cli_args(task_id)
.expect("cli args is inserted at the same time as hash");

let cache_summary = self.hash_tracker.cache_status(task_id).into();

let (dependencies, dependents) = self.dependencies_and_dependents(task_id, display_task);
Expand All @@ -159,7 +164,7 @@ impl<'a> TaskSummaryFactory<'a> {
),
cache: cache_summary,
command,
cli_arguments: self.run_opts.pass_through_args.to_vec(),
cli_arguments,
outputs: match task_definition.outputs.inclusions.is_empty() {
false => Some(task_definition.outputs.inclusions.clone()),
true => None,
Expand Down
18 changes: 13 additions & 5 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,20 @@ impl<'a> Visitor<'a> {
};
package_task_event.track_env_mode(&task_env_mode.to_string());

let is_root_task = engine.dependents(&info).map_or(0, |x| x.len()) == 0;
let task_args = if is_root_task {
self.run_opts.pass_through_args.to_vec()
} else {
vec![]
};
let dependency_set = engine.dependencies(&info).ok_or(Error::MissingDefinition)?;

let task_hash_telemetry = package_task_event.child();
let task_hash = self.task_hasher.calculate_task_hash(
&info,
task_definition,
task_env_mode,
&task_args,
workspace_info,
dependency_set,
task_hash_telemetry,
Expand Down Expand Up @@ -275,6 +282,7 @@ impl<'a> Visitor<'a> {
task_cache,
workspace_directory,
execution_env,
task_args,
takes_input,
self.task_access.clone(),
);
Expand Down Expand Up @@ -629,11 +637,11 @@ impl<'a> ExecContextFactory<'a> {
task_cache: TaskCache,
workspace_directory: AbsoluteSystemPathBuf,
execution_env: EnvironmentVariableMap,
pass_through_args: Vec<String>,
takes_input: bool,
task_access: TaskAccess,
) -> ExecContext {
let task_id_for_display = self.visitor.display_task_id(&task_id);
let pass_through_args = self.visitor.run_opts.args_for_task(&task_id);
ExecContext {
engine: self.engine.clone(),
ui: self.visitor.ui,
Expand Down Expand Up @@ -689,7 +697,7 @@ struct ExecContext {
task_hash: String,
execution_env: EnvironmentVariableMap,
continue_on_error: bool,
pass_through_args: Option<Vec<String>>,
pass_through_args: Vec<String>,
errors: Arc<Mutex<Vec<TaskError>>>,
takes_input: bool,
task_access: TaskAccess,
Expand Down Expand Up @@ -861,13 +869,13 @@ impl ExecContext {

let mut cmd = Command::new(package_manager_binary);
let mut args = vec!["run".to_string(), self.task_id.task().to_string()];
if let Some(pass_through_args) = &self.pass_through_args {
if self.pass_through_args.len() > 0 {
args.extend(
self.package_manager
.arg_separator(pass_through_args.as_slice())
.arg_separator(self.pass_through_args.as_slice())
.map(|s| s.to_string()),
);
args.extend(pass_through_args.iter().cloned());
args.extend(self.pass_through_args.iter().cloned());
}
cmd.args(args);
cmd.current_dir(self.workspace_directory.clone());
Expand Down
14 changes: 13 additions & 1 deletion crates/turborepo-lib/src/task_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ pub struct TaskHashTracker {
pub struct TaskHashTrackerState {
#[serde(skip)]
package_task_env_vars: HashMap<TaskId<'static>, DetailedMap>,
#[serde(skip)]
package_task_args: HashMap<TaskId<'static>, Vec<String>>,
package_task_hashes: HashMap<TaskId<'static>, String>,
#[serde(skip)]
package_task_framework: HashMap<TaskId<'static>, String>,
Expand Down Expand Up @@ -282,6 +284,7 @@ impl<'a> TaskHasher<'a> {
task_id: &TaskId<'static>,
task_definition: &TaskDefinition,
task_env_mode: ResolvedEnvMode,
task_args: &Vec<String>,
workspace: &PackageInfo,
dependency_set: HashSet<&TaskNode>,
telemetry: PackageTaskEventBuilder,
Expand Down Expand Up @@ -396,7 +399,7 @@ impl<'a> TaskHasher<'a> {
task: task_id.task(),
outputs,

pass_through_args: &self.run_opts.pass_through_args,
pass_through_args: task_args,
env: &task_definition.env,
resolved_env_vars: hashable_env_pairs,
pass_through_env: task_definition
Expand All @@ -412,6 +415,7 @@ impl<'a> TaskHasher<'a> {
self.task_hash_tracker.insert_hash(
task_id.clone(),
env_vars,
task_args.clone(),
task_hash.clone(),
framework_slug,
);
Expand Down Expand Up @@ -546,13 +550,16 @@ impl TaskHashTracker {
&self,
task_id: TaskId<'static>,
env_vars: DetailedMap,
args: Vec<String>,
hash: String,
framework_slug: Option<String>,
) {
let mut state = self.state.lock().expect("hash tracker mutex poisoned");
state
.package_task_env_vars
.insert(task_id.clone(), env_vars);
state.package_task_args.insert(task_id.clone(), args);

if let Some(framework) = framework_slug {
state
.package_task_framework
Expand All @@ -566,6 +573,11 @@ impl TaskHashTracker {
state.package_task_env_vars.get(task_id).cloned()
}

pub fn cli_args(&self, task_id: &TaskId) -> Option<Vec<String>> {
let state = self.state.lock().expect("hash tracker mutex poisoned");
state.package_task_args.get(task_id).cloned()
}

pub fn framework(&self, task_id: &TaskId) -> Option<String> {
let state = self.state.lock().expect("hash tracker mutex poisoned");
state.package_task_framework.get(task_id).cloned()
Expand Down