Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jun 30, 2024
1 parent 9e237d2 commit 2584270
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_java//java:defs.bzl", "java_library")

package(
Expand All @@ -13,15 +14,26 @@ filegroup(
visibility = ["//src:__subpackages__"],
)

copy_file(
name = "xcode_locator",
src = "//tools/osx:xcode-locator",
out = "xcode-locator",
)

java_library(
name = "worker",
srcs = glob(["*.java"]),
data = [
":xcode_locator",
],
resources = ["//src/main/tools:linux-sandbox"],
visibility = ["//src/tools/remote:__subpackages__"],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/exec:bin_tools",
"//src/main/java/com/google/devtools/build/lib/exec/local",
"//src/main/java/com/google/devtools/build/lib/remote",
"//src/main/java/com/google/devtools/build/lib/remote:store",
"//src/main/java/com/google/devtools/build/lib/remote/common",
Expand All @@ -46,6 +58,7 @@ java_library(
"//third_party/grpc-java:grpc-jar",
"//third_party/protobuf:protobuf_java",
"//third_party/protobuf:protobuf_java_util",
"@bazel_tools//tools/java/runfiles",
"@googleapis//:google_bytestream_bytestream_java_grpc",
"@googleapis//:google_bytestream_bytestream_java_proto",
"@googleapis//:google_longrunning_operations_java_proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
import build.bazel.remote.execution.v2.RequestMetadata;
import build.bazel.remote.execution.v2.WaitExecutionRequest;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.events.NullEventHandler;
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.exec.local.LocalEnvProvider;
import com.google.devtools.build.lib.remote.ExecutionStatusException;
import com.google.devtools.build.lib.remote.UploadManifest;
import com.google.devtools.build.lib.remote.common.CacheNotFoundException;
Expand All @@ -50,6 +53,7 @@
import com.google.devtools.build.lib.shell.FutureCommandResult;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.runfiles.Runfiles;
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
import com.google.protobuf.ExtensionRegistry;
Expand Down Expand Up @@ -102,6 +106,8 @@ final class ExecutionServer extends ExecutionImplBase {
private final ConcurrentHashMap<String, ListenableFuture<ActionResult>> operationsCache;
private final ListeningExecutorService executorService;
private final DigestUtil digestUtil;
private final LocalEnvProvider localEnvProvider;
private final BinTools binTools;

public ExecutionServer(
Path workPath,
Expand Down Expand Up @@ -135,6 +141,21 @@ public ExecutionServer(
// Allow the core threads to die.
realExecutor.allowCoreThreadTimeOut(true);
this.executorService = MoreExecutors.listeningDecorator(realExecutor);
this.localEnvProvider = LocalEnvProvider.forCurrentOs(System.getenv());
String xcodeLocator;
try {
xcodeLocator =
Runfiles.preload()
.withSourceRepository("")
.rlocation(
"io_bazel/src/tools/remote/src/main/java/com/google/devtools/build/remote/xcode-locator");
} catch (IOException e) {
throw new IllegalStateException(e);
}
this.binTools =
BinTools.forEmbeddedBin(
workPath.getFileSystem().getPath(xcodeLocator).getParentDirectory(),
ImmutableList.of("xcode-locator"));
}

@Override
Expand Down Expand Up @@ -410,12 +431,13 @@ private static boolean wasTimeout(long timeoutMillis, long wallTimeMillis) {
return timeoutMillis > 0 && wallTimeMillis > timeoutMillis;
}

private static Map<String, String> getEnvironmentVariables(Command command) {
private Map<String, String> getEnvironmentVariables(Command command)
throws IOException, InterruptedException {
HashMap<String, String> result = new HashMap<>();
for (EnvironmentVariable v : command.getEnvironmentVariablesList()) {
result.put(v.getName(), v.getValue());
}
return result;
return localEnvProvider.rewriteLocalEnv(result, binTools, "/tmp");
}

// Gets the uid of the current user. If uid could not be successfully fetched (e.g., on other
Expand Down Expand Up @@ -490,7 +512,7 @@ private static String platformAsString(@Nullable Platform platform) {
// arguments. Otherwise, returns a Command that would run the specified command inside the
// specified docker container.
private com.google.devtools.build.lib.shell.Command getCommand(Command cmd, String pathString)
throws StatusException, InterruptedException {
throws StatusException, InterruptedException, IOException {
Map<String, String> environmentVariables = getEnvironmentVariables(cmd);
// This allows Bazel's integration tests to test for the remote platform.
environmentVariables.put("BAZEL_REMOTE_PLATFORM", platformAsString(cmd.getPlatform()));
Expand Down

0 comments on commit 2584270

Please sign in to comment.