From a1ea487e0a9e180a36fa4aab57f7c746ddcf367a Mon Sep 17 00:00:00 2001
From: ichern <ichern@google.com>
Date: Thu, 16 May 2019 08:20:32 -0700
Subject: [PATCH] Do not pre-cache changed files under managed directories

Closes #8337.

PiperOrigin-RevId: 248530274
---
 .../build/lib/skyframe/DirtinessCheckerUtils.java    |  3 ++-
 .../lib/skyframe/SequencedSkyframeExecutor.java      | 12 +++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
index 860f4378039520..daaefcb1b80d42 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
@@ -144,7 +144,8 @@ public SkyValueDirtinessChecker.DirtyResult check(
         return SkyValueDirtinessChecker.DirtyResult.notDirty(oldValue);
       }
       FileType fileType = externalFilesHelper.getAndNoteFileType((RootedPath) skyKey.argument());
-      if (fileType == FileType.EXTERNAL_REPO) {
+      if (fileType == FileType.EXTERNAL_REPO
+          || fileType == FileType.EXTERNAL_IN_MANAGED_DIRECTORY) {
         // Files under output_base/external have a dependency on the WORKSPACE file, so we don't add
         // a new SkyValue to the graph yet because it might change once the WORKSPACE file has been
         // parsed.
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
index 9c7eefe8ea39bd..a760a30b578f41 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
@@ -490,9 +490,15 @@ private void handleDiffsWithMissingDiffInformation(
     ExternalFilesHelper tmpExternalFilesHelper =
         externalFilesHelper.cloneWithFreshExternalFilesKnowledge();
     // See the comment for FileType.OUTPUT for why we need to consider output files here.
-    EnumSet<FileType> fileTypesToCheck = checkOutputFiles
-        ? EnumSet.of(FileType.EXTERNAL, FileType.EXTERNAL_REPO, FileType.OUTPUT)
-        : EnumSet.of(FileType.EXTERNAL, FileType.EXTERNAL_REPO);
+    EnumSet<FileType> fileTypesToCheck =
+        checkOutputFiles
+            ? EnumSet.of(
+                FileType.EXTERNAL,
+                FileType.EXTERNAL_REPO,
+                FileType.EXTERNAL_IN_MANAGED_DIRECTORY,
+                FileType.OUTPUT)
+            : EnumSet.of(
+                FileType.EXTERNAL, FileType.EXTERNAL_REPO, FileType.EXTERNAL_IN_MANAGED_DIRECTORY);
     logger.info(
         "About to scan skyframe graph checking for filesystem nodes of types "
             + Iterables.toString(fileTypesToCheck));