Search in sources :

Example 1 with FlavorDomainException

use of com.facebook.buck.model.FlavorDomainException in project buck by facebook.

the class AppleTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    AppleDebugFormat debugFormat = AppleDebugFormat.FLAVOR_DOMAIN.getValue(params.getBuildTarget()).orElse(appleConfig.getDefaultDebugInfoFormatForTests());
    if (params.getBuildTarget().getFlavors().contains(debugFormat.getFlavor())) {
        params = params.withoutFlavor(debugFormat.getFlavor());
    }
    boolean createBundle = Sets.intersection(params.getBuildTarget().getFlavors(), AUXILIARY_LIBRARY_FLAVORS).isEmpty();
    // Flavors pertaining to the library targets that are generated.
    Sets.SetView<Flavor> libraryFlavors = Sets.difference(params.getBuildTarget().getFlavors(), AUXILIARY_LIBRARY_FLAVORS);
    boolean addDefaultPlatform = libraryFlavors.isEmpty();
    ImmutableSet.Builder<Flavor> extraFlavorsBuilder = ImmutableSet.builder();
    if (createBundle) {
        extraFlavorsBuilder.add(LIBRARY_FLAVOR, CxxDescriptionEnhancer.MACH_O_BUNDLE_FLAVOR);
    }
    extraFlavorsBuilder.add(debugFormat.getFlavor());
    if (addDefaultPlatform) {
        extraFlavorsBuilder.add(defaultCxxPlatform.getFlavor());
    }
    Optional<MultiarchFileInfo> multiarchFileInfo = MultiarchFileInfos.create(appleCxxPlatformFlavorDomain, params.getBuildTarget());
    AppleCxxPlatform appleCxxPlatform;
    ImmutableList<CxxPlatform> cxxPlatforms;
    if (multiarchFileInfo.isPresent()) {
        ImmutableList.Builder<CxxPlatform> cxxPlatformBuilder = ImmutableList.builder();
        for (BuildTarget thinTarget : multiarchFileInfo.get().getThinTargets()) {
            cxxPlatformBuilder.add(cxxPlatformFlavorDomain.getValue(thinTarget).get());
        }
        cxxPlatforms = cxxPlatformBuilder.build();
        appleCxxPlatform = multiarchFileInfo.get().getRepresentativePlatform();
    } else {
        CxxPlatform cxxPlatform = cxxPlatformFlavorDomain.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
        cxxPlatforms = ImmutableList.of(cxxPlatform);
        try {
            appleCxxPlatform = appleCxxPlatformFlavorDomain.getValue(cxxPlatform.getFlavor());
        } catch (FlavorDomainException e) {
            throw new HumanReadableException(e, "%s: Apple test requires an Apple platform, found '%s'", params.getBuildTarget(), cxxPlatform.getFlavor().getName());
        }
    }
    Optional<TestHostInfo> testHostInfo;
    if (args.testHostApp.isPresent()) {
        testHostInfo = Optional.of(createTestHostInfo(params, resolver, args.testHostApp.get(), debugFormat, libraryFlavors, cxxPlatforms));
    } else {
        testHostInfo = Optional.empty();
    }
    BuildTarget libraryTarget = params.getBuildTarget().withAppendedFlavors(extraFlavorsBuilder.build()).withAppendedFlavors(debugFormat.getFlavor()).withAppendedFlavors(LinkerMapMode.NO_LINKER_MAP.getFlavor());
    BuildRule library = createTestLibraryRule(targetGraph, params, resolver, args, testHostInfo.map(TestHostInfo::getTestHostAppBinarySourcePath), testHostInfo.map(TestHostInfo::getBlacklist).orElse(ImmutableSet.of()), libraryTarget);
    if (!createBundle || SwiftLibraryDescription.isSwiftTarget(libraryTarget)) {
        return library;
    }
    String platformName = appleCxxPlatform.getAppleSdk().getApplePlatform().getName();
    AppleBundle bundle = AppleDescriptions.createAppleBundle(cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatformFlavorDomain, targetGraph, params.withBuildTarget(params.getBuildTarget().withAppendedFlavors(BUNDLE_FLAVOR, debugFormat.getFlavor(), LinkerMapMode.NO_LINKER_MAP.getFlavor(), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(library).addAll(params.getDeclaredDeps().get()).build()), params.getExtraDeps()), resolver, codeSignIdentityStore, provisioningProfileStore, library.getBuildTarget(), args.getExtension(), Optional.empty(), args.infoPlist, args.infoPlistSubstitutions, args.deps, args.tests, debugFormat, appleConfig.useDryRunCodeSigning(), appleConfig.cacheBundlesAndPackages());
    resolver.addToIndex(bundle);
    Optional<SourcePath> xctool = getXctool(params, resolver);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    return new AppleTest(xctool, appleConfig.getXctoolStutterTimeoutMs(), appleCxxPlatform.getXctest(), appleConfig.getXctestPlatformNames().contains(platformName), platformName, appleConfig.getXctoolDefaultDestinationSpecifier(), Optional.of(args.destinationSpecifier), params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(bundle)), Suppliers.ofInstance(ImmutableSortedSet.of())), bundle, testHostInfo.map(TestHostInfo::getTestHostApp), args.contacts, args.labels, args.getRunTestSeparately(), xcodeDeveloperDirectorySupplier, appleConfig.getTestLogDirectoryEnvironmentVariable(), appleConfig.getTestLogLevelEnvironmentVariable(), appleConfig.getTestLogLevel(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.isUiTest(), args.snapshotReferenceImagesPath, ruleFinder);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) Sets(com.google.common.collect.Sets) BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomainException(com.facebook.buck.model.FlavorDomainException) Optional(java.util.Optional) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Aggregations

CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 Flavor (com.facebook.buck.model.Flavor)1 FlavorDomainException (com.facebook.buck.model.FlavorDomainException)1 InternalFlavor (com.facebook.buck.model.InternalFlavor)1 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)1 BuildRule (com.facebook.buck.rules.BuildRule)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Optional (java.util.Optional)1