Skip to content

Commit e001a50

Browse files
Stu Hoodillicitonion
Stu Hood
authored andcommitted
Review feedback from #5792. (#5796)
1 parent 0c5790f commit e001a50

File tree

5 files changed

+21
-50
lines changed

5 files changed

+21
-50
lines changed

src/python/pants/bin/engine_initializer.py

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from pants.base.specs import Specs
1414
from pants.engine.build_files import create_graph_rules
1515
from pants.engine.fs import create_fs_rules
16-
from pants.engine.isolated_process import create_process_rules
1716
from pants.engine.legacy.address_mapper import LegacyAddressMapper
1817
from pants.engine.legacy.graph import (LegacyBuildGraph, TransitiveHydratedTargets,
1918
create_legacy_graph_tasks)
@@ -182,7 +181,6 @@ def setup_legacy_graph(pants_ignore_patterns,
182181
create_legacy_graph_tasks(symbol_table) +
183182
create_fs_rules() +
184183
create_graph_rules(address_mapper, symbol_table) +
185-
create_process_rules() +
186184
rules
187185
)
188186

src/python/pants/engine/isolated_process.py

-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99

1010
from pants.engine.fs import EMPTY_SNAPSHOT
11-
from pants.engine.rules import RootRule
1211
from pants.util.objects import datatype
1312

1413

@@ -56,10 +55,3 @@ def __new__(cls, argv, env, input_files_digest, digest_length):
5655

5756
class ExecuteProcessResult(datatype(['stdout', 'stderr', 'exit_code'])):
5857
pass
59-
60-
61-
def create_process_rules():
62-
"""Intrinsically replaced on the rust side."""
63-
return [
64-
RootRule(ExecuteProcessRequest),
65-
]

src/rust/engine/src/nodes.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl Select {
265265
.core
266266
.rule_graph
267267
.edges_for_inner(entry)
268-
.expect("edges for Snapshot exist.");
268+
.expect("Expected edges to exist for Snapshot intrinsic.");
269269
// Compute PathGlobs for the subject.
270270
let context = context.clone();
271271
Select::new(
@@ -274,11 +274,7 @@ impl Select {
274274
self.variants.clone(),
275275
edges,
276276
).run(context.clone())
277-
.and_then(move |path_globs_val| {
278-
context.get(Snapshot {
279-
subject: externs::key_for(path_globs_val),
280-
})
281-
})
277+
.and_then(move |path_globs_val| context.get(Snapshot(externs::key_for(path_globs_val))))
282278
.to_boxed()
283279
}
284280

@@ -291,7 +287,7 @@ impl Select {
291287
.core
292288
.rule_graph
293289
.edges_for_inner(entry)
294-
.expect("edges for ExecuteProcessResult exist.");
290+
.expect("Expected edges to exist for ExecuteProcess intrinsic.");
295291
// Compute an ExecuteProcessRequest for the subject.
296292
let context = context.clone();
297293
Select::new(
@@ -713,9 +709,7 @@ impl From<Scandir> for NodeKey {
713709
/// A Node that captures an fs::Snapshot for a PathGlobs subject.
714710
///
715711
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
716-
pub struct Snapshot {
717-
subject: Key,
718-
}
712+
pub struct Snapshot(Key);
719713

720714
impl Snapshot {
721715
fn create(context: Context, path_globs: PathGlobs) -> NodeFuture<fs::Snapshot> {
@@ -812,7 +806,7 @@ impl Node for Snapshot {
812806
type Output = fs::Snapshot;
813807

814808
fn run(self, context: Context) -> NodeFuture<fs::Snapshot> {
815-
match Self::lift_path_globs(&externs::val_for(&self.subject)) {
809+
match Self::lift_path_globs(&externs::val_for(&self.0)) {
816810
Ok(pgs) => Self::create(context, pgs),
817811
Err(e) => err(throw(&format!("Failed to parse PathGlobs: {}", e))),
818812
}
@@ -981,7 +975,7 @@ impl NodeKey {
981975
keystr(&s.subject),
982976
typstr(&s.product)
983977
),
984-
&NodeKey::Snapshot(ref s) => format!("Snapshot({})", keystr(&s.subject)),
978+
&NodeKey::Snapshot(ref s) => format!("Snapshot({})", keystr(&s.0)),
985979
}
986980
}
987981

src/rust/engine/src/rule_graph.rs

+2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl From<RootEntry> for Entry {
6464

6565
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
6666
pub enum Rule {
67+
// Intrinsic rules are implemented in rust.
6768
Intrinsic(Intrinsic),
69+
// Task rules are implemented in python.
6870
Task(Task),
6971
}
7072

tests/python/pants_test/engine/test_isolated_process.py

+13-28
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import unittest
1111

1212
from pants.engine.fs import PathGlobs, Snapshot, create_fs_rules
13-
from pants.engine.isolated_process import (ExecuteProcessRequest, ExecuteProcessResult,
14-
create_process_rules)
13+
from pants.engine.isolated_process import ExecuteProcessRequest, ExecuteProcessResult
1514
from pants.engine.rules import RootRule, rule
1615
from pants.engine.selectors import Get, Select
1716
from pants.util.objects import TypeCheckError, datatype
@@ -64,26 +63,21 @@ def argv_from_snapshot(self, snapshot):
6463
class CatExecutionRequest(datatype([('shell_cat', ShellCat), ('path_globs', PathGlobs)])): pass
6564

6665

67-
@rule(ExecuteProcessRequest, [Select(CatExecutionRequest)])
68-
def cat_files_process_request_input_snapshot(cat_exe_req):
66+
@rule(Concatted, [Select(CatExecutionRequest)])
67+
def cat_files_process_result_concatted(cat_exe_req):
6968
cat_bin = cat_exe_req.shell_cat
7069
cat_files_snapshot = yield Get(Snapshot, PathGlobs, cat_exe_req.path_globs)
71-
yield ExecuteProcessRequest.create_from_snapshot(
70+
process_request = ExecuteProcessRequest.create_from_snapshot(
7271
argv=cat_bin.argv_from_snapshot(cat_files_snapshot),
7372
env=tuple(),
7473
snapshot=cat_files_snapshot,
7574
)
76-
77-
78-
@rule(Concatted, [Select(CatExecutionRequest)])
79-
def cat_files_process_result_concatted(cat_exe_req):
80-
cat_process_result = yield Get(ExecuteProcessResult, CatExecutionRequest, cat_exe_req)
75+
cat_process_result = yield Get(ExecuteProcessResult, ExecuteProcessRequest, process_request)
8176
yield Concatted(str(cat_process_result.stdout))
8277

8378

8479
def create_cat_stdout_rules():
8580
return [
86-
cat_files_process_request_input_snapshot,
8781
cat_files_process_result_concatted,
8882
RootRule(CatExecutionRequest),
8983
]
@@ -177,17 +171,6 @@ def argv_from_source_snapshot(self, snapshot):
177171
return (self.bin_path,) + tuple(snapshot_file_paths)
178172

179173

180-
@rule(ExecuteProcessRequest, [Select(JavacCompileRequest)])
181-
def javac_compile_sources_execute_process_request(javac_compile_req):
182-
sources_snapshot = yield Get(
183-
Snapshot, PathGlobs, javac_compile_req.javac_sources.path_globs)
184-
yield ExecuteProcessRequest.create_from_snapshot(
185-
argv=javac_compile_req.argv_from_source_snapshot(sources_snapshot),
186-
env=tuple(),
187-
snapshot=sources_snapshot,
188-
)
189-
190-
191174
# TODO: make this contain the snapshot(s?) of the output files (or contain
192175
# something that contains it) once we've made it so processes can make snapshots
193176
# of the files they produce.
@@ -196,10 +179,13 @@ class JavacCompileResult(object): pass
196179

197180
@rule(JavacCompileResult, [Select(JavacCompileRequest)])
198181
def javac_compile_process_result(javac_compile_req):
199-
javac_proc_req = yield Get(
200-
ExecuteProcessRequest, JavacCompileRequest, javac_compile_req)
201-
javac_proc_result = yield Get(
202-
ExecuteProcessResult, ExecuteProcessRequest, javac_proc_req)
182+
sources_snapshot = yield Get(Snapshot, PathGlobs, javac_compile_req.javac_sources.path_globs)
183+
process_request = ExecuteProcessRequest.create_from_snapshot(
184+
argv=javac_compile_req.argv_from_source_snapshot(sources_snapshot),
185+
env=tuple(),
186+
snapshot=sources_snapshot,
187+
)
188+
javac_proc_result = yield Get(ExecuteProcessResult, ExecuteProcessRequest, process_request)
203189

204190
exit_code = javac_proc_result.exit_code
205191
if exit_code != 0:
@@ -213,7 +199,6 @@ def javac_compile_process_result(javac_compile_req):
213199

214200
def create_javac_compile_rules():
215201
return [
216-
javac_compile_sources_execute_process_request,
217202
javac_compile_process_result,
218203
RootRule(JavacCompileRequest),
219204
]
@@ -328,5 +313,5 @@ def mk_example_fs_tree(self):
328313
return fs_tree
329314

330315
def mk_scheduler_in_example_fs(self, rules):
331-
rules = list(rules) + create_fs_rules() + create_process_rules()
316+
rules = list(rules) + create_fs_rules()
332317
return self.mk_scheduler(rules=rules, project_tree=self.mk_example_fs_tree())

0 commit comments

Comments
 (0)