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);
}
Aggregations