pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.29k stars 628 forks source link

shell/adhoc: use metadata hashing instead of content hashing for `workspace_invalidation_sources` #21092

Closed tdyas closed 3 months ago

tdyas commented 3 months ago

Switch to using metadata-based invalidation instead of content-based invalidation for any sources referenced by the workspace_invalidation_sources field.

This is necessary because workspace_invalidation_sources is intended to be used with the experimental_workspace_environment and there is a problem with content-based invalidation in that scenario: There is a potential cache poisoning scenario where Pants computes a content digest but then the user overwrites the digested sources before Pants has executed the applicable adhoc_tool / shell_command process. The cache will now have a result stored under the digest of the original file version even though the file content changed. See https://github.com/pantsbuild/pants/pull/21051#issuecomment-2174995973 for expanded discussion.

tdyas commented 3 months ago

Also added setters for PyPathMetadata so the tests can manipulate an existing metadata instance.