Search in sources :

Example 31 with Flavor

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

the class AndroidBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    try (SimplePerfEvent.Scope ignored = SimplePerfEvent.scope(Optional.ofNullable(resolver.getEventBus()), PerfEventId.of("AndroidBinaryDescription"), "target", params.getBuildTarget().toString())) {
        ResourceCompressionMode compressionMode = getCompressionMode(args);
        BuildTarget target = params.getBuildTarget();
        boolean isFlavored = target.isFlavored();
        if (isFlavored) {
            if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR) && !compressionMode.isStoreStringsAsAssets()) {
                throw new HumanReadableException("'package_string_assets' flavor does not exist for %s.", target.getUnflavoredBuildTarget());
            }
            params = params.withBuildTarget(BuildTarget.of(target.getUnflavoredBuildTarget()));
        }
        BuildRule keystore = resolver.getRule(args.keystore);
        if (!(keystore instanceof Keystore)) {
            throw new HumanReadableException("In %s, keystore='%s' must be a keystore() but was %s().", params.getBuildTarget(), keystore.getFullyQualifiedName(), keystore.getType());
        }
        APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, target, Optional.of(args.applicationModuleTargets));
        ProGuardObfuscateStep.SdkProguardType androidSdkProguardConfig = args.androidSdkProguardConfig.orElse(ProGuardObfuscateStep.SdkProguardType.DEFAULT);
        // was not specified, and allow the old form to override the default.
        if (args.useAndroidProguardConfigWithOptimizations.isPresent()) {
            Preconditions.checkArgument(!args.androidSdkProguardConfig.isPresent(), "The deprecated use_android_proguard_config_with_optimizations parameter" + " cannot be used with android_sdk_proguard_config.");
            LOG.error("Target %s specified use_android_proguard_config_with_optimizations, " + "which is deprecated. Use android_sdk_proguard_config.", params.getBuildTarget());
            androidSdkProguardConfig = args.useAndroidProguardConfigWithOptimizations.orElse(false) ? ProGuardObfuscateStep.SdkProguardType.OPTIMIZED : ProGuardObfuscateStep.SdkProguardType.DEFAULT;
        }
        EnumSet<ExopackageMode> exopackageModes = EnumSet.noneOf(ExopackageMode.class);
        if (!args.exopackageModes.isEmpty()) {
            exopackageModes = EnumSet.copyOf(args.exopackageModes);
        } else if (args.exopackage.orElse(false)) {
            LOG.error("Target %s specified exopackage=True, which is deprecated. Use exopackage_modes.", params.getBuildTarget());
            exopackageModes = EnumSet.of(ExopackageMode.SECONDARY_DEX);
        }
        DexSplitMode dexSplitMode = createDexSplitMode(args, exopackageModes);
        PackageType packageType = getPackageType(args);
        boolean shouldPreDex = !args.disablePreDex && PackageType.DEBUG.equals(packageType) && !args.preprocessJavaClassesBash.isPresent();
        ResourceFilter resourceFilter = new ResourceFilter(args.resourceFilter);
        AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(params, resolver, compressionMode, resourceFilter, args.getBannedDuplicateResourceTypes(), args.resourceUnionPackage, addFallbackLocales(args.locales), args.manifest, packageType, ImmutableSet.copyOf(args.cpuFilters), args.buildStringSourceMap, shouldPreDex, AndroidBinary.getPrimaryDexPath(params.getBuildTarget(), params.getProjectFilesystem()), dexSplitMode, ImmutableSet.copyOf(args.noDx.orElse(ImmutableSet.of())), /* resourcesToExclude */
        ImmutableSet.of(), args.skipCrunchPngs, args.includesVectorDrawables, javacOptions, exopackageModes, args.buildConfigValues, args.buildConfigValuesFile, Optional.empty(), args.trimResourceIds, args.keepResourcePattern, nativePlatforms, Optional.of(args.nativeLibraryMergeMap), args.nativeLibraryMergeGlue, args.nativeLibraryMergeCodeGenerator, args.enableRelinker ? RelinkerMode.ENABLED : RelinkerMode.DISABLED, dxExecutorService, args.manifestEntries, cxxBuckConfig, apkModuleGraph, dxConfig);
        AndroidGraphEnhancementResult result = graphEnhancer.createAdditionalBuildables();
        if (target.getFlavors().contains(PACKAGE_STRING_ASSETS_FLAVOR)) {
            Optional<PackageStringAssets> packageStringAssets = result.getPackageStringAssets();
            Preconditions.checkState(packageStringAssets.isPresent());
            return packageStringAssets.get();
        }
        // Build rules added to "no_dx" are only hints, not hard dependencies. Therefore, although a
        // target may be mentioned in that parameter, it may not be present as a build rule.
        ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.naturalOrder();
        for (BuildTarget noDxTarget : args.noDx.orElse(ImmutableSet.of())) {
            Optional<BuildRule> ruleOptional = resolver.getRuleOptional(noDxTarget);
            if (ruleOptional.isPresent()) {
                builder.add(ruleOptional.get());
            } else {
                LOG.info("%s: no_dx target not a dependency: %s", target, noDxTarget);
            }
        }
        ImmutableSortedSet<BuildRule> buildRulesToExcludeFromDex = builder.build();
        ImmutableSortedSet<JavaLibrary> rulesToExcludeFromDex = RichStream.from(buildRulesToExcludeFromDex).filter(JavaLibrary.class).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()));
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        Optional<RedexOptions> redexOptions = getRedexOptions(params, resolver, args);
        ImmutableSortedSet<BuildRule> redexExtraDeps = redexOptions.map(a -> a.getRedexExtraArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()))).orElse(ImmutableSortedSet.of());
        return new AndroidBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(result.getFinalDeps())).copyAppendingExtraDeps(ruleFinder.filterBuildRuleInputs(result.getPackageableCollection().getProguardConfigs())).copyAppendingExtraDeps(rulesToExcludeFromDex).copyAppendingExtraDeps(redexExtraDeps), ruleFinder, proGuardConfig.getProguardJarOverride(), proGuardConfig.getProguardMaxHeapSize(), Optional.of(args.proguardJvmArgs), proGuardConfig.getProguardAgentPath(), (Keystore) keystore, packageType, dexSplitMode, args.noDx.orElse(ImmutableSet.of()), androidSdkProguardConfig, args.optimizationPasses, args.proguardConfig, args.skipProguard, redexOptions, compressionMode, args.cpuFilters, resourceFilter, exopackageModes, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver), args.preprocessJavaClassesBash, rulesToExcludeFromDex, result, args.reorderClassesIntraDex, args.dexReorderToolFile, args.dexReorderDataDumpFile, args.xzCompressionLevel, dxExecutorService, args.packageAssetLibraries, args.compressAssetLibraries, args.manifestEntries, javaOptions.getJavaRuntimeLauncher(), dxConfig.getDxMaxHeapSize());
    }
}
Also used : PerfEventId(com.facebook.buck.event.PerfEventId) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) RichStream(com.facebook.buck.util.RichStream) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HasTests(com.facebook.buck.model.HasTests) ExopackageMode(com.facebook.buck.android.AndroidBinary.ExopackageMode) BuckConfig(com.facebook.buck.cli.BuckConfig) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) DexSplitStrategy(com.facebook.buck.dalvik.ZipSplitter.DexSplitStrategy) Keystore(com.facebook.buck.jvm.java.Keystore) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) MacroException(com.facebook.buck.model.MacroException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Collectors(java.util.stream.Collectors) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) List(java.util.List) PackageType(com.facebook.buck.android.AndroidBinary.PackageType) RelinkerMode(com.facebook.buck.android.AndroidBinary.RelinkerMode) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ResourceCompressionMode(com.facebook.buck.android.ResourcesFilter.ResourceCompressionMode) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) JavaOptions(com.facebook.buck.jvm.java.JavaOptions) SourcePath(com.facebook.buck.rules.SourcePath) Flavored(com.facebook.buck.model.Flavored) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields) Suppliers(com.google.common.base.Suppliers) RedexOptions(com.facebook.buck.android.redex.RedexOptions) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) MacroArg(com.facebook.buck.rules.args.MacroArg) ManifestEntries(com.facebook.buck.rules.coercer.ManifestEntries) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) HumanReadableException(com.facebook.buck.util.HumanReadableException) PACKAGE_STRING_ASSETS_FLAVOR(com.facebook.buck.android.AndroidBinaryGraphEnhancer.PACKAGE_STRING_ASSETS_FLAVOR) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Ordering(com.google.common.collect.Ordering) TargetCpuType(com.facebook.buck.android.NdkCxxPlatforms.TargetCpuType) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) RedexOptions(com.facebook.buck.android.redex.RedexOptions) Keystore(com.facebook.buck.jvm.java.Keystore) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) BuildTarget(com.facebook.buck.model.BuildTarget) PackageType(com.facebook.buck.android.AndroidBinary.PackageType) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ResourceCompressionMode(com.facebook.buck.android.ResourcesFilter.ResourceCompressionMode) ExopackageMode(com.facebook.buck.android.AndroidBinary.ExopackageMode) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 32 with Flavor

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

the class InstallCommand method getInstallHelperTargets.

private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
    for (int index = 0; index < getArguments().size(); index++) {
        // TODO(ryu2): Cache argument parsing
        TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
        BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
        TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
        if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
            for (Flavor flavor : node.getBuildTarget().getFlavors()) {
                if (ApplePlatform.needsInstallHelper(flavor.getName())) {
                    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
                    Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
                    Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
                }
            }
        }
    }
    return installHelperTargets.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) AppleSimulatorDiscovery(com.facebook.buck.apple.simulator.AppleSimulatorDiscovery) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AdbOptions(com.facebook.buck.step.AdbOptions) AdbHelper(com.facebook.buck.android.AdbHelper) InstallEvent(com.facebook.buck.event.InstallEvent) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AppleConfig(com.facebook.buck.apple.AppleConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) ApplePlatform(com.facebook.buck.apple.ApplePlatform) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Locale(java.util.Locale) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController) Path(java.nio.file.Path) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) BuildTargetException(com.facebook.buck.model.BuildTargetException) Option(org.kohsuke.args4j.Option) AppleInfoPlistParsing(com.facebook.buck.apple.AppleInfoPlistParsing) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) List(java.util.List) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) UninstallOptions(com.facebook.buck.cli.UninstallCommand.UninstallOptions) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Assertions(com.facebook.infer.annotation.Assertions) Build(com.facebook.buck.command.Build) MoreExceptions(com.facebook.buck.util.MoreExceptions) SourcePath(com.facebook.buck.rules.SourcePath) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Lists(com.google.common.collect.Lists) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) TargetNode(com.facebook.buck.rules.TargetNode) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) AppleBundle(com.facebook.buck.apple.AppleBundle) HasInstallableApk(com.facebook.buck.android.HasInstallableApk) SpeculativeParsing(com.facebook.buck.parser.SpeculativeParsing) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 33 with Flavor

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

the class KotlinLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    BuildTarget target = params.getBuildTarget();
    // creating the action graph from the target graph.
    if (CalculateAbi.isAbiTarget(target)) {
        BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    ImmutableSortedSet<Flavor> flavors = target.getFlavors();
    BuildRuleParams paramsWithMavenFlavor = null;
    if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
        paramsWithMavenFlavor = params;
        // Maven rules will depend upon their vanilla versions, so the latter have to be constructed
        // without the maven flavor to prevent output-path conflict
        params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
    }
    if (flavors.contains(JavaLibrary.SRC_JAR)) {
        args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
        if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
            return new JavaSourceJar(params, args.srcs, args.mavenCoords);
        } else {
            return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
        }
    }
    JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
    BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
    DefaultKotlinLibrary defaultKotlinLibrary = new DefaultKotlinLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), Optional.empty(), Optional.empty(), ImmutableList.of(), exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), false, ImmutableSet.of(), new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
    if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
        return defaultKotlinLibrary;
    } else {
        return MavenUberJar.create(defaultKotlinLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) CalculateAbi(com.facebook.buck.jvm.java.CalculateAbi) JavaLibraryRules(com.facebook.buck.jvm.java.JavaLibraryRules) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) JavacOptionsFactory(com.facebook.buck.jvm.java.JavacOptionsFactory) Flavored(com.facebook.buck.model.Flavored) BuildRule(com.facebook.buck.rules.BuildRule) JavaSourceJar(com.facebook.buck.jvm.java.JavaSourceJar) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ResourceValidator.validateResources(com.facebook.buck.jvm.common.ResourceValidator.validateResources) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildRules(com.facebook.buck.rules.BuildRules) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) AetherUtil(com.facebook.buck.maven.AetherUtil) TargetGraph(com.facebook.buck.rules.TargetGraph) MavenUberJar(com.facebook.buck.jvm.java.MavenUberJar) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Description(com.facebook.buck.rules.Description) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Flavor(com.facebook.buck.model.Flavor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) JavaSourceJar(com.facebook.buck.jvm.java.JavaSourceJar)

Example 34 with Flavor

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

the class AbstractFlavorSearchTargetNodeFinder method getBaseTargetFlavorMap.

// Build the flavor map, which maps all unflavored targets to the flavors they have in the
// graph.  We sort the list of flavor sets from largest to smallest, so that look ups pick the
// more flavored sets first.
@Value.Derived
ImmutableMap<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> getBaseTargetFlavorMap() {
    Map<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> flavorMapRawBuilder = new LinkedHashMap<>();
    for (Map.Entry<BuildTarget, TargetNode<?, ?>> ent : getBaseTargetIndex().entrySet()) {
        BuildTarget baseTarget = ent.getKey();
        UnflavoredBuildTarget unflavoredTarget = baseTarget.getUnflavoredBuildTarget();
        if (!flavorMapRawBuilder.containsKey(unflavoredTarget)) {
            flavorMapRawBuilder.put(unflavoredTarget, new ArrayList<>());
        }
        flavorMapRawBuilder.get(unflavoredTarget).add(baseTarget.getFlavors());
    }
    ImmutableMap.Builder<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> flavorMapBuilder = ImmutableMap.builder();
    for (Map.Entry<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> ent : flavorMapRawBuilder.entrySet()) {
        ent.getValue().sort((o1, o2) -> Integer.compare(o2.size(), o1.size()));
        flavorMapBuilder.put(ent.getKey(), ImmutableSet.copyOf(ent.getValue()));
    }
    return flavorMapBuilder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 35 with Flavor

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

the class ProjectGenerator method getBuildWithBuckShellScript.

private String getBuildWithBuckShellScript(TargetNode<?, ?> targetNode) {
    ST template;
    try {
        template = new ST(Resources.toString(Resources.getResource(ProjectGenerator.class, BUILD_WITH_BUCK_TEMPLATE), Charsets.UTF_8));
    } catch (IOException e) {
        throw new RuntimeException("There was an error loading '" + BUILD_WITH_BUCK_TEMPLATE + "' template", e);
    }
    String buildFlags = getBuildFlags();
    String escapedBuildTarget = Escaper.escapeAsBashString(targetNode.getBuildTarget().getFullyQualifiedName());
    Optional<String> productName = getProductNameForTargetNode(targetNode);
    String binaryName = AppleBundle.getBinaryName(targetNode.getBuildTarget(), productName);
    Path bundleDestination = getScratchPathForAppBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
    Path dsymDestination = getScratchPathForDsymBundle(projectFilesystem, targetNode.getBuildTarget(), binaryName);
    Path resolvedBundleDestination = projectFilesystem.resolve(bundleDestination);
    Path resolvedDsymDestination = projectFilesystem.resolve(dsymDestination);
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(targetNode.getBuildTarget().getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    String oldCompDir = cxxPlatform.getCompilerDebugPathSanitizer().getCompilationDirectory();
    // Use the hostname for padding instead of the directory, this way the directory matches without
    // having to resolve it.
    String dsymPaddedCompDirWithHost = Strings.padStart(":" + projectFilesystem.getRootPath().toString(), oldCompDir.length(), 'f');
    template.add("path_to_build_with_buck_py", getBuildWithBuckPythonScriptPath(projectFilesystem));
    template.add("path_to_fix_uuid_script", getFixUUIDScriptPath(projectFilesystem));
    template.add("repo_root", projectFilesystem.getRootPath());
    template.add("path_to_buck", getPathToBuck(executableFinder, environment));
    template.add("build_flags", buildFlags);
    template.add("escaped_build_target", escapedBuildTarget);
    template.add("buck_dwarf_flavor", (appleConfig.forceDsymModeInBuildWithBuck() ? AppleDebugFormat.DWARF_AND_DSYM : AppleDebugFormat.DWARF).getFlavor().getName());
    template.add("buck_dsym_flavor", AppleDebugFormat.DWARF_AND_DSYM.getFlavor().getName());
    template.add("binary_name", binaryName);
    template.add("comp_dir", oldCompDir);
    template.add("new_comp_dir", projectFilesystem.getRootPath().toString());
    template.add("padded_source_dir", dsymPaddedCompDirWithHost);
    template.add("resolved_bundle_destination", resolvedBundleDestination);
    template.add("resolved_bundle_destination_parent", resolvedBundleDestination.getParent());
    template.add("resolved_dsym_destination", resolvedDsymDestination);
    template.add("force_dsym", appleConfig.forceDsymModeInBuildWithBuck() ? "true" : "false");
    return template.render();
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) ST(org.stringtemplate.v4.ST) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) IOException(java.io.IOException) NSString(com.dd.plist.NSString) Flavor(com.facebook.buck.model.Flavor)

Aggregations

Flavor (com.facebook.buck.model.Flavor)60 InternalFlavor (com.facebook.buck.model.InternalFlavor)42 BuildTarget (com.facebook.buck.model.BuildTarget)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)17 Test (org.junit.Test)17 SourcePath (com.facebook.buck.rules.SourcePath)14 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 BuildRule (com.facebook.buck.rules.BuildRule)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)12 Path (java.nio.file.Path)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)11 Optional (java.util.Optional)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)9 Map (java.util.Map)9 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)7 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)6