Skip to content

Commit

Permalink
Make jdeps rewriting work with arbitrary PathMappers
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Apr 18, 2023
1 parent 8f7857e commit 1eb1d03
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,16 +736,14 @@ static Deps.Dependencies createFullOutputDeps(
return executorJdeps;
}

// For each of the action's generated inputs, map its stripped path to its full path.
PathFragment outputRoot = outputDepsProto.getExecPath().subFragment(0, 1);
Map<PathFragment, PathFragment> strippedToFullPaths = new HashMap<>();
// For each of the action's generated inputs, revert its mapped path back to its original path.
Map<String, PathFragment> mappedToOriginalPath = new HashMap<>();
for (Artifact actionInput : actionInputs.toList()) {
if (actionInput.isSourceArtifact()) {
continue;
}
// Turns "bazel-out/x86-fastbuild/bin/foo" to "bazel-out/bin/foo".
PathFragment strippedPath = outputRoot.getRelative(actionInput.getExecPath().subFragment(2));
if (strippedToFullPaths.put(strippedPath, actionInput.getExecPath()) != null) {
String mappedPath = pathMapper.getMappedExecPathString(actionInput);
if (mappedToOriginalPath.put(mappedPath, actionInput.getExecPath()) != null) {
// If an entry already exists, that means different inputs reduce to the same stripped path.
// That also means PathStripper would exempt this action from path stripping, so the
// executor-produced .jdeps already includes full paths. No need to update it.
Expand All @@ -759,16 +757,17 @@ static Deps.Dependencies createFullOutputDeps(
}

// Rewrite the .jdeps proto with full paths.
PathFragment outputRoot = outputDepsProto.getExecPath().subFragment(0, 1);
Deps.Dependencies.Builder fullDepsBuilder = Deps.Dependencies.newBuilder(executorJdeps);
for (Deps.Dependency.Builder dep : fullDepsBuilder.getDependencyBuilderList()) {
PathFragment pathOnExecutor = PathFragment.create(dep.getPath());
PathFragment fullPath = strippedToFullPaths.get(pathOnExecutor);
if (fullPath == null && pathOnExecutor.subFragment(0, 1).equals(outputRoot)) {
// The stripped path -> full path map failed, which means the paths weren't stripped. Fast-
PathFragment originalPath = mappedToOriginalPath.get(pathOnExecutor.getPathString());
if (originalPath == null && pathOnExecutor.subFragment(0, 1).equals(outputRoot)) {
// The mapped path -> full path map failed, which means the paths weren't mapped. Fast-
// return the original jdeps to save unnecessary CPU time.
return executorJdeps;
}
dep.setPath(fullPath == null ? pathOnExecutor.getPathString() : fullPath.getPathString());
dep.setPath(originalPath == null ? pathOnExecutor.getPathString() : originalPath.getPathString());
}
Deps.Dependencies fullOutputDeps = fullDepsBuilder.build();

Expand Down

0 comments on commit 1eb1d03

Please sign in to comment.