Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject metadata for UnresolvedSymlinkAction #24832

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.devtools.build.lib.util.HashCodes;
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
Expand Down Expand Up @@ -277,13 +278,20 @@ public static FileArtifactValue createForVirtualActionInput(byte[] digest, long
return new RegularFileArtifactValue(digest, /* proxy= */ null, size);
}

@VisibleForTesting
public static FileArtifactValue createForUnresolvedSymlink(Artifact artifact) throws IOException {
checkArgument(artifact.isSymlink());
return createForUnresolvedSymlink(artifact.getPath());
}

public static FileArtifactValue createForUnresolvedSymlink(Path symlink) throws IOException {
return new UnresolvedSymlinkArtifactValue(symlink);
return new UnresolvedSymlinkArtifactValue(
symlink.readSymbolicLink().getPathString(), symlink.getFileSystem());
}

public static FileArtifactValue createForUnresolvedSymlinkWithKnownTarget(
Path symlink, String symlinkTarget) {
return new UnresolvedSymlinkArtifactValue(symlinkTarget, symlink.getFileSystem());
}

public static FileArtifactValue createForNormalFile(
Expand Down Expand Up @@ -726,16 +734,9 @@ public static final class UnresolvedSymlinkArtifactValue extends FileArtifactVal
private final String symlinkTarget;
private final byte[] digest;

private UnresolvedSymlinkArtifactValue(Path symlink) throws IOException {
String symlinkTarget = symlink.readSymbolicLink().getPathString();

private UnresolvedSymlinkArtifactValue(String symlinkTarget, FileSystem fs) {
byte[] digest =
symlink
.getFileSystem()
.getDigestFunction()
.getHashFunction()
.hashString(symlinkTarget, ISO_8859_1)
.asBytes();
fs.getDigestFunction().getHashFunction().hashString(symlinkTarget, ISO_8859_1).asBytes();

// We need to be able to tell the difference between a symlink and a file containing the same
// text. So we transform the digest a bit. This works because if one wants to craft a file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.lib.actions.ActionResult;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactExpander;
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
Expand Down Expand Up @@ -81,6 +82,16 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
throw new ActionExecutionException(message, e, this, false, code);
}

// Action filesystems are responsible for their own metadata injection.
if (actionExecutionContext.getActionFileSystem() == null) {
actionExecutionContext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether this can be done inside skyframe (i.e. we don't need to add special case for action filesystem)?

cc @tjgq

.getOutputMetadataStore()
.injectFile(
getPrimaryOutput(),
FileArtifactValue.createForUnresolvedSymlinkWithKnownTarget(
getPrimaryOutput().getPath(), target.getPathString()));
}

return ActionResult.EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib/exec/util",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
import static org.mockito.Mockito.mock;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
Expand All @@ -28,6 +29,7 @@
import com.google.devtools.build.lib.actions.DiscoveredModulesPruner;
import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.ThreadStateReceiver;
import com.google.devtools.build.lib.actions.cache.OutputMetadataStore;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.RepositoryName;
Expand Down Expand Up @@ -106,7 +108,7 @@ public void testSymlink() throws Exception {
/* actionInputFileCache= */ null,
ActionInputPrefetcher.NONE,
actionKeyContext,
/* outputMetadataStore= */ null,
mock(OutputMetadataStore.class),
/* rewindingEnabled= */ false,
LostInputsCheck.NONE,
/* fileOutErr= */ null,
Expand Down