Skip to content

Commit

Permalink
Cloc uses pre-captured Snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Jun 21, 2018
1 parent 36b4211 commit 1a81185
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/python/pants/backend/graph_info/tasks/cloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pants.backend.graph_info.subsystems.cloc_binary import ClocBinary
from pants.base.exceptions import TaskError
from pants.base.workunit import WorkUnitLabel
from pants.engine.fs import FilesContent, PathGlobs, PathGlobsAndRoot, Snapshot
from pants.engine.fs import FilesContent, PathGlobs, PathGlobsAndRoot
from pants.engine.isolated_process import ExecuteProcessRequest
from pants.task.console_task import ConsoleTask
from pants.util.contextutil import temporary_dir
Expand All @@ -36,16 +36,18 @@ def console_output(self, targets):
if not self.get_options().transitive:
targets = self.context.target_roots

input_snapshots = tuple(
target.sources_snapshot(scheduler=self.context._scheduler) for target in targets
)
input_files = set(f.path for snapshot in input_snapshots for f in snapshot.files)

# TODO: Work out a nice library-like utility for writing an argfile, as this will be common.
with temporary_dir() as tmpdir:
list_file = os.path.join(tmpdir, 'input_files_list')
input_files = set()
with open(list_file, 'w') as list_file_out:
for target in targets:
for source in target.sources_relative_to_buildroot():
input_files.add(source)
list_file_out.write(source)
list_file_out.write(b'\n')
for input_file in sorted(input_files):
list_file_out.write(input_file)
list_file_out.write(b'\n')
list_file_snapshot = self.context._scheduler.capture_snapshots((
PathGlobsAndRoot(
PathGlobs(('input_files_list',)),
Expand All @@ -55,17 +57,11 @@ def console_output(self, targets):

cloc_path, cloc_snapshot = ClocBinary.global_instance().hackily_snapshot(self.context)

# TODO: This should use an input file snapshot which should be provided on the Target object,
# rather than hackily re-snapshotting each of the input files.
# See https://github.com/pantsbuild/pants/issues/5762
input_pathglobs = PathGlobs(tuple(input_files))
input_snapshot = self.context._scheduler.product_request(Snapshot, [input_pathglobs])[0]

directory_digest = self.context._scheduler.merge_directories((
cloc_snapshot.directory_digest,
input_snapshot.directory_digest,
list_file_snapshot.directory_digest,
))
directory_digest = self.context._scheduler.merge_directories(tuple(s.directory_digest for s in
input_snapshots + (
cloc_snapshot,
list_file_snapshot,
)))

cmd = (
'/usr/bin/perl',
Expand Down

0 comments on commit 1a81185

Please sign in to comment.