Search in sources :

Example 11 with CxxPlatform

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

the class SwiftCompile method makeCompileStep.

private SwiftCompileStep makeCompileStep(SourcePathResolver resolver) {
    ImmutableList.Builder<String> compilerCommand = ImmutableList.builder();
    compilerCommand.addAll(swiftCompiler.getCommandPrefix(resolver));
    if (bridgingHeader.isPresent()) {
        compilerCommand.add("-import-objc-header", resolver.getRelativePath(bridgingHeader.get()).toString());
    }
    final Function<FrameworkPath, Path> frameworkPathToSearchPath = CxxDescriptionEnhancer.frameworkPathToSearchPath(cxxPlatform, resolver);
    compilerCommand.addAll(frameworks.stream().map(frameworkPathToSearchPath::apply).flatMap(searchPath -> ImmutableSet.of("-F", searchPath.toString()).stream()).iterator());
    compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle("-Xcc"), getSwiftIncludeArgs(resolver)));
    compilerCommand.addAll(MoreIterables.zipAndConcat(Iterables.cycle(INCLUDE_FLAG), getDeps().stream().filter(SwiftCompile.class::isInstance).map(BuildRule::getSourcePathToOutput).map(input -> resolver.getAbsolutePath(input).toString()).collect(MoreCollectors.toImmutableSet())));
    Optional<Iterable<String>> configFlags = swiftBuckConfig.getFlags();
    if (configFlags.isPresent()) {
        compilerCommand.addAll(configFlags.get());
    }
    boolean hasMainEntry = srcs.stream().map(input -> resolver.getAbsolutePath(input).getFileName().toString()).anyMatch(SwiftDescriptions.SWIFT_MAIN_FILENAME::equalsIgnoreCase);
    compilerCommand.add("-c", enableObjcInterop ? "-enable-objc-interop" : "", hasMainEntry ? "" : "-parse-as-library", "-module-name", moduleName, "-emit-module", "-emit-module-path", modulePath.toString(), "-o", objectPath.toString(), "-emit-objc-header-path", headerPath.toString());
    compilerCommand.addAll(compilerFlags);
    for (SourcePath sourcePath : srcs) {
        compilerCommand.add(resolver.getRelativePath(sourcePath).toString());
    }
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    return new SwiftCompileStep(projectFilesystem.getRootPath(), ImmutableMap.of(), compilerCommand.build());
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) CxxHeaders(com.facebook.buck.cxx.CxxHeaders) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) LinkedHashSet(java.util.LinkedHashSet) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableContext(com.facebook.buck.rules.BuildableContext) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) Arg(com.facebook.buck.rules.args.Arg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) BuildContext(com.facebook.buck.rules.BuildContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MoreIterables(com.facebook.buck.util.MoreIterables) ImmutableList(com.google.common.collect.ImmutableList) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 12 with CxxPlatform

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

the class SwiftLibraryDescription method createBuildRule.

@Override
public <A extends SwiftLibraryDescription.Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    final BuildTarget buildTarget = params.getBuildTarget();
    // See if we're building a particular "type" and "platform" of this library, and if so, extract
    // them from the flavors attached to the build target.
    Optional<Map.Entry<Flavor, CxxPlatform>> platform = cxxPlatformFlavorDomain.getFlavorAndValue(buildTarget);
    final ImmutableSortedSet<Flavor> buildFlavors = buildTarget.getFlavors();
    ImmutableSortedSet<BuildRule> filteredExtraDeps = params.getExtraDeps().get().stream().filter(input -> !input.getBuildTarget().getUnflavoredBuildTarget().equals(buildTarget.getUnflavoredBuildTarget())).collect(MoreCollectors.toImmutableSortedSet());
    params = params.copyReplacingExtraDeps(Suppliers.ofInstance(filteredExtraDeps));
    if (!buildFlavors.contains(SWIFT_COMPANION_FLAVOR) && platform.isPresent()) {
        final CxxPlatform cxxPlatform = platform.get().getValue();
        Optional<SwiftPlatform> swiftPlatform = swiftPlatformFlavorDomain.getValue(buildTarget);
        if (!swiftPlatform.isPresent()) {
            throw new HumanReadableException("Platform %s is missing swift compiler", cxxPlatform);
        }
        // See if we're building a particular "type" and "platform" of this library, and if so,
        // extract them from the flavors attached to the build target.
        Optional<Map.Entry<Flavor, Type>> type = LIBRARY_TYPE.getFlavorAndValue(buildTarget);
        if (!buildFlavors.contains(SWIFT_COMPILE_FLAVOR) && type.isPresent()) {
            Set<Flavor> flavors = Sets.newHashSet(params.getBuildTarget().getFlavors());
            flavors.remove(type.get().getKey());
            BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
            if (flavoredLinkerMapMode.isPresent()) {
                target = target.withAppendedFlavors(flavoredLinkerMapMode.get().getFlavor());
            }
            BuildRuleParams typeParams = params.withBuildTarget(target);
            switch(type.get().getValue()) {
                case SHARED:
                    return createSharedLibraryBuildRule(typeParams, resolver, target, swiftPlatform.get(), cxxPlatform, args.soname, flavoredLinkerMapMode);
                case STATIC:
                case MACH_O_BUNDLE:
            }
            throw new RuntimeException("unhandled library build type");
        }
        // All swift-compile rules of swift-lib deps are required since we need their swiftmodules
        // during compilation.
        final Function<BuildRule, BuildRule> requireSwiftCompile = input -> {
            try {
                Preconditions.checkArgument(input instanceof SwiftLibrary);
                return ((SwiftLibrary) input).requireSwiftCompileRule(cxxPlatform.getFlavor());
            } catch (NoSuchBuildTargetException e) {
                throw new HumanReadableException(e, "Could not find SwiftCompile with target %s", buildTarget);
            }
        };
        params = params.copyAppendingExtraDeps(params.getDeps().stream().filter(SwiftLibrary.class::isInstance).map(requireSwiftCompile).collect(MoreCollectors.toImmutableSet()));
        params = params.copyAppendingExtraDeps(params.getDeps().stream().filter(CxxLibrary.class::isInstance).map(input -> {
            BuildTarget companionTarget = input.getBuildTarget().withAppendedFlavors(SWIFT_COMPANION_FLAVOR);
            return resolver.getRuleOptional(companionTarget).map(requireSwiftCompile);
        }).filter(Optional::isPresent).map(Optional::get).collect(MoreCollectors.toImmutableSortedSet()));
        return new SwiftCompile(cxxPlatform, swiftBuckConfig, params, swiftPlatform.get().getSwift(), args.frameworks, args.moduleName.orElse(buildTarget.getShortName()), BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s"), args.srcs, args.compilerFlags, args.enableObjcInterop, args.bridgingHeader);
    }
    // Otherwise, we return the generic placeholder of this library.
    params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    return new SwiftLibrary(params, resolver, ImmutableSet.of(), swiftPlatformFlavorDomain, args.frameworks, args.libraries, args.supportedPlatformsRegex, args.preferredLinkage.orElse(NativeLinkable.Linkage.ANY));
}
Also used : CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Linker(com.facebook.buck.cxx.Linker) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) Function(java.util.function.Function) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomain(com.facebook.buck.model.FlavorDomain) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxLinkableEnhancer(com.facebook.buck.cxx.CxxLinkableEnhancer) ImmutableSet(com.google.common.collect.ImmutableSet) FlavorConvertible(com.facebook.buck.model.FlavorConvertible) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Sets(com.google.common.collect.Sets) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) BuildTargets(com.facebook.buck.model.BuildTargets) Description(com.facebook.buck.rules.Description) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) Optional(java.util.Optional) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule)

Example 13 with CxxPlatform

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

the class AppleCxxPlatformsTest method watchOSSdkPathsBuiltFromDirectory.

@Test
public void watchOSSdkPathsBuiltFromDirectory() throws Exception {
    AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/WatchOS.platform")).setSdkPath(Paths.get("Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.0.sdk")).build();
    AppleToolchain toolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setVersion("1").build();
    AppleSdk targetSdk = AppleSdk.builder().setApplePlatform(ApplePlatform.WATCHOS).setName("watchos2.0").setVersion("2.0").setToolchains(ImmutableList.of(toolchain)).build();
    ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/ar")).build();
    AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "2.0", "armv7k", appleSdkPaths, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new FakeExecutableFinder(paths), Optional.empty(), Optional.empty());
    CxxPlatform cxxPlatform = appleCxxPlatform.getCxxPlatform();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    assertEquals(ImmutableList.of("usr/bin/actool"), appleCxxPlatform.getActool().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/ibtool"), appleCxxPlatform.getIbtool().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/lldb"), appleCxxPlatform.getLldb().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil"), appleCxxPlatform.getDsymutil().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/xctest"), appleCxxPlatform.getXctest().getCommandPrefix(resolver));
    assertEquals(InternalFlavor.of("watchos2.0-armv7k"), cxxPlatform.getFlavor());
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang").toString(), cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertThat(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver)).addAll(cxxPlatform.getCflags()).build(), hasConsecutiveItems("-isysroot", Paths.get("Platforms/WatchOS.platform/Developer/SDKs/WatchOS2.0.sdk").toString()));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-arch", "armv7k"));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-mwatchos-version-min=2.0"));
    assertThat(cxxPlatform.getLdflags(), hasConsecutiveItems("-Wl,-sdk_version", "-Wl,2.0"));
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++").toString(), cxxPlatform.getCxx().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertEquals(Paths.get("Platforms/WatchOS.platform/Developer/usr/bin/ar").toString(), cxxPlatform.getAr().getCommandPrefix(resolver).get(0));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 14 with CxxPlatform

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

the class AppleCxxPlatformsTest method appleTVOSSdkPathsBuiltFromDirectory.

@Test
public void appleTVOSSdkPathsBuiltFromDirectory() throws Exception {
    AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/AppleTVOS.platform")).setSdkPath(Paths.get("Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk")).build();
    AppleToolchain toolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setVersion("1").build();
    AppleSdk targetSdk = AppleSdk.builder().setApplePlatform(ApplePlatform.APPLETVOS).setName("appletvos9.1").setVersion("9.1").setToolchains(ImmutableList.of(toolchain)).build();
    ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/ar")).build();
    AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "9.1", "arm64", appleSdkPaths, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new FakeExecutableFinder(paths), Optional.empty(), Optional.empty());
    CxxPlatform cxxPlatform = appleCxxPlatform.getCxxPlatform();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    assertEquals(ImmutableList.of("usr/bin/actool"), appleCxxPlatform.getActool().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/ibtool"), appleCxxPlatform.getIbtool().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/lldb"), appleCxxPlatform.getLldb().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil"), appleCxxPlatform.getDsymutil().getCommandPrefix(resolver));
    assertEquals(ImmutableList.of("usr/bin/xctest"), appleCxxPlatform.getXctest().getCommandPrefix(resolver));
    assertEquals(InternalFlavor.of("appletvos9.1-arm64"), cxxPlatform.getFlavor());
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang").toString(), cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertThat(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(ruleResolver).getCommandPrefix(resolver)).addAll(cxxPlatform.getCflags()).build(), hasConsecutiveItems("-isysroot", Paths.get("Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk").toString()));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-arch", "arm64"));
    assertThat(cxxPlatform.getCflags(), hasConsecutiveItems("-mtvos-version-min=9.1"));
    assertThat(cxxPlatform.getLdflags(), hasConsecutiveItems("-Wl,-sdk_version", "-Wl,9.1"));
    assertEquals(Paths.get("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++").toString(), cxxPlatform.getCxx().resolve(ruleResolver).getCommandPrefix(resolver).get(0));
    assertEquals(Paths.get("Platforms/AppleTVOS.platform/Developer/usr/bin/ar").toString(), cxxPlatform.getAr().getCommandPrefix(resolver).get(0));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 15 with CxxPlatform

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

the class AppleCxxPlatformsTest method watchOSSimulatorPlatformSetsLinkerFlags.

@Test
public void watchOSSimulatorPlatformSetsLinkerFlags() throws Exception {
    AppleSdkPaths appleSdkPaths = AppleSdkPaths.builder().setDeveloperPath(Paths.get(".")).addToolchainPaths(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setPlatformPath(Paths.get("Platforms/WatchSimulator.platform")).setSdkPath(Paths.get("Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator2.0.sdk")).build();
    ImmutableSet<Path> paths = ImmutableSet.<Path>builder().addAll(COMMON_KNOWN_PATHS).add(Paths.get("Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool")).add(Paths.get("Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar")).build();
    AppleToolchain toolchain = AppleToolchain.builder().setIdentifier("com.apple.dt.XcodeDefault").setPath(Paths.get("Toolchains/XcodeDefault.xctoolchain")).setVersion("1").build();
    AppleSdk targetSdk = AppleSdk.builder().setApplePlatform(ApplePlatform.WATCHSIMULATOR).setName("watchsimulator2.0").setVersion("2.0").setToolchains(ImmutableList.of(toolchain)).build();
    AppleCxxPlatform appleCxxPlatform = AppleCxxPlatforms.buildWithExecutableChecker(projectFilesystem, targetSdk, "2.0", "armv7k", appleSdkPaths, FakeBuckConfig.builder().build(), new FakeAppleConfig(), new FakeExecutableFinder(paths), Optional.empty(), Optional.empty());
    CxxPlatform cxxPlatform = appleCxxPlatform.getCxxPlatform();
    assertThat(cxxPlatform.getCflags(), hasItem("-mwatchos-simulator-version-min=2.0"));
    assertThat(cxxPlatform.getLdflags(), hasItem("-mwatchos-simulator-version-min=2.0"));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) Test(org.junit.Test)

Aggregations

CxxPlatform (com.facebook.buck.cxx.CxxPlatform)52 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)24 Path (java.nio.file.Path)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 BuildTarget (com.facebook.buck.model.BuildTarget)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)19 SourcePath (com.facebook.buck.rules.SourcePath)17 BuildRule (com.facebook.buck.rules.BuildRule)14 ImmutableList (com.google.common.collect.ImmutableList)11 HumanReadableException (com.facebook.buck.util.HumanReadableException)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 FakeExecutableFinder (com.facebook.buck.io.FakeExecutableFinder)8 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)8 Optional (java.util.Optional)8 Flavor (com.facebook.buck.model.Flavor)7 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)7 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)6 Linker (com.facebook.buck.cxx.Linker)6