Search in sources :

Example 31 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project gradle by gradle.

the class SkipCachedTaskExecuter method resolveProperties.

private static SortedSet<ResolvedTaskOutputFilePropertySpec> resolveProperties(ImmutableSortedSet<? extends TaskOutputFilePropertySpec> properties) {
    ImmutableSortedSet.Builder<ResolvedTaskOutputFilePropertySpec> builder = ImmutableSortedSet.naturalOrder();
    for (TaskOutputFilePropertySpec property : properties) {
        // At this point we assume that the task only has cacheable properties,
        // otherwise caching would have been disabled by now
        CacheableTaskOutputFilePropertySpec cacheableProperty = (CacheableTaskOutputFilePropertySpec) property;
        builder.add(new ResolvedTaskOutputFilePropertySpec(cacheableProperty.getPropertyName(), cacheableProperty.getOutputType(), cacheableProperty.getOutputFile()));
    }
    return builder.build();
}
Also used : CacheableTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec) ResolvedTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec) TaskOutputFilePropertySpec(org.gradle.api.internal.tasks.TaskOutputFilePropertySpec) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ResolvedTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec) CacheableTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec)

Example 32 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class AndroidAarDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams originalBuildRuleParams, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    UnflavoredBuildTarget originalBuildTarget = originalBuildRuleParams.getBuildTarget().checkUnflavored();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ImmutableList.Builder<BuildRule> aarExtraDepsBuilder = ImmutableList.<BuildRule>builder().addAll(originalBuildRuleParams.getExtraDeps().get());
    /* android_manifest */
    AndroidManifestDescription.Arg androidManifestArgs = androidManifestDescription.createUnpopulatedConstructorArg();
    androidManifestArgs.skeleton = args.manifestSkeleton;
    androidManifestArgs.deps = args.deps;
    BuildRuleParams androidManifestParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_MANIFEST_FLAVOR));
    AndroidManifest manifest = androidManifestDescription.createBuildRule(targetGraph, androidManifestParams, resolver, androidManifestArgs);
    aarExtraDepsBuilder.add(resolver.addToIndex(manifest));
    final APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph, originalBuildRuleParams.getBuildTarget(), Optional.empty());
    /* assemble dirs */
    AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildRuleParams.getBuildTarget(), /* buildTargetsToExcludeFromDex */
    ImmutableSet.of(), /* resourcesToExclude */
    ImmutableSet.of(), apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalBuildRuleParams.getDeps()));
    AndroidPackageableCollection packageableCollection = collector.build();
    ImmutableSortedSet<BuildRule> androidResourceDeclaredDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getDeclaredDeps().get());
    ImmutableSortedSet<BuildRule> androidResourceExtraDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getExtraDeps().get());
    BuildRuleParams assembleAssetsParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_ASSETS_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
    ImmutableCollection<SourcePath> assetsDirectories = packageableCollection.getAssetsDirectories();
    AssembleDirectories assembleAssetsDirectories = new AssembleDirectories(assembleAssetsParams, assetsDirectories);
    aarExtraDepsBuilder.add(resolver.addToIndex(assembleAssetsDirectories));
    BuildRuleParams assembleResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
    ImmutableCollection<SourcePath> resDirectories = packageableCollection.getResourceDetails().getResourceDirectories();
    MergeAndroidResourceSources assembleResourceDirectories = new MergeAndroidResourceSources(assembleResourceParams, resDirectories);
    aarExtraDepsBuilder.add(resolver.addToIndex(assembleResourceDirectories));
    /* android_resource */
    BuildRuleParams androidResourceParams = originalBuildRuleParams.withBuildTarget(BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_RESOURCE_FLAVOR)).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(manifest, assembleAssetsDirectories, assembleResourceDirectories)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    AndroidResource androidResource = new AndroidResource(androidResourceParams, ruleFinder, /* deps */
    ImmutableSortedSet.<BuildRule>naturalOrder().add(assembleAssetsDirectories).add(assembleResourceDirectories).addAll(originalBuildRuleParams.getDeclaredDeps().get()).build(), assembleResourceDirectories.getSourcePathToOutput(), /* resSrcs */
    ImmutableSortedMap.of(), /* rDotJavaPackage */
    null, assembleAssetsDirectories.getSourcePathToOutput(), /* assetsSrcs */
    ImmutableSortedMap.of(), manifest.getSourcePathToOutput(), /* hasWhitelistedStrings */
    false);
    aarExtraDepsBuilder.add(resolver.addToIndex(androidResource));
    ImmutableSortedSet.Builder<SourcePath> classpathToIncludeInAar = ImmutableSortedSet.naturalOrder();
    classpathToIncludeInAar.addAll(packageableCollection.getClasspathEntriesToDex());
    aarExtraDepsBuilder.addAll(BuildRules.toBuildRulesFor(originalBuildRuleParams.getBuildTarget(), resolver, packageableCollection.getJavaLibrariesToDex()));
    if (!args.buildConfigValues.getNameToField().isEmpty() && !args.includeBuildConfigClass) {
        throw new HumanReadableException("Rule %s has build_config_values set but does not set " + "include_build_config_class to True. Either indicate you want to include the " + "BuildConfig class in the final .aar or do not specify build config values.", originalBuildRuleParams.getBuildTarget());
    }
    if (args.includeBuildConfigClass) {
        ImmutableSortedSet<JavaLibrary> buildConfigRules = AndroidBinaryGraphEnhancer.addBuildConfigDeps(originalBuildRuleParams, AndroidBinary.PackageType.RELEASE, EnumSet.noneOf(AndroidBinary.ExopackageMode.class), args.buildConfigValues, Optional.empty(), resolver, javacOptions, packageableCollection);
        resolver.addAllToIndex(buildConfigRules);
        aarExtraDepsBuilder.addAll(buildConfigRules);
        classpathToIncludeInAar.addAll(buildConfigRules.stream().map(BuildRule::getSourcePathToOutput).collect(Collectors.toList()));
    }
    /* native_libraries */
    AndroidNativeLibsPackageableGraphEnhancer packageableGraphEnhancer = new AndroidNativeLibsPackageableGraphEnhancer(resolver, originalBuildRuleParams, nativePlatforms, ImmutableSet.of(), cxxBuckConfig, /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> nativeLibrariesOptional = packageableGraphEnhancer.enhance(packageableCollection).getCopyNativeLibraries();
    if (nativeLibrariesOptional.isPresent() && nativeLibrariesOptional.get().containsKey(apkModuleGraph.getRootAPKModule())) {
        aarExtraDepsBuilder.add(resolver.addToIndex(nativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule())));
    }
    Optional<Path> assembledNativeLibsDir = nativeLibrariesOptional.map(input -> {
        CopyNativeLibraries copyNativeLibraries = input.get(apkModuleGraph.getRootAPKModule());
        if (copyNativeLibraries == null) {
            throw new HumanReadableException("Native libraries are present but not in the root application module.");
        }
        return copyNativeLibraries.getPathToNativeLibsDir();
    });
    BuildRuleParams androidAarParams = originalBuildRuleParams.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(aarExtraDepsBuilder.build())));
    return new AndroidAar(androidAarParams, manifest, androidResource, assembleResourceDirectories.getSourcePathToOutput(), assembleAssetsDirectories.getSourcePathToOutput(), assembledNativeLibsDir, ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()), classpathToIncludeInAar.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HumanReadableException(com.facebook.buck.util.HumanReadableException) MergeAndroidResourceSources(com.facebook.buck.android.aapt.MergeAndroidResourceSources)

Example 33 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet 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 34 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class AndroidInstrumentationApkDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    BuildRule installableApk = resolver.getRule(args.apk);
    if (!(installableApk instanceof HasInstallableApk)) {
        throw new HumanReadableException("In %s, apk='%s' must be an android_binary() or apk_genrule() but was %s().", params.getBuildTarget(), installableApk.getFullyQualifiedName(), installableApk.getType());
    }
    AndroidBinary apkUnderTest = getUnderlyingApk((HasInstallableApk) installableApk);
    ImmutableSortedSet<JavaLibrary> rulesToExcludeFromDex = new ImmutableSortedSet.Builder<>(Ordering.<JavaLibrary>natural()).addAll(apkUnderTest.getRulesToExcludeFromDex()).addAll(getClasspathDeps(apkUnderTest.getClasspathDeps())).build();
    // TODO(natthu): Instrumentation APKs should also exclude native libraries and assets from the
    // apk under test.
    AndroidPackageableCollection.ResourceDetails resourceDetails = apkUnderTest.getAndroidPackageableCollection().getResourceDetails();
    ImmutableSet<BuildTarget> resourcesToExclude = ImmutableSet.copyOf(Iterables.concat(resourceDetails.getResourcesWithNonEmptyResDir(), resourceDetails.getResourcesWithEmptyResButNonEmptyAssetsDir()));
    Path primaryDexPath = AndroidBinary.getPrimaryDexPath(params.getBuildTarget(), params.getProjectFilesystem());
    AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(params, resolver, ResourceCompressionMode.DISABLED, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
    EnumSet.noneOf(RType.class), /* resourceUnionPackage */
    Optional.empty(), /* locales */
    ImmutableSet.of(), args.manifest, PackageType.INSTRUMENTED, apkUnderTest.getCpuFilters(), /* shouldBuildStringSourceMap */
    false, /* shouldPreDex */
    false, primaryDexPath, DexSplitMode.NO_SPLIT, rulesToExcludeFromDex.stream().map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), resourcesToExclude, /* skipCrunchPngs */
    false, args.includesVectorDrawables.orElse(false), javacOptions, EnumSet.noneOf(ExopackageMode.class), /* buildConfigValues */
    BuildConfigFields.empty(), /* buildConfigValuesFile */
    Optional.empty(), /* xzCompressionLevel */
    Optional.empty(), /* trimResourceIds */
    false, /* keepResourcePattern */
    Optional.empty(), nativePlatforms, /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), /* nativeLibraryMergeCodeGenerator */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, dxExecutorService, apkUnderTest.getManifestEntries(), cxxBuckConfig, new APKModuleGraph(targetGraph, params.getBuildTarget(), Optional.empty()), dxConfig);
    AndroidGraphEnhancementResult enhancementResult = graphEnhancer.createAdditionalBuildables();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    return new AndroidInstrumentationApk(params.copyReplacingExtraDeps(Suppliers.ofInstance(enhancementResult.getFinalDeps())).copyAppendingExtraDeps(rulesToExcludeFromDex), ruleFinder, proGuardConfig.getProguardJarOverride(), proGuardConfig.getProguardMaxHeapSize(), proGuardConfig.getProguardAgentPath(), apkUnderTest, rulesToExcludeFromDex, enhancementResult, dxExecutorService);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ExopackageMode(com.facebook.buck.android.AndroidBinary.ExopackageMode) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 35 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class AuditInputCommand method printJsonInputs.

@VisibleForTesting
int printJsonInputs(final CommandRunnerParams params, TargetGraph graph) throws IOException {
    final SortedMap<String, ImmutableSortedSet<Path>> targetToInputs = new TreeMap<>();
    new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(graph) {

        @Override
        public void visit(TargetNode<?, ?> node) {
            Optional<Cell> cellRoot = params.getCell().getCellIfKnown(node.getBuildTarget());
            Cell cell = cellRoot.isPresent() ? cellRoot.get() : params.getCell();
            LOG.debug("Looking at inputs for %s", node.getBuildTarget().getFullyQualifiedName());
            SortedSet<Path> targetInputs = new TreeSet<>();
            for (Path input : node.getInputs()) {
                LOG.debug("Walking input %s", input);
                try {
                    if (!cell.getFilesystem().exists(input)) {
                        throw new HumanReadableException("Target %s refers to non-existent input file: %s", node, params.getCell().getRoot().relativize(cell.getRoot().resolve(input)));
                    }
                    targetInputs.addAll(cell.getFilesystem().getFilesUnderPath(input));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            targetToInputs.put(node.getBuildTarget().getFullyQualifiedName(), ImmutableSortedSet.copyOf(targetInputs));
        }
    }.traverse();
    params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetToInputs);
    return 0;
}
Also used : Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) Optional(java.util.Optional) IOException(java.io.IOException) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Cell(com.facebook.buck.rules.Cell) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)53 BuildTarget (com.facebook.buck.model.BuildTarget)26 BuildRule (com.facebook.buck.rules.BuildRule)26 Path (java.nio.file.Path)25 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableList (com.google.common.collect.ImmutableList)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)19 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 Optional (java.util.Optional)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)15 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 Map (java.util.Map)13 Flavor (com.facebook.buck.model.Flavor)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 Preconditions (com.google.common.base.Preconditions)11 Suppliers (com.google.common.base.Suppliers)10 TargetGraph (com.facebook.buck.rules.TargetGraph)9