diff --git a/src/python/pants/base/specs.py b/src/python/pants/base/specs.py index 296b44856db..1fb404d38fb 100644 --- a/src/python/pants/base/specs.py +++ b/src/python/pants/base/specs.py @@ -333,6 +333,7 @@ def __bool__(self) -> bool: class Specs: address_specs: AddressSpecs filesystem_specs: FilesystemSpecs + from_change_detection: bool = False @property def provided(self) -> bool: diff --git a/src/python/pants/engine/internals/graph.py b/src/python/pants/engine/internals/graph.py index ea0fad1d0e8..293e1b040ef 100644 --- a/src/python/pants/engine/internals/graph.py +++ b/src/python/pants/engine/internals/graph.py @@ -1320,7 +1320,18 @@ async def find_valid_field_sets_for_target_roots( ) if request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.error: raise no_applicable_exception - if request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.warn: + # We squelch the warning if the specs came from change detection or only from address globs, + # since in that case we interpret the user's intent as "if there are relevant matching + # targets, act on them". But we still want to warn if the specs were literal, or empty. + empty_ok = specs.from_change_detection or ( + specs.address_specs.globs + and not specs.address_specs.literals + and not specs.filesystem_specs + ) + if ( + request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.warn + and not empty_ok + ): logger.warning(str(no_applicable_exception)) result = TargetRootsToFieldSets(targets_to_applicable_field_sets) diff --git a/src/python/pants/init/specs_calculator.py b/src/python/pants/init/specs_calculator.py index 4443f9b605f..8e5dbc0c89a 100644 --- a/src/python/pants/init/specs_calculator.py +++ b/src/python/pants/init/specs_calculator.py @@ -75,7 +75,11 @@ def calculate_specs( parameters=address_input.parameters, ) ) - return Specs(AddressSpecs(address_specs, filter_by_global_options=True), FilesystemSpecs([])) + return Specs( + AddressSpecs(address_specs, filter_by_global_options=True), + FilesystemSpecs([]), + from_change_detection=True, + ) def rules():