Skip to content

Commit

Permalink
Make writing and reading flag file arguments interruptible.
Browse files Browse the repository at this point in the history
Looking into this also pointed out that input prefetching should be interruptible, but that's a larger piece of work.

PiperOrigin-RevId: 523984388
Change-Id: I82d96593a85e92beb37497230738bf6b223ddd22
  • Loading branch information
larsrc-google authored and copybara-github committed Apr 13, 2023
1 parent 6b55a66 commit 3485512
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public SandboxInputs processInputFiles(
Path withinSandboxExecRootPath,
ImmutableList<Root> packageRoots,
Path sandboxSourceRoots)
throws IOException {
throws IOException, InterruptedException {
Root withinSandboxExecRoot = Root.fromPath(withinSandboxExecRootPath);
Root execRoot =
withinSandboxExecRootPath.equals(execRootPath)
Expand All @@ -465,6 +465,9 @@ public SandboxInputs processInputFiles(
Map<Root, Root> sourceRootToSandboxSourceRoot = new TreeMap<>();

for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
PathFragment pathFragment = e.getKey();
ActionInput actionInput = e.getValue();
if (actionInput instanceof VirtualActionInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private WorkRequest createWorkRequest(
Map<VirtualActionInput, byte[]> virtualInputDigests,
InputMetadataProvider inputFileCache,
WorkerKey key)
throws IOException {
throws IOException, InterruptedException {
WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
for (String flagfile : flagfiles) {
expandArgument(execRoot, flagfile, requestBuilder);
Expand Down Expand Up @@ -298,8 +298,11 @@ private WorkRequest createWorkRequest(
* @throws java.io.IOException if one of the files containing options cannot be read.
*/
static void expandArgument(Path execRoot, String arg, WorkRequest.Builder requestBuilder)
throws IOException {
throws IOException, InterruptedException {
if (arg.startsWith("@") && !arg.startsWith("@@") && !isExternalRepositoryLabel(arg)) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
String argValue = arg.substring(1);
Path path = execRoot.getRelative(argValue);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected void setExecutable(PathFragment path, boolean executable) throws IOExc
sandboxHelpers.processInputFiles(
inputMap(input), customExecRoot, customExecRoot, ImmutableList.of(), null);
finishProcessingSemaphore.release();
} catch (IOException e) {
} catch (IOException | InterruptedException e) {
throw new IllegalArgumentException(e);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ public void testExecInWorker_throwsWithEmptyResponse() throws Exception {
}

@Test
public void testExpandArgument_expandsArgumentsRecursively() throws IOException {
public void testExpandArgument_expandsArgumentsRecursively()
throws IOException, InterruptedException {
WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
FileSystemUtils.writeIsoLatin1(fs.getPath("/file"), "arg1\n@file2\nmulti arg\n");
FileSystemUtils.writeIsoLatin1(fs.getPath("/file2"), "arg2\narg3");
Expand All @@ -521,7 +522,8 @@ public void testExpandArgument_expandsArgumentsRecursively() throws IOException
}

@Test
public void testExpandArgument_expandsOnlyProperArguments() throws IOException {
public void testExpandArgument_expandsOnlyProperArguments()
throws IOException, InterruptedException {
WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
FileSystemUtils.writeIsoLatin1(fs.getPath("/file"), "arg1\n@@nonfile\n@foo//bar\narg2");
WorkerSpawnRunner.expandArgument(fs.getPath("/"), "@file", requestBuilder);
Expand Down

0 comments on commit 3485512

Please sign in to comment.