Search in sources :

Example 1 with Platform

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;
}
Also used : ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(com.facebook.buck.apple.project_generator.ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) AppleBundleExtension(com.facebook.buck.apple.AppleBundleExtension) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) AppleLibraryBuilder(com.facebook.buck.apple.AppleLibraryBuilder) InternalFlavor(com.facebook.buck.model.InternalFlavor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FlavorDomain(com.facebook.buck.model.FlavorDomain) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSDictionary(com.dd.plist.NSDictionary) FileAttribute(java.nio.file.attribute.FileAttribute) BuildTarget(com.facebook.buck.model.BuildTarget) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Assert.assertFalse(org.junit.Assert.assertFalse) StringWithMacrosUtils(com.facebook.buck.rules.macros.StringWithMacrosUtils) ByteStreams(com.google.common.io.ByteStreams) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuckEventBus(com.facebook.buck.event.BuckEventBus) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase) Iterables(com.google.common.collect.Iterables) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) HalideLibraryDescription(com.facebook.buck.halide.HalideLibraryDescription) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) AppleBinaryBuilder(com.facebook.buck.apple.AppleBinaryBuilder) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) AppleAssetCatalogBuilder(com.facebook.buck.apple.AppleAssetCatalogBuilder) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Assert.assertTrue(org.junit.Assert.assertTrue) ProductType(com.facebook.buck.apple.xcode.xcodeproj.ProductType) AppleResourceBuilder(com.facebook.buck.apple.AppleResourceBuilder) Test(org.junit.Test) IOException(java.io.IOException) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase) SceneKitAssetsBuilder(com.facebook.buck.apple.SceneKitAssetsBuilder) CxxSource(com.facebook.buck.cxx.CxxSource) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) HalideLibraryBuilder(com.facebook.buck.halide.HalideLibraryBuilder) Paths(java.nio.file.Paths) AppleLibraryDescription(com.facebook.buck.apple.AppleLibraryDescription) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) Assert.assertEquals(org.junit.Assert.assertEquals) IosReactNativeLibraryBuilder(com.facebook.buck.js.IosReactNativeLibraryBuilder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) XcodePostbuildScriptBuilder(com.facebook.buck.apple.XcodePostbuildScriptBuilder) Matchers.hasKey(org.hamcrest.Matchers.hasKey) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) Assert.assertThat(org.junit.Assert.assertThat) AppleConfig(com.facebook.buck.apple.AppleConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Cell(com.facebook.buck.rules.Cell) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) AppleBundleBuilder(com.facebook.buck.apple.AppleBundleBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Collection(java.util.Collection) Platform(com.facebook.buck.util.environment.Platform) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) XcodePrebuildScriptBuilder(com.facebook.buck.apple.XcodePrebuildScriptBuilder) List(java.util.List) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeAppleRuleDescriptions(com.facebook.buck.apple.FakeAppleRuleDescriptions) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription) Optional(java.util.Optional) Assume.assumeTrue(org.junit.Assume.assumeTrue) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CoreMatchers.not(org.hamcrest.CoreMatchers.not) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) AbstractBottomUpTraversal(com.facebook.buck.graph.AbstractBottomUpTraversal) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NSString(com.dd.plist.NSString) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) ExpectedException(org.junit.rules.ExpectedException) MoreCollectors(com.facebook.buck.util.MoreCollectors) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) Matchers(org.hamcrest.Matchers) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TimeUnit(java.util.concurrent.TimeUnit) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) AppleTestBuilder(com.facebook.buck.apple.AppleTestBuilder) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) CoreDataModelBuilder(com.facebook.buck.apple.CoreDataModelBuilder) CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) Flavor(com.facebook.buck.model.Flavor) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) InputStream(java.io.InputStream) TargetNode(com.facebook.buck.rules.TargetNode) AbstractBottomUpTraversal(com.facebook.buck.graph.AbstractBottomUpTraversal) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) IOException(java.io.IOException) ExpectedException(org.junit.rules.ExpectedException) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 2 with Platform

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();
}
Also used : Platform(com.facebook.buck.util.environment.Platform) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Architecture(com.facebook.buck.util.environment.Architecture)

Example 3 with Platform

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);
        }
    });
}
Also used : Path(java.nio.file.Path) Logger(com.facebook.buck.log.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Platform(com.facebook.buck.util.environment.Platform) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) Field(java.lang.reflect.Field) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ExecutionContext(com.facebook.buck.step.ExecutionContext) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ImmutableList(com.google.common.collect.ImmutableList) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Paths(java.nio.file.Paths) Map(java.util.Map) Optional(java.util.Optional) ShellStep(com.facebook.buck.shell.ShellStep) Path(java.nio.file.Path) Field(java.lang.reflect.Field) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) Platform(com.facebook.buck.util.environment.Platform)

Example 4 with Platform

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;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Platform(com.facebook.buck.util.environment.Platform) Libc(com.facebook.buck.util.Libc)

Example 5 with Platform

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));
}
Also used : DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) Architecture(com.facebook.buck.util.environment.Architecture) Platform(com.facebook.buck.util.environment.Platform) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildJobStateBuckConfig(com.facebook.buck.distributed.thrift.BuildJobStateBuckConfig)

Aggregations

Platform (com.facebook.buck.util.environment.Platform)11 Path (java.nio.file.Path)8 ImmutableMap (com.google.common.collect.ImmutableMap)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 Test (org.junit.Test)3 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)2 AppleConfig (com.facebook.buck.apple.AppleConfig)2 AppleLibraryDescription (com.facebook.buck.apple.AppleLibraryDescription)2 BuckConfig (com.facebook.buck.cli.BuckConfig)2 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)2 JavaBuckConfig (com.facebook.buck.jvm.java.JavaBuckConfig)2 CommandThreadFactory (com.facebook.buck.log.CommandThreadFactory)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 Architecture (com.facebook.buck.util.environment.Architecture)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 Paths (java.nio.file.Paths)2 HashMap (java.util.HashMap)2