2323import com .google .common .io .BaseEncoding ;
2424import com .google .devtools .build .lib .actions .FileValue ;
2525import com .google .devtools .build .lib .analysis .BlazeDirectories ;
26+ import com .google .devtools .build .lib .cmdline .LabelConstants ;
2627import com .google .devtools .build .lib .cmdline .LabelValidator ;
2728import com .google .devtools .build .lib .cmdline .RepositoryName ;
2829import com .google .devtools .build .lib .skyframe .ActionEnvironmentFunction ;
@@ -115,8 +116,7 @@ public static boolean areAllValuesUpToDate(
115116 throws InterruptedException {
116117 env .getValuesAndExceptions (
117118 recordedInputValues .keySet ().stream ()
118- .map (RepoRecordedInput ::getSkyKey )
119- .filter (Objects ::nonNull )
119+ .map (rri -> rri .getSkyKey (directories ))
120120 .collect (toImmutableSet ()));
121121 if (env .valuesMissing ()) {
122122 return false ;
@@ -157,18 +157,14 @@ public int compareTo(RepoRecordedInput o) {
157157 /** Returns the parser object for this type of recorded inputs. */
158158 public abstract Parser getParser ();
159159
160- /**
161- * Returns the {@link SkyKey} that is necessary to determine {@link #isUpToDate}. Can be null if
162- * no SkyKey is needed.
163- */
164- @ Nullable
165- public abstract SkyKey getSkyKey ();
160+ /** Returns the {@link SkyKey} that is necessary to determine {@link #isUpToDate}. */
161+ public abstract SkyKey getSkyKey (BlazeDirectories directories );
166162
167163 /**
168164 * Returns whether the given {@code oldValue} is still up-to-date for this recorded input. This
169- * method can assume that {@link #getSkyKey()} is already evaluated; it can request further
170- * Skyframe evaluations, and if any values are missing, this method can return any value (doesn't
171- * matter what) and will be reinvoked after a Skyframe restart.
165+ * method can assume that {@link #getSkyKey(BlazeDirectories )} is already evaluated; it can
166+ * request further Skyframe evaluations, and if any values are missing, this method can return any
167+ * value (doesn't matter what) and will be reinvoked after a Skyframe restart.
172168 */
173169 public abstract boolean isUpToDate (
174170 Environment env , BlazeDirectories directories , @ Nullable String oldValue )
@@ -226,32 +222,25 @@ public static RepoCacheFriendlyPath parse(String s) {
226222 return createOutsideWorkspace (PathFragment .create (s ));
227223 }
228224
229- /**
230- * If resolving this path requires getting a {@link RepositoryDirectoryValue}, this method
231- * returns the appropriate key; otherwise it returns null.
232- */
233- @ Nullable
234- public final RepositoryDirectoryValue .Key getRepoDirSkyKeyOrNull () {
235- if (repoName ().isEmpty () || repoName ().get ().isMain ()) {
236- return null ;
237- }
238- return RepositoryDirectoryValue .key (repoName ().get ());
239- }
240-
241- public final RootedPath getRootedPath (Environment env , BlazeDirectories directories )
242- throws InterruptedException {
225+ /** Returns the rooted path corresponding to this "repo-friendly path". */
226+ public final RootedPath getRootedPath (BlazeDirectories directories ) {
243227 Root root ;
244228 if (repoName ().isEmpty ()) {
245229 root = Root .absoluteRoot (directories .getOutputBase ().getFileSystem ());
246230 } else if (repoName ().get ().isMain ()) {
247231 root = Root .fromPath (directories .getWorkspace ());
248232 } else {
249- RepositoryDirectoryValue repoDirValue =
250- (RepositoryDirectoryValue ) env .getValue (getRepoDirSkyKeyOrNull ());
251- if (repoDirValue == null || !repoDirValue .repositoryExists ()) {
252- return null ;
253- }
254- root = Root .fromPath (repoDirValue .getPath ());
233+ // This path is from an external repo. We just directly fabricate the path here instead of
234+ // requesting the appropriate RepositoryDirectoryValue, since we can rely on the various
235+ // other SkyFunctions (such as FileStateFunction and DirectoryListingStateFunction) to do
236+ // that for us instead. This also sidesteps an awkward situation when the external repo in
237+ // question is not defined.
238+ root =
239+ Root .fromPath (
240+ directories
241+ .getOutputBase ()
242+ .getRelative (LabelConstants .EXTERNAL_REPOSITORY_LOCATION )
243+ .getRelative (repoName ().get ().getName ()));
255244 }
256245 return RootedPath .toRootedPath (root , path ());
257246 }
@@ -331,23 +320,18 @@ public static String fileValueToMarkerValue(FileValue fileValue) throws IOExcept
331320 return BaseEncoding .base16 ().lowerCase ().encode (digest );
332321 }
333322
334- @ Override
335323 @ Nullable
336- public SkyKey getSkyKey () {
337- return path .getRepoDirSkyKeyOrNull ( );
324+ public SkyKey getSkyKey (BlazeDirectories directories ) {
325+ return FileValue . key ( path .getRootedPath ( directories ) );
338326 }
339327
340328 @ Override
341329 public boolean isUpToDate (
342330 Environment env , BlazeDirectories directories , @ Nullable String oldValue )
343331 throws InterruptedException {
344- RootedPath rootedPath = path .getRootedPath (env , directories );
345- if (rootedPath == null ) {
346- return false ;
347- }
348- SkyKey fileKey = FileValue .key (rootedPath );
349332 try {
350- FileValue fileValue = (FileValue ) env .getValueOrThrow (fileKey , IOException .class );
333+ FileValue fileValue =
334+ (FileValue ) env .getValueOrThrow (getSkyKey (directories ), IOException .class );
351335 if (fileValue == null ) {
352336 return false ;
353337 }
@@ -406,25 +390,22 @@ public Parser getParser() {
406390 return PARSER ;
407391 }
408392
409- @ Nullable
410393 @ Override
411- public SkyKey getSkyKey () {
412- return path .getRepoDirSkyKeyOrNull ( );
394+ public SkyKey getSkyKey (BlazeDirectories directories ) {
395+ return DirectoryListingValue . key ( path .getRootedPath ( directories ) );
413396 }
414397
415398 @ Override
416399 public boolean isUpToDate (
417400 Environment env , BlazeDirectories directories , @ Nullable String oldValue )
418401 throws InterruptedException {
419- RootedPath rootedPath = path .getRootedPath (env , directories );
420- if (rootedPath == null ) {
421- return false ;
422- }
423- if (env .getValue (DirectoryListingValue .key (rootedPath )) == null ) {
402+ SkyKey skyKey = getSkyKey (directories );
403+ if (env .getValue (skyKey ) == null ) {
424404 return false ;
425405 }
426406 try {
427- return oldValue .equals (getDirentsMarkerValue (rootedPath .asPath ()));
407+ return oldValue .equals (
408+ getDirentsMarkerValue (((DirectoryListingValue .Key ) skyKey ).argument ().asPath ()));
428409 } catch (IOException e ) {
429410 return false ;
430411 }
@@ -493,22 +474,17 @@ public Parser getParser() {
493474 return PARSER ;
494475 }
495476
496- @ Nullable
497477 @ Override
498- public SkyKey getSkyKey () {
499- return path .getRepoDirSkyKeyOrNull ( );
478+ public SkyKey getSkyKey (BlazeDirectories directories ) {
479+ return DirectoryTreeDigestValue . key ( path .getRootedPath ( directories ) );
500480 }
501481
502482 @ Override
503483 public boolean isUpToDate (
504484 Environment env , BlazeDirectories directories , @ Nullable String oldValue )
505485 throws InterruptedException {
506- RootedPath rootedPath = path .getRootedPath (env , directories );
507- if (rootedPath == null ) {
508- return false ;
509- }
510486 DirectoryTreeDigestValue value =
511- (DirectoryTreeDigestValue ) env .getValue (DirectoryTreeDigestValue . key ( rootedPath ));
487+ (DirectoryTreeDigestValue ) env .getValue (getSkyKey ( directories ));
512488 if (value == null ) {
513489 return false ;
514490 }
@@ -565,7 +541,7 @@ public String toStringInternal() {
565541 }
566542
567543 @ Override
568- public SkyKey getSkyKey () {
544+ public SkyKey getSkyKey (BlazeDirectories directories ) {
569545 return ActionEnvironmentFunction .key (name );
570546 }
571547
@@ -575,7 +551,7 @@ public boolean isUpToDate(
575551 throws InterruptedException {
576552 String v = PrecomputedValue .REPO_ENV .get (env ).get (name );
577553 if (v == null ) {
578- v = ((ClientEnvironmentValue ) env .getValue (getSkyKey ())).getValue ();
554+ v = ((ClientEnvironmentValue ) env .getValue (getSkyKey (directories ))).getValue ();
579555 }
580556 // Note that `oldValue` can be null if the env var was not set.
581557 return Objects .equals (oldValue , v );
@@ -636,7 +612,7 @@ public String toStringInternal() {
636612 }
637613
638614 @ Override
639- public SkyKey getSkyKey () {
615+ public SkyKey getSkyKey (BlazeDirectories directories ) {
640616 // Since we only record repo mapping entries for repos defined in Bzlmod, we can request the
641617 // WORKSPACE-less version of the main repo mapping (as no repos defined in Bzlmod can see
642618 // stuff from WORKSPACE).
@@ -649,7 +625,8 @@ public SkyKey getSkyKey() {
649625 public boolean isUpToDate (
650626 Environment env , BlazeDirectories directories , @ Nullable String oldValue )
651627 throws InterruptedException {
652- RepositoryMappingValue repoMappingValue = (RepositoryMappingValue ) env .getValue (getSkyKey ());
628+ RepositoryMappingValue repoMappingValue =
629+ (RepositoryMappingValue ) env .getValue (getSkyKey (directories ));
653630 return repoMappingValue != RepositoryMappingValue .NOT_FOUND_VALUE
654631 && RepositoryName .createUnvalidated (oldValue )
655632 .equals (repoMappingValue .getRepositoryMapping ().get (apparentName ));
0 commit comments