Skip to content

Commit

Permalink
Include the full absolute paths of runfiles in action keys
Browse files Browse the repository at this point in the history
Both `SourceManifestAction` and `SymlinkTreeAction`, the only users of
`Runfiles#fingerprint`, emit absolute paths to runfiles artifacts in
their output. This requires also including these paths in the action key
computation to prevent incorrect incremental builds if `--output_base`
changes.
  • Loading branch information
fmeum committed Aug 4, 2023
1 parent 90ee766 commit bb35179
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
27 changes: 21 additions & 6 deletions src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public void fingerprint(Fingerprint fp) {
args.accept(symlink.getArtifact().getExecPathString());
};

private static final CommandLineItem.ExceptionlessMapFn<Artifact>
RUNFILES_AND_ABSOLUTE_PATH_MAP_FN =
(artifact, args) -> {
args.accept(artifact.getRunfilesPathString());
args.accept(artifact.getPath().getPathString());
};

private static final CommandLineItem.ExceptionlessMapFn<Artifact> RUNFILES_AND_EXEC_PATH_MAP_FN =
(artifact, args) -> {
args.accept(artifact.getRunfilesPathString());
Expand All @@ -109,7 +116,7 @@ public void fingerprint(Fingerprint fp) {
/**
* The directory to put all runfiles under.
*
* <p>Using "foo" will put runfiles under &lt;target&gt;.runfiles/foo.</p>
* <p>Using "foo" will put runfiles under &lt;target&gt;.runfiles/foo.
*
* <p>This is either set to the workspace name, or is empty.
*/
Expand Down Expand Up @@ -1112,15 +1119,19 @@ public Runfiles mergeAll(Sequence<?> sequence, StarlarkThread thread) throws Eva
}
}

/** Fingerprint this {@link Runfiles} tree. */
public void fingerprint(ActionKeyContext actionKeyContext, Fingerprint fp) {
/** Fingerprint this {@link Runfiles} tree, including the absolute paths of artifacts. */
public void fingerprint(
ActionKeyContext actionKeyContext, Fingerprint fp, boolean digestAbsolutePaths) {
fp.addInt(conflictPolicy.ordinal());
fp.addBoolean(legacyExternalRunfiles);
fp.addPath(suffix);

actionKeyContext.addNestedSetToFingerprint(SYMLINK_ENTRY_MAP_FN, fp, symlinks);
actionKeyContext.addNestedSetToFingerprint(SYMLINK_ENTRY_MAP_FN, fp, rootSymlinks);
actionKeyContext.addNestedSetToFingerprint(RUNFILES_AND_EXEC_PATH_MAP_FN, fp, artifacts);
actionKeyContext.addNestedSetToFingerprint(
digestAbsolutePaths ? RUNFILES_AND_ABSOLUTE_PATH_MAP_FN : RUNFILES_AND_EXEC_PATH_MAP_FN,
fp,
artifacts);

emptyFilesSupplier.fingerprint(fp);

Expand All @@ -1129,7 +1140,7 @@ public void fingerprint(ActionKeyContext actionKeyContext, Fingerprint fp) {
}

/** Describes the inputs {@link #fingerprint} uses to aid describeKey() descriptions. */
public String describeFingerprint() {
public String describeFingerprint(boolean digestAbsolutePaths) {
return String.format("conflictPolicy: %s\n", conflictPolicy)
+ String.format("legacyExternalRunfiles: %s\n", legacyExternalRunfiles)
+ String.format("suffix: %s\n", suffix)
Expand All @@ -1139,7 +1150,11 @@ public String describeFingerprint() {
"rootSymlinks: %s\n", describeNestedSetFingerprint(SYMLINK_ENTRY_MAP_FN, rootSymlinks))
+ String.format(
"artifacts: %s\n",
describeNestedSetFingerprint(RUNFILES_AND_EXEC_PATH_MAP_FN, artifacts))
describeNestedSetFingerprint(
digestAbsolutePaths
? RUNFILES_AND_ABSOLUTE_PATH_MAP_FN
: RUNFILES_AND_EXEC_PATH_MAP_FN,
artifacts))
+ String.format("emptyFilesSupplier: %s\n", emptyFilesSupplier.getClass().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void writeEntry(
* @return
*/
boolean isRemotable();

/** Whether the manifest includes absolute paths to artifacs. */
boolean emitsAbsolutePaths();
}

/** The strategy we use to write manifest entries. */
Expand Down Expand Up @@ -254,7 +257,7 @@ protected void computeKey(
Fingerprint fp) {
fp.addString(GUID);
fp.addBoolean(remotableSourceManifestActions);
runfiles.fingerprint(actionKeyContext, fp);
runfiles.fingerprint(actionKeyContext, fp, manifestWriter.emitsAbsolutePaths());
fp.addBoolean(repoMappingManifest != null);
if (repoMappingManifest != null) {
fp.addPath(repoMappingManifest.getExecPath());
Expand All @@ -265,7 +268,9 @@ protected void computeKey(
public String describeKey() {
return String.format(
"GUID: %s\nremotableSourceManifestActions: %s\nrunfiles: %s\n",
GUID, remotableSourceManifestActions, runfiles.describeFingerprint());
GUID,
remotableSourceManifestActions,
runfiles.describeFingerprint(manifestWriter.emitsAbsolutePaths()));
}

/** Supported manifest writing strategies. */
Expand Down Expand Up @@ -311,6 +316,11 @@ public boolean isRemotable() {
// There is little gain to remoting these, since they include absolute path names inline.
return false;
}

@Override
public boolean emitsAbsolutePaths() {
return true;
}
},

/**
Expand Down Expand Up @@ -346,6 +356,11 @@ public boolean isRemotable() {
// Source-only symlink manifest has root-relative paths and does not include absolute paths.
return true;
}

@Override
public boolean emitsAbsolutePaths() {
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected void computeKey(
// safe to add more fields in the future.
fp.addBoolean(runfiles != null);
if (runfiles != null) {
runfiles.fingerprint(actionKeyContext, fp);
runfiles.fingerprint(actionKeyContext, fp, /* digestAbsolutePaths= */ true);
}
fp.addBoolean(repoMappingManifest != null);
if (repoMappingManifest != null) {
Expand Down

0 comments on commit bb35179

Please sign in to comment.