Skip to content
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

Optimize generated subtargets' interaction with SpecifiedSourceFiles #10454

Merged
merged 1 commit into from Jul 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/python/pants/core/util_rules/determine_source_files.py
Expand Up @@ -10,6 +10,7 @@
SourceRootStrippedSources,
StripSourcesFieldRequest,
)
from pants.engine.addresses import Address
from pants.engine.fs import MergeDigests, PathGlobs, Snapshot, SnapshotSubset
from pants.engine.rules import RootRule, rule
from pants.engine.selectors import Get, MultiGet
Expand Down Expand Up @@ -76,10 +77,11 @@ def __init__(


def calculate_specified_sources(
sources_snapshot: Snapshot, origin: OriginSpec
sources_snapshot: Snapshot, address: Address, origin: OriginSpec
) -> Union[Snapshot, SnapshotSubset]:
# AddressSpecs simply use the entire `sources` field.
if isinstance(origin, AddressSpec):
# AddressSpecs simply use the entire `sources` field. If it's a generated subtarget, we also
# know we're as precise as we can get (1 file), so use the whole snapshot.
if isinstance(origin, AddressSpec) or address.generated_base_target_name:
return sources_snapshot
# NB: we ensure that `precise_files_specified` is a subset of the original `sources` field.
# It's possible when given a glob filesystem spec that the spec will have
Expand Down Expand Up @@ -149,7 +151,9 @@ async def determine_specified_source_files(request: SpecifiedSourceFilesRequest)
sources_field, origin = sources_field_with_origin
if not hydrated_sources.snapshot.files:
continue
specified_sources = calculate_specified_sources(hydrated_sources.snapshot, origin)
specified_sources = calculate_specified_sources(
hydrated_sources.snapshot, sources_field.address, origin
)
if isinstance(specified_sources, Snapshot):
full_snapshots[sources_field] = specified_sources
else:
Expand Down