Add an event for source directory encountered in a build.

PiperOrigin-RevId: 437843565
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index a13373f..f734c0d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -275,6 +275,10 @@
       return new MissingArtifactValue(artifact);
     }
 
+    if (fileValue.isDirectory()) {
+      env.getListener().post(SourceDirectoryEvent.create(artifact.getExecPath()));
+    }
+
     if (!fileValue.isDirectory() || !TrackSourceDirectoriesFlag.trackSourceDirectories()) {
       FileArtifactValue metadata;
       try {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
index 7397d83..253f241 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -615,6 +615,16 @@
 )
 
 java_library(
+    name = "source_directory_event",
+    srcs = ["SourceDirectoryEvent.java"],
+    deps = [
+        "//src/main/java/com/google/devtools/build/lib/events",
+        "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
+        "//third_party:auto_value",
+    ],
+)
+
+java_library(
     name = "artifact_function",
     srcs = ["ArtifactFunction.java"],
     deps = [
@@ -625,6 +635,7 @@
         ":metadata_consumer_for_metrics",
         ":recursive_filesystem_traversal",
         ":runfiles_artifact_value",
+        ":source_directory_event",
         ":track_source_directories_flag",
         ":tree_artifact_value",
         "//src/main/java/com/google/devtools/build/lib/actions",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SourceDirectoryEvent.java b/src/main/java/com/google/devtools/build/lib/skyframe/SourceDirectoryEvent.java
new file mode 100644
index 0000000..73fdf17
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SourceDirectoryEvent.java
@@ -0,0 +1,29 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skyframe;
+
+import com.google.auto.value.AutoValue;
+import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike;
+import com.google.devtools.build.lib.vfs.PathFragment;
+
+/** Event issued when a source directory is encountered in {@link ArtifactFunction}. */
+@AutoValue
+public abstract class SourceDirectoryEvent implements ProgressLike {
+  public abstract PathFragment execPath();
+
+  public static SourceDirectoryEvent create(PathFragment execPath) {
+    return new AutoValue_SourceDirectoryEvent(execPath);
+  }
+}