use of com.facebook.buck.util.environment.Platform in project buck by facebook.
the class ProjectGeneratorTest method getBuildRuleResolverNodeFunction.
private Function<TargetNode<?, ?>, BuildRuleResolver> getBuildRuleResolverNodeFunction(final TargetGraph targetGraph) {
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException> bottomUpTraversal = new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(targetGraph) {
@Override
@SuppressWarnings("PMD.EmptyCatchBlock")
public void visit(TargetNode<?, ?> node) {
try {
resolver.requireRule(node.getBuildTarget());
} catch (Exception e) {
// NOTE(agallagher): A large number of the tests appear to setup their target nodes
// incorrectly, causing action graph creation to fail with lots of missing expected
// Apple C/C++ platform flavors. This is gross, but to support tests that need a
// complete sub-action graph, just skip over the errors.
}
}
};
bottomUpTraversal.traverse();
return input -> resolver;
}
use of com.facebook.buck.util.environment.Platform in project buck by facebook.
the class GoPlatformFlavorDomain method getValue.
public Optional<GoPlatform> getValue(Flavor flavor) {
String[] components = flavor.getName().split("_");
if (components.length != 2) {
return Optional.empty();
}
Platform os = goOsValues.get(components[0]);
Architecture arch = goArchValues.get(components[1]);
if (os != null && arch != null) {
return Optional.of(GoPlatform.builder().setGoOs(components[0]).setGoArch(components[1]).setCxxPlatform(getCxxPlatform(os, arch)).build());
}
return Optional.empty();
}
use of com.facebook.buck.util.environment.Platform in project buck by facebook.
the class JUnitStep method getTimeoutHandler.
@Override
protected Optional<Consumer<Process>> getTimeoutHandler(final ExecutionContext context) {
return Optional.of(process -> {
Optional<Long> pid = Optional.empty();
Platform platform = context.getPlatform();
try {
switch(platform) {
case LINUX:
case FREEBSD:
case MACOS:
{
Field field = process.getClass().getDeclaredField("pid");
field.setAccessible(true);
try {
pid = Optional.of((long) field.getInt(process));
} catch (IllegalAccessException e) {
LOG.error(e, "Failed to access `pid`.");
}
break;
}
case WINDOWS:
{
Field field = process.getClass().getDeclaredField("handle");
field.setAccessible(true);
try {
pid = Optional.of(field.getLong(process));
} catch (IllegalAccessException e) {
LOG.error(e, "Failed to access `handle`.");
}
break;
}
case UNKNOWN:
LOG.info("Unknown platform; unable to obtain the process id!");
break;
}
} catch (NoSuchFieldException e) {
LOG.error(e);
}
Optional<Path> jstack = new ExecutableFinder(context.getPlatform()).getOptionalExecutable(Paths.get("jstack"), context.getEnvironment());
if (!pid.isPresent() || !jstack.isPresent()) {
LOG.info("Unable to print a stack trace for timed out test!");
return;
}
context.getStdErr().println("Test has timed out! Here is a trace of what it is currently doing:");
try {
context.getProcessExecutor().launchAndExecute(ProcessExecutorParams.builder().addCommand(jstack.get().toString(), "-l", pid.get().toString()).setEnvironment(context.getEnvironment()).build(), ImmutableSet.<ProcessExecutor.Option>builder().add(ProcessExecutor.Option.PRINT_STD_OUT).add(ProcessExecutor.Option.PRINT_STD_ERR).build(), Optional.empty(), Optional.of(TimeUnit.SECONDS.toMillis(30)), Optional.of(input -> {
context.getStdErr().print("Printing the stack took longer than 30 seconds. No longer trying.");
}));
} catch (Exception e) {
LOG.error(e);
}
});
}
use of com.facebook.buck.util.environment.Platform in project buck by facebook.
the class Main method daemonizeIfPossible.
private static void daemonizeIfPossible() {
String osName = System.getProperty("os.name");
Libc.OpenPtyLibrary openPtyLibrary;
Platform platform = Platform.detect();
if (platform == Platform.LINUX) {
Libc.Constants.rTIOCSCTTY = Libc.Constants.LINUX_TIOCSCTTY;
Libc.Constants.rFDCLOEXEC = Libc.Constants.LINUX_FD_CLOEXEC;
Libc.Constants.rFGETFD = Libc.Constants.LINUX_F_GETFD;
Libc.Constants.rFSETFD = Libc.Constants.LINUX_F_SETFD;
openPtyLibrary = (Libc.OpenPtyLibrary) Native.loadLibrary("libutil", Libc.OpenPtyLibrary.class);
} else if (platform == Platform.MACOS) {
Libc.Constants.rTIOCSCTTY = Libc.Constants.DARWIN_TIOCSCTTY;
Libc.Constants.rFDCLOEXEC = Libc.Constants.DARWIN_FD_CLOEXEC;
Libc.Constants.rFGETFD = Libc.Constants.DARWIN_F_GETFD;
Libc.Constants.rFSETFD = Libc.Constants.DARWIN_F_SETFD;
openPtyLibrary = (Libc.OpenPtyLibrary) Native.loadLibrary(com.sun.jna.Platform.C_LIBRARY_NAME, Libc.OpenPtyLibrary.class);
} else {
LOG.info("not enabling process killing on nailgun exit: unknown OS %s", osName);
return;
}
// Making ourselves a session leader with setsid disconnects us from our controlling terminal
int ret = Libc.INSTANCE.setsid();
if (ret < 0) {
LOG.warn("cannot enable background process killing: %s", Native.getLastError());
return;
}
LOG.info("enabling background process killing for buckd");
IntByReference master = new IntByReference();
IntByReference slave = new IntByReference();
if (openPtyLibrary.openpty(master, slave, Pointer.NULL, Pointer.NULL, Pointer.NULL) != 0) {
throw new RuntimeException("Failed to open pty");
}
// Deliberately leak the file descriptors for the lifetime of this process; NuProcess can
// sometimes leak file descriptors to children, so make sure these FDs are marked close-on-exec.
markFdCloseOnExec(master.getValue());
markFdCloseOnExec(slave.getValue());
// Make the pty our controlling terminal; works because we disconnected above with setsid.
if (Libc.INSTANCE.ioctl(slave.getValue(), Pointer.createConstant(Libc.Constants.rTIOCSCTTY), 0) == -1) {
throw new RuntimeException("Failed to set pty");
}
LOG.info("enabled background process killing for buckd");
isSessionLeader = true;
}
use of com.facebook.buck.util.environment.Platform in project buck by facebook.
the class DistBuildState method createBuckConfig.
private static BuckConfig createBuckConfig(Config config, ProjectFilesystem projectFilesystem, BuildJobStateBuckConfig remoteBuckConfig) {
Architecture remoteArchitecture = Architecture.valueOf(remoteBuckConfig.getArchitecture());
Architecture localArchitecture = Architecture.detect();
Preconditions.checkState(remoteArchitecture.equals(localArchitecture), "Trying to load config with architecture %s on a machine that is %s. " + "This is not supported.", remoteArchitecture, localArchitecture);
Platform remotePlatform = Platform.valueOf(remoteBuckConfig.getPlatform());
Platform localPlatform = Platform.detect();
Preconditions.checkState(remotePlatform.equals(localPlatform), "Trying to load config with platform %s on a machine that is %s. This is not supported.", remotePlatform, localPlatform);
return new BuckConfig(config, projectFilesystem, remoteArchitecture, remotePlatform, ImmutableMap.copyOf(remoteBuckConfig.getUserEnvironment()), new DefaultCellPathResolver(projectFilesystem.getRootPath(), config));
}
Aggregations