@Override public AndroidInstrumentationApk build(BuildRuleResolver ruleResolver) { BuildRule apkRule = ruleResolver.get(this.apk); if (apkRule == null) { throw new HumanReadableException("Must specify apk for " + getBuildTarget()); } else if (!(apkRule instanceof InstallableBuildRule)) { throw new HumanReadableException( "In %s, apk='%s' must be an android_binary() or apk_genrule() but was %s().", getBuildTarget(), apkRule.getFullyQualifiedName(), apkRule.getType().getName()); } AndroidBinaryRule underlyingApk = getUnderlyingApk((InstallableBuildRule) apkRule); return new AndroidInstrumentationApk( createBuildRuleParams(ruleResolver), manifest, underlyingApk); }
public static ImmutableSet<BuildRule> validateAndGetSourcesUnderTest( ImmutableSet<BuildTarget> sourceUnderTestTargets, BuildTarget owner, BuildRuleResolver resolver) { ImmutableSet.Builder<BuildRule> sourceUnderTest = ImmutableSet.builder(); for (BuildTarget target : sourceUnderTestTargets) { BuildRule rule = resolver.getRule(target); if (!(rule instanceof JavaLibrary)) { // In this case, the source under test specified in the build file was not a Java library // rule. Since EMMA requires the sources to be in Java, we will throw this exception and // not continue with the tests. throw new HumanReadableException( "Specified source under test for %s is not a Java library: %s (%s).", owner, rule.getFullyQualifiedName(), rule.getType()); } sourceUnderTest.add(rule); } return sourceUnderTest.build(); }
/** * @return adds a the header {@link SymlinkTree} for the given rule to the {@link * CxxPreprocessorInput}. */ public static CxxPreprocessorInput.Builder addHeaderSymlinkTree( CxxPreprocessorInput.Builder builder, BuildTarget target, BuildRuleResolver ruleResolver, Flavor flavor, HeaderVisibility headerVisibility, IncludeType includeType) throws NoSuchBuildTargetException { BuildRule rule = ruleResolver.requireRule( BuildTarget.builder(target) .addFlavors( flavor, CxxDescriptionEnhancer.getHeaderSymlinkTreeFlavor(headerVisibility)) .build()); Preconditions.checkState( rule instanceof HeaderSymlinkTree, "Attempt to add %s of type %s and class %s to %s", rule.getFullyQualifiedName(), rule.getType(), rule.getClass(), target); HeaderSymlinkTree symlinkTree = (HeaderSymlinkTree) rule; builder .addRules(symlinkTree.getBuildTarget()) .setIncludes( CxxHeaders.builder() .setNameToPathMap(ImmutableSortedMap.copyOf(symlinkTree.getLinks())) .setFullNameToPathMap(ImmutableSortedMap.copyOf(symlinkTree.getFullLinks())) .build()); switch (includeType) { case LOCAL: builder.addIncludeRoots(symlinkTree.getIncludePath()); builder.addAllHeaderMaps(symlinkTree.getHeaderMap().asSet()); break; case SYSTEM: builder.addSystemIncludeRoots(symlinkTree.getSystemIncludePath()); break; } return builder; }
@Override public <A extends Arg> BuildRule createBuildRule( TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) { BuildRule installableApk = resolver.getRule(args.apk); if (!(installableApk instanceof InstallableApk)) { 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((InstallableApk) installableApk); ImmutableSortedSet<JavaLibrary> rulesToExcludeFromDex = FluentIterable.from( ImmutableSet.<JavaLibrary>builder() .addAll(apkUnderTest.getRulesToExcludeFromDex()) .addAll( Classpaths.getClasspathEntries(apkUnderTest.getClasspathDeps()).keySet()) .build()) .toSortedSet(HasBuildTarget.BUILD_TARGET_COMPARATOR); // 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()); AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer( targetGraph, params, resolver, ResourceCompressionMode.DISABLED, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* resourceUnionPackage */ Optional.<String>absent(), /* locales */ ImmutableSet.<String>of(), args.manifest, PackageType.INSTRUMENTED, apkUnderTest.getCpuFilters(), /* shouldBuildStringSourceMap */ false, /* shouldPreDex */ false, primaryDexPath, DexSplitMode.NO_SPLIT, FluentIterable.from(rulesToExcludeFromDex).transform(TO_TARGET).toSet(), resourcesToExclude, /* skipCrunchPngs */ false, javacOptions, EnumSet.noneOf(ExopackageMode.class), apkUnderTest.getKeystore(), /* buildConfigValues */ BuildConfigFields.empty(), /* buildConfigValuesFile */ Optional.<SourcePath>absent(), /* xzCompressionLevel */ Optional.<Integer>absent(), nativePlatforms, dxExecutorService); AndroidGraphEnhancementResult enhancementResult = graphEnhancer.createAdditionalBuildables(); return new AndroidInstrumentationApk( params .copyWithExtraDeps(Suppliers.ofInstance(enhancementResult.getFinalDeps())) .appendExtraDeps(rulesToExcludeFromDex), new SourcePathResolver(resolver), proGuardConfig.getProguardJarOverride(), proGuardConfig.getProguardMaxHeapSize(), apkUnderTest, rulesToExcludeFromDex, enhancementResult, dxExecutorService); }