Search in sources :

Example 26 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class AppleCxxPlatformsTest method buildAppleCxxPlatformWithSwiftToolchain.

private AppleCxxPlatform buildAppleCxxPlatformWithSwiftToolchain(boolean useDefaultSwift) throws IOException {
    Path tempRoot = temp.getRoot();
    AppleToolchain swiftToolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(tempRoot).setVersion("1").build();
    temp.newFolder("usr", "bin");
    temp.newFolder("usr", "lib", "swift", "iphoneos");
    temp.newFolder("usr", "lib", "swift_static", "iphoneos");
    MoreFiles.makeExecutable(temp.newFile("usr/bin/swift"));
    MoreFiles.makeExecutable(temp.newFile("usr/bin/swift-stdlib-tool"));
    Optional<AppleToolchain> selectedSwiftToolChain = useDefaultSwift ? Optional.empty() : Optional.of(swiftToolchain);
    final ImmutableSet<Path> knownPaths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/iPhoneOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/iPhoneOS.platform/Developer/usr/bin/ar")).add(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/swift")).add(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-stdlib-tool")).build();
    return AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_SDK, "7.0", "i386", FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_SDK_PATHS, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new ExecutableFinder() {

        @Override
        public Optional<Path> getOptionalExecutable(Path suggestedPath, ImmutableCollection<Path> searchPath, ImmutableCollection<String> fileSuffixes) {
            Optional<Path> realPath = super.getOptionalExecutable(suggestedPath, searchPath, fileSuffixes);
            if (realPath.isPresent()) {
                return realPath;
            }
            for (Path path : knownPaths) {
                if (suggestedPath.equals(path.getFileName())) {
                    return Optional.of(path);
                }
            }
            return Optional.empty();
        }
    }, Optional.of(FakeAppleRuleDescriptions.PROCESS_EXECUTOR), selectedSwiftToolChain);
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Optional(java.util.Optional) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 27 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class LuaBinaryIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    // We don't currently support windows.
    assumeThat(Platform.detect(), Matchers.not(Platform.WINDOWS));
    // Verify that a Lua interpreter is available on the system.
    LuaBuckConfig fakeConfig = new LuaBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
    Optional<Path> luaOptional = fakeConfig.getSystemLua();
    assumeTrue(luaOptional.isPresent());
    lua = luaOptional.get();
    // Try to detect if a Lua devel package is available, which is needed to C/C++ support.
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(Platform.detect(), new FakeProjectFilesystem(), new CxxBuckConfig(FakeBuckConfig.builder().build()));
    ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(resolver).getCommandPrefix(new SourcePathResolver(new SourcePathRuleFinder(resolver)))).add("-includelua.h", "-E", "-").build()).setRedirectInput(ProcessBuilder.Redirect.PIPE).build();
    ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
    ProcessExecutor.LaunchedProcess launchedProcess = executor.launchProcess(params);
    launchedProcess.getOutputStream().close();
    int exitCode = executor.waitForLaunchedProcess(launchedProcess).getExitCode();
    luaDevel = exitCode == 0;
    if (starterType == LuaBinaryDescription.StarterType.NATIVE) {
        assumeTrue("Lua devel package required for native starter", luaDevel);
    }
    // Setup the workspace.
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "lua_binary", tmp);
    workspace.setUp();
    workspace.writeContentsToPath(Joiner.on(System.lineSeparator()).join(ImmutableList.of("[lua]", "  starter_type = " + starterType.toString().toLowerCase(), "  native_link_strategy = " + nativeLinkStrategy.toString().toLowerCase(), "[cxx]", "  sandbox_sources =" + sandboxSources)), ".buckconfig");
    LuaBuckConfig config = getLuaBuckConfig();
    assertThat(config.getStarterType(), Matchers.equalTo(Optional.of(starterType)));
    assertThat(config.getNativeLinkStrategy(), Matchers.equalTo(nativeLinkStrategy));
}
Also used : Path(java.nio.file.Path) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Before(org.junit.Before)

Example 28 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class OCamlIntegrationTest method getOcamlVersion.

private String getOcamlVersion(ProjectWorkspace workspace) throws IOException, InterruptedException {
    Path ocamlc = new ExecutableFinder(Platform.detect()).getExecutable(Paths.get("ocamlc"), ImmutableMap.copyOf(System.getenv()));
    ProcessExecutor.Result result = workspace.runCommand(ocamlc.toString(), "-version");
    assertEquals(0, result.getExitCode());
    return result.getStdout().get();
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 29 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class ResolverIntegrationTest method createParser.

@BeforeClass
public static void createParser() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuckConfig buckConfig = FakeBuckConfig.builder().build();
    ParserConfig parserConfig = buckConfig.getView(ParserConfig.class);
    PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(buckConfig, new ExecutableFinder());
    ImmutableSet<Description<?>> descriptions = ImmutableSet.of(new RemoteFileDescription(new ExplodingDownloader()), new PrebuiltJarDescription());
    DefaultProjectBuildFileParserFactory parserFactory = new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(filesystem.getRootPath()).setPythonInterpreter(pythonBuckConfig.getPythonInterpreter()).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(filesystem.getIgnorePaths()).setBuildFileName(parserConfig.getBuildFileName()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(descriptions).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
    buildFileParser = parserFactory.createParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())), new TestConsole(), ImmutableMap.of(), BuckEventBusFactory.newInstance(), /* ignoreBuckAutodepsFiles */
    false);
}
Also used : PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) PrebuiltJarDescription(com.facebook.buck.jvm.java.PrebuiltJarDescription) RemoteFileDescription(com.facebook.buck.file.RemoteFileDescription) Description(com.facebook.buck.rules.Description) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) RemoteFileDescription(com.facebook.buck.file.RemoteFileDescription) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ExplodingDownloader(com.facebook.buck.file.ExplodingDownloader) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) PrebuiltJarDescription(com.facebook.buck.jvm.java.PrebuiltJarDescription) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) ParserConfig(com.facebook.buck.parser.ParserConfig) BeforeClass(org.junit.BeforeClass)

Example 30 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class NdkBuildStep method getShellCommandInternal.

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    Optional<Path> ndkRoot = context.getAndroidPlatformTarget().getNdkDirectory();
    if (!ndkRoot.isPresent()) {
        throw new HumanReadableException("Must set ANDROID_NDK to point to the absolute path of your Android NDK directory.");
    }
    Optional<Path> ndkBuild = new ExecutableFinder().getOptionalExecutable(Paths.get("ndk-build"), ndkRoot.get());
    if (!ndkBuild.isPresent()) {
        throw new HumanReadableException("Unable to find ndk-build");
    }
    ConcurrencyLimit concurrencyLimit = context.getConcurrencyLimit();
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    builder.add(ndkBuild.get().toAbsolutePath().toString(), "-j", // coordinate job concurrency.
    Integer.toString(concurrencyLimit.threadLimit), "-C", this.root.toString());
    if (concurrencyLimit.loadLimit < Double.POSITIVE_INFINITY) {
        builder.add("--load-average", Double.toString(concurrencyLimit.loadLimit));
    }
    Iterable<String> flags = Iterables.transform(this.flags, macroExpander);
    builder.addAll(flags);
    // We want relative, not absolute, paths in the debug-info for binaries we build using
    // ndk_library.  Absolute paths are machine-specific, but relative ones should be the
    // same everywhere.
    Path relativePathToProject = filesystem.resolve(root).relativize(filesystem.getRootPath());
    builder.add("APP_PROJECT_PATH=" + filesystem.resolve(buildArtifactsDirectory) + File.separatorChar, "APP_BUILD_SCRIPT=" + filesystem.resolve(makefile), "NDK_OUT=" + filesystem.resolve(buildArtifactsDirectory) + File.separatorChar, "NDK_LIBS_OUT=" + filesystem.resolve(binDirectory), "BUCK_PROJECT_DIR=" + relativePathToProject);
    // Suppress the custom build step messages (e.g. "Compile++ ...").
    if (Platform.detect() == Platform.WINDOWS) {
        builder.add("host-echo-build-step=@REM");
    } else {
        builder.add("host-echo-build-step=@#");
    }
    // If we're running verbosely, force all the subcommands from the ndk build to be printed out.
    if (context.getVerbosity().shouldPrintCommand()) {
        builder.add("V=1");
    // Otherwise, suppress everything, including the "make: entering directory..." messages.
    } else {
        builder.add("--silent");
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ExecutableFinder (com.facebook.buck.io.ExecutableFinder)47 Path (java.nio.file.Path)28 Test (org.junit.Test)20 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)9 PythonBuckConfig (com.facebook.buck.python.PythonBuckConfig)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)5 BuildTarget (com.facebook.buck.model.BuildTarget)5 ParserConfig (com.facebook.buck.parser.ParserConfig)5 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)5 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 DefaultProjectBuildFileParserFactory (com.facebook.buck.json.DefaultProjectBuildFileParserFactory)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 TestConsole (com.facebook.buck.testutil.TestConsole)4 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)3 Config (com.facebook.buck.config.Config)3 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)3