Search in sources :

Example 1 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class ProjectGeneratorTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    clock = new SettableFakeClock(0, 0);
    fakeProjectFilesystem = new FakeProjectFilesystem(clock);
    projectCell = (new TestCellBuilder()).setFilesystem(fakeProjectFilesystem).build();
    projectFilesystem = projectCell.getFilesystem();
    rootPath = projectFilesystem.getRootPath();
    // Add files and directories used to test resources.
    projectFilesystem.createParentDirs(Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("bar.png"));
    fakeProjectFilesystem.touch(Paths.get("Base.lproj", "Bar.storyboard"));
    halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(fakeProjectFilesystem);
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("cflags", "-Wno-deprecated -Wno-conversion", "cxxflags", "-Wundeclared-selector -Wno-objc-designated-initializers"), "apple", ImmutableMap.of("force_dsym_mode_in_build_with_buck", "false"), "swift", ImmutableMap.of("version", "1.23"));
    BuckConfig config = FakeBuckConfig.builder().setSections(sections).build();
    cxxBuckConfig = new CxxBuckConfig(config);
    appleConfig = new AppleConfig(config);
    swiftBuckConfig = new SwiftBuckConfig(config);
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 2 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class AppleCxxPlatforms method buildWithExecutableChecker.

@VisibleForTesting
static AppleCxxPlatform buildWithExecutableChecker(ProjectFilesystem filesystem, AppleSdk targetSdk, String minVersion, String targetArchitecture, final AppleSdkPaths sdkPaths, BuckConfig buckConfig, AppleConfig appleConfig, ExecutableFinder executableFinder, Optional<ProcessExecutor> processExecutor, Optional<AppleToolchain> swiftToolChain) {
    AppleCxxPlatform.Builder platformBuilder = AppleCxxPlatform.builder();
    ImmutableList.Builder<Path> toolSearchPathsBuilder = ImmutableList.builder();
    // Search for tools from most specific to least specific.
    toolSearchPathsBuilder.add(sdkPaths.getSdkPath().resolve(USR_BIN)).add(sdkPaths.getSdkPath().resolve("Developer").resolve(USR_BIN)).add(sdkPaths.getPlatformPath().resolve("Developer").resolve(USR_BIN));
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        toolSearchPathsBuilder.add(toolchainPath.resolve(USR_BIN));
    }
    if (sdkPaths.getDeveloperPath().isPresent()) {
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve(USR_BIN));
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve("Tools"));
    }
    // TODO(bhamiltoncx): Add more and better cflags.
    ImmutableList.Builder<String> cflagsBuilder = ImmutableList.builder();
    cflagsBuilder.add("-isysroot", sdkPaths.getSdkPath().toString());
    cflagsBuilder.add("-iquote", filesystem.getRootPath().toString());
    cflagsBuilder.add("-arch", targetArchitecture);
    cflagsBuilder.add(targetSdk.getApplePlatform().getMinVersionFlagPrefix() + minVersion);
    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        cflagsBuilder.add("-fembed-bitcode");
    }
    ImmutableList.Builder<String> ldflagsBuilder = ImmutableList.builder();
    ldflagsBuilder.addAll(Linkers.iXlinker("-sdk_version", targetSdk.getVersion(), "-ObjC"));
    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        ldflagsBuilder.addAll(Linkers.iXlinker("-bitcode_verify", "-bitcode_hide_symbols", "-bitcode_symbol_map"));
    }
    // Populate Xcode version keys from Xcode's own Info.plist if available.
    Optional<String> xcodeBuildVersion = Optional.empty();
    Optional<Path> developerPath = sdkPaths.getDeveloperPath();
    if (developerPath.isPresent()) {
        Path xcodeBundlePath = developerPath.get().getParent();
        if (xcodeBundlePath != null) {
            File xcodeInfoPlistPath = xcodeBundlePath.resolve("Info.plist").toFile();
            try {
                NSDictionary parsedXcodeInfoPlist = (NSDictionary) PropertyListParser.parse(xcodeInfoPlistPath);
                NSObject xcodeVersionObject = parsedXcodeInfoPlist.objectForKey("DTXcode");
                if (xcodeVersionObject != null) {
                    Optional<String> xcodeVersion = Optional.of(xcodeVersionObject.toString());
                    platformBuilder.setXcodeVersion(xcodeVersion);
                }
            } catch (IOException e) {
                LOG.warn("Error reading Xcode's info plist %s; ignoring Xcode versions", xcodeInfoPlistPath);
            } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
                LOG.warn("Error in parsing %s; ignoring Xcode versions", xcodeInfoPlistPath);
            }
        }
        // different than the build number in the Info.plist, sigh.
        if (processExecutor.isPresent()) {
            xcodeBuildVersion = appleConfig.getXcodeBuildVersionSupplier(developerPath.get(), processExecutor.get()).get();
            platformBuilder.setXcodeBuildVersion(xcodeBuildVersion);
            LOG.debug("Xcode build version is: " + xcodeBuildVersion.orElse("<absent>"));
        }
    }
    ImmutableList.Builder<String> versions = ImmutableList.builder();
    versions.add(targetSdk.getVersion());
    ImmutableList<String> toolchainVersions = targetSdk.getToolchains().stream().map(AppleToolchain::getVersion).flatMap(Optionals::toStream).collect(MoreCollectors.toImmutableList());
    if (toolchainVersions.isEmpty()) {
        if (!xcodeBuildVersion.isPresent()) {
            throw new HumanReadableException("Failed to read toolchain versions and Xcode version.");
        }
        versions.add(xcodeBuildVersion.get());
    } else {
        versions.addAll(toolchainVersions);
    }
    String version = Joiner.on(':').join(versions.build());
    ImmutableList<Path> toolSearchPaths = toolSearchPathsBuilder.build();
    Tool clangPath = VersionedTool.of(getToolPath("clang", toolSearchPaths, executableFinder), "apple-clang", version);
    Tool clangXxPath = VersionedTool.of(getToolPath("clang++", toolSearchPaths, executableFinder), "apple-clang++", version);
    Tool ar = VersionedTool.of(getToolPath("ar", toolSearchPaths, executableFinder), "apple-ar", version);
    Tool ranlib = VersionedTool.builder().setPath(getToolPath("ranlib", toolSearchPaths, executableFinder)).setName("apple-ranlib").setVersion(version).build();
    Tool strip = VersionedTool.of(getToolPath("strip", toolSearchPaths, executableFinder), "apple-strip", version);
    Tool nm = VersionedTool.of(getToolPath("nm", toolSearchPaths, executableFinder), "apple-nm", version);
    Tool actool = VersionedTool.of(getToolPath("actool", toolSearchPaths, executableFinder), "apple-actool", version);
    Tool ibtool = VersionedTool.of(getToolPath("ibtool", toolSearchPaths, executableFinder), "apple-ibtool", version);
    Tool momc = VersionedTool.of(getToolPath("momc", toolSearchPaths, executableFinder), "apple-momc", version);
    Tool xctest = VersionedTool.of(getToolPath("xctest", toolSearchPaths, executableFinder), "apple-xctest", version);
    Tool dsymutil = VersionedTool.of(getToolPath("dsymutil", toolSearchPaths, executableFinder), "apple-dsymutil", version);
    Tool lipo = VersionedTool.of(getToolPath("lipo", toolSearchPaths, executableFinder), "apple-lipo", version);
    Tool lldb = VersionedTool.of(getToolPath("lldb", toolSearchPaths, executableFinder), "lldb", version);
    Optional<Path> stubBinaryPath = targetSdk.getApplePlatform().getStubBinaryPath().map(input -> sdkPaths.getSdkPath().resolve(input));
    CxxBuckConfig config = new CxxBuckConfig(buckConfig);
    UserFlavor targetFlavor = UserFlavor.of(Flavor.replaceInvalidCharacters(targetSdk.getName() + "-" + targetArchitecture), String.format("SDK: %s, architecture: %s", targetSdk.getName(), targetArchitecture));
    ImmutableBiMap.Builder<Path, Path> sanitizerPaths = ImmutableBiMap.builder();
    sanitizerPaths.put(sdkPaths.getSdkPath(), Paths.get("APPLE_SDKROOT"));
    sanitizerPaths.put(sdkPaths.getPlatformPath(), Paths.get("APPLE_PLATFORM_DIR"));
    if (sdkPaths.getDeveloperPath().isPresent()) {
        sanitizerPaths.put(sdkPaths.getDeveloperPath().get(), Paths.get("APPLE_DEVELOPER_DIR"));
    }
    DebugPathSanitizer compilerDebugPathSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.CLANG, filesystem);
    DebugPathSanitizer assemblerDebugPathSanitizer = new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build());
    ImmutableList<String> cflags = cflagsBuilder.build();
    ImmutableMap.Builder<String, String> macrosBuilder = ImmutableMap.builder();
    macrosBuilder.put("SDKROOT", sdkPaths.getSdkPath().toString());
    macrosBuilder.put("PLATFORM_DIR", sdkPaths.getPlatformPath().toString());
    macrosBuilder.put("CURRENT_ARCH", targetArchitecture);
    if (sdkPaths.getDeveloperPath().isPresent()) {
        macrosBuilder.put("DEVELOPER_DIR", sdkPaths.getDeveloperPath().get().toString());
    }
    ImmutableMap<String, String> macros = macrosBuilder.build();
    Optional<String> buildVersion = Optional.empty();
    Path platformVersionPlistPath = sdkPaths.getPlatformPath().resolve("version.plist");
    try (InputStream versionPlist = Files.newInputStream(platformVersionPlistPath)) {
        NSDictionary versionInfo = (NSDictionary) PropertyListParser.parse(versionPlist);
        if (versionInfo != null) {
            NSObject productBuildVersion = versionInfo.objectForKey("ProductBuildVersion");
            if (productBuildVersion != null) {
                buildVersion = Optional.of(productBuildVersion.toString());
            } else {
                LOG.warn("In %s, missing ProductBuildVersion. Build version will be unset for this platform.", platformVersionPlistPath);
            }
        } else {
            LOG.warn("Empty version plist in %s. Build version will be unset for this platform.", platformVersionPlistPath);
        }
    } catch (NoSuchFileException e) {
        LOG.warn("%s does not exist. Build version will be unset for this platform.", platformVersionPlistPath);
    } catch (PropertyListFormatException | SAXException | ParserConfigurationException | ParseException | IOException e) {
        // Some other error occurred, print the exception since it may contain error details.
        LOG.warn(e, "Failed to parse %s. Build version will be unset for this platform.", platformVersionPlistPath);
    }
    PreprocessorProvider aspp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    CompilerProvider as = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cpp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    CompilerProvider cc = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cxxpp = new PreprocessorProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
    CompilerProvider cxx = new CompilerProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
    ImmutableList.Builder<String> whitelistBuilder = ImmutableList.builder();
    whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getSdkPath().toString()) + "\\/.*");
    whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getPlatformPath().toString() + "/Developer/Library/Frameworks") + "\\/.*");
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        LOG.debug("Apple toolchain path: %s", toolchainPath);
        try {
            whitelistBuilder.add("^" + Pattern.quote(toolchainPath.toRealPath().toString()) + "\\/.*");
        } catch (IOException e) {
            LOG.warn(e, "Apple toolchain path could not be resolved: %s", toolchainPath);
        }
    }
    HeaderVerification headerVerification = config.getHeaderVerification().withPlatformWhitelist(whitelistBuilder.build());
    LOG.debug("Headers verification platform whitelist: %s", headerVerification.getPlatformWhitelist());
    CxxPlatform cxxPlatform = CxxPlatforms.build(targetFlavor, Platform.MACOS, config, as, aspp, cc, cxx, cpp, cxxpp, new DefaultLinkerProvider(LinkerProvider.Type.DARWIN, new ConstantToolProvider(clangXxPath)), ImmutableList.<String>builder().addAll(cflags).addAll(ldflagsBuilder.build()).build(), strip, new BsdArchiver(ar), ranlib, new PosixNmSymbolNameTool(nm), cflagsBuilder.build(), ImmutableList.of(), cflags, ImmutableList.of(), "dylib", "%s.dylib", "a", "o", compilerDebugPathSanitizer, assemblerDebugPathSanitizer, macros, Optional.empty(), headerVerification);
    ApplePlatform applePlatform = targetSdk.getApplePlatform();
    ImmutableList.Builder<Path> swiftOverrideSearchPathBuilder = ImmutableList.builder();
    AppleSdkPaths.Builder swiftSdkPathsBuilder = AppleSdkPaths.builder().from(sdkPaths);
    if (swiftToolChain.isPresent()) {
        swiftOverrideSearchPathBuilder.add(swiftToolChain.get().getPath().resolve(USR_BIN));
        swiftSdkPathsBuilder.setToolchainPaths(ImmutableList.of(swiftToolChain.get().getPath()));
    }
    Optional<SwiftPlatform> swiftPlatform = getSwiftPlatform(applePlatform.getName(), targetArchitecture + "-apple-" + applePlatform.getSwiftName().orElse(applePlatform.getName()) + minVersion, version, swiftSdkPathsBuilder.build(), swiftOverrideSearchPathBuilder.addAll(toolSearchPaths).build(), executableFinder);
    platformBuilder.setCxxPlatform(cxxPlatform).setSwiftPlatform(swiftPlatform).setAppleSdk(targetSdk).setAppleSdkPaths(sdkPaths).setMinVersion(minVersion).setBuildVersion(buildVersion).setActool(actool).setIbtool(ibtool).setMomc(momc).setCopySceneKitAssets(getOptionalTool("copySceneKitAssets", toolSearchPaths, executableFinder, version)).setXctest(xctest).setDsymutil(dsymutil).setLipo(lipo).setStubBinary(stubBinaryPath).setLldb(lldb).setCodesignAllocate(getOptionalTool("codesign_allocate", toolSearchPaths, executableFinder, version)).setCodesignProvider(appleConfig.getCodesignProvider());
    return platformBuilder.build();
}
Also used : NSDictionary(com.dd.plist.NSDictionary) NoSuchFileException(java.nio.file.NoSuchFileException) CompilerProvider(com.facebook.buck.cxx.CompilerProvider) SAXException(org.xml.sax.SAXException) DefaultLinkerProvider(com.facebook.buck.cxx.DefaultLinkerProvider) MungingDebugPathSanitizer(com.facebook.buck.cxx.MungingDebugPathSanitizer) DebugPathSanitizer(com.facebook.buck.cxx.DebugPathSanitizer) PrefixMapDebugPathSanitizer(com.facebook.buck.cxx.PrefixMapDebugPathSanitizer) VersionedTool(com.facebook.buck.rules.VersionedTool) PosixNmSymbolNameTool(com.facebook.buck.cxx.PosixNmSymbolNameTool) Tool(com.facebook.buck.rules.Tool) BsdArchiver(com.facebook.buck.cxx.BsdArchiver) MungingDebugPathSanitizer(com.facebook.buck.cxx.MungingDebugPathSanitizer) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyListFormatException(com.dd.plist.PropertyListFormatException) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) PreprocessorProvider(com.facebook.buck.cxx.PreprocessorProvider) File(java.io.File) PosixNmSymbolNameTool(com.facebook.buck.cxx.PosixNmSymbolNameTool) SwiftPlatform(com.facebook.buck.swift.SwiftPlatform) NSObject(com.dd.plist.NSObject) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) ImmutableList(com.google.common.collect.ImmutableList) HeaderVerification(com.facebook.buck.cxx.HeaderVerification) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Path(java.nio.file.Path) PrefixMapDebugPathSanitizer(com.facebook.buck.cxx.PrefixMapDebugPathSanitizer) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) InputStream(java.io.InputStream) IOException(java.io.IOException) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) HumanReadableException(com.facebook.buck.util.HumanReadableException) UserFlavor(com.facebook.buck.model.UserFlavor) ParseException(java.text.ParseException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class ProjectCommand method generateWorkspacesForTargets.

@VisibleForTesting
static ImmutableSet<BuildTarget> generateWorkspacesForTargets(final CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet, ImmutableSet<ProjectGenerator.Option> options, ImmutableList<String> buildWithBuckFlags, Optional<ImmutableSet<UnflavoredBuildTarget>> focusModules, Map<Path, ProjectGenerator> projectGenerators, boolean combinedProject, boolean buildWithBuck) throws IOException, InterruptedException {
    ImmutableSet<BuildTarget> targets;
    if (passedInTargetsSet.isEmpty()) {
        targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
    } else {
        targets = passedInTargetsSet;
    }
    LOG.debug("Generating workspace for config targets %s", targets);
    ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder();
    for (final BuildTarget inputTarget : targets) {
        TargetNode<?, ?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget);
        XcodeWorkspaceConfigDescription.Arg workspaceArgs;
        if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) {
            TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(inputNode);
            workspaceArgs = castedWorkspaceNode.getConstructorArg();
        } else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) {
            workspaceArgs = createImplicitWorkspaceArgs(inputNode);
        } else {
            throw new HumanReadableException("%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library", inputNode);
        }
        BuckConfig buckConfig = params.getBuckConfig();
        AppleConfig appleConfig = new AppleConfig(buckConfig);
        HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig);
        CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig);
        SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig);
        CxxPlatform defaultCxxPlatform = params.getCell().getKnownBuildRuleTypes().getDefaultCxxPlatforms();
        WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(params.getCell(), targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options, combinedProject, buildWithBuck, buildWithBuckFlags, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(), new ExecutableFinder(), params.getEnvironment(), params.getCell().getKnownBuildRuleTypes().getCxxPlatforms(), defaultCxxPlatform, params.getBuckConfig().getView(ParserConfig.class).getBuildFileName(), input -> ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph().getSubgraph(ImmutableSet.of(input))).getResolver(), params.getBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
        ListeningExecutorService executorService = params.getExecutors().get(ExecutorPool.PROJECT);
        Preconditions.checkNotNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool");
        generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService);
        ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets();
        LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace);
        requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);
    }
    return requiredBuildTargetsBuilder.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) WorkspaceAndProjectGenerator(com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableSet(com.google.common.collect.ImmutableSet) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class HaskellLibraryDescriptionTest method thinArchivesPropagatesDepFromObjects.

@Test
public void thinArchivesPropagatesDepFromObjects() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().setSections("[cxx]", "archive_contents=thin").build());
    HaskellLibraryBuilder builder = new HaskellLibraryBuilder(target, FakeHaskellConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORMS).setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("Test.hs")))).setLinkWhole(true);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    HaskellLibrary library = builder.build(resolver);
    // Test static dep type.
    NativeLinkableInput staticInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
    assertThat(FluentIterable.from(staticInput.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).transform(BuildRule::getBuildTarget).toList(), Matchers.hasItem(HaskellDescriptionUtils.getCompileBuildTarget(library.getBuildTarget(), CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Linker(com.facebook.buck.cxx.Linker) Matchers.not(org.hamcrest.Matchers.not) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Assert.assertThat(org.junit.Assert.assertThat) BuildRule(com.facebook.buck.rules.BuildRule) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Predicates(com.google.common.base.Predicates) SourceList(com.facebook.buck.rules.coercer.SourceList) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Arg(com.facebook.buck.rules.args.Arg) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) Preconditions(com.google.common.base.Preconditions) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 5 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class LuaBinaryDescriptionTest method platformDeps.

@Test
public void platformDeps() throws Exception {
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().build());
    CxxLibraryBuilder py2LibBuilder = new CxxLibraryBuilder(PYTHON2_DEP_TARGET);
    CxxLibraryBuilder py3LibBuilder = new CxxLibraryBuilder(PYTHON3_DEP_TARGET);
    CxxLibraryBuilder py2CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py2_library")).setSoname("libpy2.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxLibraryBuilder py3CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py3_library")).setSoname("libpy3.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxPythonExtensionBuilder cxxPythonExtensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, cxxBuckConfig, CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(py2CxxLibraryBuilder.getTarget())).add(Pattern.compile(PY3.getFlavor().toString()), ImmutableSortedSet.of(py3CxxLibraryBuilder.getTarget())).build());
    LuaBinaryBuilder luaBinaryBuilder = new LuaBinaryBuilder(new LuaBinaryDescription(FakeLuaConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS, pythonPlatforms), BuildTargetFactory.newInstance("//:binary")).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxPythonExtensionBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(py2LibBuilder.build(), py3LibBuilder.build(), py2CxxLibraryBuilder.build(), py3CxxLibraryBuilder.build(), cxxPythonExtensionBuilder.build(), luaBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    py2LibBuilder.build(resolver);
    py3LibBuilder.build(resolver);
    py2CxxLibraryBuilder.build(resolver);
    py3CxxLibraryBuilder.build(resolver);
    cxxPythonExtensionBuilder.build(resolver);
    LuaBinary luaBinary = luaBinaryBuilder.build(resolver);
    LuaPackageComponents components = luaBinary.getComponents();
    assertThat(components.getNativeLibraries().keySet(), Matchers.hasItem("libpy2.so"));
    assertThat(components.getNativeLibraries().keySet(), Matchers.not(Matchers.hasItem("libpy3.so")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) CxxPythonExtensionBuilder(com.facebook.buck.python.CxxPythonExtensionBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PythonPlatform(com.facebook.buck.python.PythonPlatform) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)27 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)19 Test (org.junit.Test)19 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)18 BuildTarget (com.facebook.buck.model.BuildTarget)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)9 TargetGraph (com.facebook.buck.rules.TargetGraph)8 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)6 NativeLinkTarget (com.facebook.buck.cxx.NativeLinkTarget)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)5 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)5 BuildRule (com.facebook.buck.rules.BuildRule)5 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)5 AppleConfig (com.facebook.buck.apple.AppleConfig)4