From 0c15fc97e266dc509be2476c0299746b4a2e3c54 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Thu, 19 Oct 2017 15:03:44 -0700 Subject: [PATCH] Invalidate parent directories (#5000) ### Problem Watchman `4.9.0` does not send events for a parent when a child is created or deleted, which causes issues like #4662. ### Solution Revert to explicitly invalidating the parent directory when a child has changed. More precision is possible here, but it's possible that re-gaining the precision by using the `notify` crate would be preferable (see #4999). ### Result Fixes #4662. --- src/python/pants/engine/scheduler.py | 11 +++++------ tests/python/pants_test/engine/legacy/test_graph.py | 5 +---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/python/pants/engine/scheduler.py b/src/python/pants/engine/scheduler.py index 0b99ddba0c4..66c72f26e0d 100644 --- a/src/python/pants/engine/scheduler.py +++ b/src/python/pants/engine/scheduler.py @@ -414,13 +414,12 @@ def root_entries(self, execution_request): self._execution_request, execution_request)) return self._scheduler.root_entries(execution_request) - def invalidate_files(self, filenames): + def invalidate_files(self, direct_filenames): """Calls `Graph.invalidate_files()` against an internal product Graph instance.""" - # NB: Watchman will never trigger an invalidation event for the root directory that - # is being watched. Instead, we treat any invalidation of a path directly in the - # root directory as an invalidation of the root. - if any(os.path.dirname(f) in ('', '.') for f in filenames): - filenames = tuple(filenames) + ('', '.') + # NB: Watchman no longer triggers events when children are created/deleted under a directory, + # so we always need to invalidate the direct parent as well. + filenames = set(direct_filenames) + filenames.update(os.path.dirname(f) for f in direct_filenames) with self._product_graph_lock: invalidated = self._scheduler.invalidate(filenames) logger.debug('invalidated %d nodes for: %s', invalidated, filenames) diff --git a/tests/python/pants_test/engine/legacy/test_graph.py b/tests/python/pants_test/engine/legacy/test_graph.py index abd15e3c494..17d74c26646 100644 --- a/tests/python/pants_test/engine/legacy/test_graph.py +++ b/tests/python/pants_test/engine/legacy/test_graph.py @@ -126,10 +126,7 @@ def test_invalidate_fsnode_incremental(self): # Invalidate the '3rdparty/python' DirectoryListing, the `3rdparty` DirectoryListing, # and then the root DirectoryListing by "touching" files/dirs. - # NB: Invalidation of entries in the root directory is special: because Watchman will - # never trigger an event for the root itself, we treat changes to files in the root - # directory as events for the root. - for filename in ('3rdparty/python/BUILD', '3rdparty/python', 'non_existing_file'): + for filename in ('3rdparty/python/BUILD', '3rdparty/jvm', 'non_existing_file'): invalidated_count = scheduler.invalidate_files([filename]) self.assertGreater(invalidated_count, 0,