Skip to content

Commit 27feff3

Browse files
committed
internal: Task fixes and improvements. (#1974)
* Move impl. * Add tests. * Hash action data. * Rework via. * Rework env substitution. * Fixes. * Fixes.
1 parent db9c848 commit 27feff3

26 files changed

Lines changed: 532 additions & 302 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
- Fixed an issue where terminal prompt validation would not trigger.
4343
- Fixed an issue with remote cache hydration where multiple files with the same blob hash would fail
4444
to write them all.
45+
- Fixed an issue where changing `args` or `env` of a task dependency would not invalidate its cache.
46+
- Fixed an issue where environment variables passed on the command line would not overwrite task
47+
`env`.
48+
- Fixed tag-based task dependencies not creating implicit project dependencies.
4549
- Fixed some task/command argument quoting issues.
4650

4751
#### 🧩 Plugins

crates/app/src/commands/project.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ pub async fn project(session: MoonSession, args: ProjectArgs) -> AppResult {
169169
ListItem {
170170
StyledText(
171171
content: format!(
172-
"{} <mutedlight>({}, {})</mutedlight>",
172+
"{} <mutedlight>({})</mutedlight>",
173173
dep.id,
174-
dep.source,
175-
dep.scope,
174+
if let Some(via) = &dep.via {
175+
format!("{} via {via}", dep.scope)
176+
} else {
177+
dep.scope.to_string()
178+
},
176179
),
177180
style: Style::Id
178181
)

crates/cli/tests/snapshots/project_test__basic_config.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ About ──────────────────
1111
Stack: unknown
1212
Type: unknown
1313
Depends on:
14-
- noConfig (explicit, production)
14+
- noConfig (production)
1515

1616
Configuation ───────────
1717

crates/cli/tests/snapshots/project_test__depends_on_paths.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ About ──────────────────
1111
Stack: unknown
1212
Type: application
1313
Depends on:
14-
- baz (explicit, production)
15-
- bar (explicit, production)
14+
- baz (production)
15+
- bar (production)
1616

1717
Configuation ───────────
1818

crates/env-var/src/env_scanner.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::env_substitutor::ENV_VAR_SUBSTITUTE;
2+
use rustc_hash::FxHashSet;
3+
4+
#[derive(Default)]
5+
pub struct EnvScanner {
6+
pub found: FxHashSet<String>,
7+
}
8+
9+
impl EnvScanner {
10+
pub fn scan(&mut self, value: impl AsRef<str>) -> String {
11+
self.do_scan(value)
12+
}
13+
14+
fn do_scan(&mut self, value: impl AsRef<str>) -> String {
15+
let value = value.as_ref();
16+
17+
if !value.contains('$') {
18+
self.found.clear();
19+
20+
return value.to_owned();
21+
}
22+
23+
let mut found = FxHashSet::default();
24+
25+
let result = ENV_VAR_SUBSTITUTE.replace_all(value, |caps: &regex::Captures| {
26+
let Some(name) = caps
27+
.name("name1")
28+
.or_else(|| caps.name("name2"))
29+
.map(|cap| cap.as_str())
30+
else {
31+
return String::new();
32+
};
33+
34+
found.insert(name.to_owned());
35+
36+
format!("${name}")
37+
});
38+
39+
self.found = found;
40+
41+
result.to_string()
42+
}
43+
}

crates/env-var/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
mod env_scanner;
12
mod env_substitutor;
23
mod global_bag;
34

5+
pub use env_scanner::*;
46
pub use env_substitutor::*;
57
pub use global_bag::*;

crates/process/src/command.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::shell::Shell;
55
use moon_common::{color, is_test_env};
66
use moon_console::Console;
7+
use moon_env_var::GlobalEnvBag;
78
use rustc_hash::{FxHashMap, FxHasher};
89
use std::collections::VecDeque;
910
use std::env;
@@ -143,6 +144,25 @@ impl Command {
143144
self
144145
}
145146

147+
pub fn envs_if_not_global<I, K, V>(&mut self, vars: I) -> &mut Self
148+
where
149+
I: IntoIterator<Item = (K, V)>,
150+
K: AsRef<OsStr>,
151+
V: AsRef<OsStr>,
152+
{
153+
let bag = GlobalEnvBag::instance();
154+
155+
for (k, v) in vars {
156+
let k = k.as_ref();
157+
158+
if !bag.has(k) {
159+
self.env(k, v);
160+
}
161+
}
162+
163+
self
164+
}
165+
146166
pub fn inherit_colors(&mut self) -> &mut Self {
147167
// Don't show colors in our own tests, as it disrupts snapshots
148168
if !is_test_env() {

crates/project-builder/src/project_builder.rs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use moon_common::path::WorkspaceRelativePath;
22
use moon_common::{Id, color};
33
use moon_config::{
4-
ConfigLoader, DependencyConfig, DependencyScope, DependencySource, InheritedTasksManager,
5-
InheritedTasksResult, LanguageType, ProjectConfig, ProjectDependsOn, TaskConfig,
6-
ToolchainConfig,
4+
ConfigLoader, DependencyConfig, DependencySource, InheritedTasksManager, InheritedTasksResult,
5+
LanguageType, ProjectConfig, ProjectDependsOn, TaskConfig, ToolchainConfig,
76
};
87
use moon_file_group::FileGroup;
98
use moon_project::Project;
10-
use moon_task::{TargetScope, Task};
11-
use moon_task_builder::{TasksBuilder, TasksBuilderContext};
9+
use moon_task::Task;
10+
use moon_task_builder::{TasksBuilder, TasksBuilderContext, create_project_dep_from_task_dep};
1211
use moon_toolchain::detect::{
1312
detect_project_language, detect_project_toolchains, get_project_toolchains,
1413
};
@@ -312,35 +311,19 @@ impl<'app> ProjectBuilder<'app> {
312311
// Tasks can depend on arbitrary projects, so include them also
313312
for task_config in tasks.values() {
314313
for task_dep in &task_config.deps {
315-
if let TargetScope::Project(dep_id) = &task_dep.target.scope {
316-
// Already a dependency, or references self
317-
if deps.contains_key(dep_id)
318-
|| self.id == dep_id
319-
|| self.alias.as_ref().is_some_and(|a| *a == dep_id.as_str())
320-
{
321-
continue;
322-
}
323-
324-
trace!(
325-
project_id = self.id.as_str(),
326-
dep_id = dep_id.as_str(),
327-
task_target = task_config.target.as_str(),
328-
"Marking arbitrary project as an implicit dependency because of a task dependency"
329-
);
330-
331-
deps.insert(
332-
dep_id.to_owned(),
333-
DependencyConfig {
334-
id: dep_id.to_owned(),
335-
scope: if self.context.root_project_id.is_some_and(|id| id == dep_id) {
336-
DependencyScope::Root
337-
} else {
338-
DependencyScope::Build
339-
},
340-
source: DependencySource::Implicit,
341-
via: Some(task_config.target.to_string()),
342-
},
343-
);
314+
if let Some(dep_config) = create_project_dep_from_task_dep(
315+
task_dep,
316+
self.id,
317+
self.context.root_project_id,
318+
|dep_project_id| {
319+
deps.contains_key(dep_project_id)
320+
|| self
321+
.alias
322+
.as_ref()
323+
.is_some_and(|alias| alias.as_str() == dep_project_id.as_str())
324+
},
325+
) {
326+
deps.insert(dep_config.id.clone(), dep_config);
344327
}
345328
}
346329
}

crates/task-builder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ publish = false
1111
[dependencies]
1212
moon_common = { path = "../common" }
1313
moon_config = { path = "../config", features = ["loader"] }
14+
moon_project = { path = "../project" }
1415
moon_target = { path = "../target" }
1516
moon_task = { path = "../task" }
1617
moon_task_args = { path = "../task-args" }

0 commit comments

Comments
 (0)