@Override public ImmutableCollection<Path> getInputsToCompareToOutput() { ImmutableSortedSet.Builder<Path> inputsToConsiderForCachingPurposes = ImmutableSortedSet .naturalOrder(); for (Path dir : dirs) { BuildRules.addInputsToSortedSet( dir, inputsToConsiderForCachingPurposes, directoryTraverser); } for (String virtualPathName : variants.keySet()) { Map<String, SourcePath> variant = variants.get(virtualPathName); inputsToConsiderForCachingPurposes.addAll( SourcePaths.filterInputsToCompareToOutput(variant.values())); } inputsToConsiderForCachingPurposes.addAll(SourcePaths.filterInputsToCompareToOutput(files)); return inputsToConsiderForCachingPurposes.build(); }
private static BuildRuleParams getBundleParamsWithUpdatedDeps( BuildRuleParams params, final BuildTarget originalBinaryTarget, final Set<BuildRule> newDeps) { // Remove the unflavored binary rule and add the flavored one instead. final Predicate<BuildRule> notOriginalBinaryRule = BuildRules.isBuildRuleWithTarget(originalBinaryTarget).negate(); return params .withDeclaredDeps( FluentIterable.from(params.getDeclaredDeps().get()) .filter(notOriginalBinaryRule::test) .append(newDeps) .toSortedSet(Ordering.natural())) .withExtraDeps( params .getExtraDeps() .get() .stream() .filter(notOriginalBinaryRule) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural()))); }
static ImmutableSortedSet<BuildRule> getAllDeps( BuildTarget aaptTarget, SourcePathRuleFinder ruleFinder, BuildRuleResolver ruleResolver, SourcePath manifest, FilteredResourcesProvider filteredResourcesProvider, ImmutableList<HasAndroidResourceDeps> resourceDeps) { ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder(); Stream<BuildTarget> resourceTargets = resourceDeps.stream().map(HasAndroidResourceDeps::getBuildTarget); depsBuilder.addAll( BuildRules.toBuildRulesFor(aaptTarget, ruleResolver, resourceTargets::iterator)); depsBuilder.addAll( resourceDeps .stream() .map(HasAndroidResourceDeps::getRes) .flatMap(ruleFinder.FILTER_BUILD_RULE_INPUTS) .iterator()); ruleFinder.getRule(manifest).ifPresent(depsBuilder::add); filteredResourcesProvider.getResourceFilterRule().ifPresent(depsBuilder::add); return depsBuilder.build(); }
@Test public void runtimeDepOnDeps() throws Exception { ProjectFilesystem filesystem = new FakeProjectFilesystem(); BuildTarget cxxBinaryTarget = BuildTargetFactory.newInstance("//:dep"); BuildTarget cxxLibraryTarget = BuildTargetFactory.newInstance("//:lib"); CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(cxxBinaryTarget); CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(cxxLibraryTarget).setDeps(ImmutableSortedSet.of(cxxBinaryTarget)); BuildRuleResolver resolver = new SingleThreadedBuildRuleResolver( TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), cxxBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer()); addFramework(resolver, filesystem); BuildRule cxxBinary = cxxBinaryBuilder.build(resolver, filesystem); cxxLibraryBuilder.build(resolver, filesystem); CxxTestBuilder cxxTestBuilder = createTestBuilder().setDeps(ImmutableSortedSet.of(cxxLibraryTarget)); addSandbox(resolver, filesystem, cxxTestBuilder.getTarget()); CxxTest cxxTest = cxxTestBuilder.build(resolver, filesystem); assertThat( BuildRules.getTransitiveRuntimeDeps(cxxTest, resolver), hasItem(cxxBinary.getBuildTarget())); }
@Override public ImmutableCollection<Path> getInputsToCompareToOutput() { // Build a sorted set so that metaInfDirectory contents are listed in a canonical order. ImmutableSortedSet.Builder<Path> builder = ImmutableSortedSet.naturalOrder(); if (manifestFile != null) { builder.addAll( SourcePaths.filterInputsToCompareToOutput(Collections.singleton(manifestFile))); } BuildRules.addInputsToSortedSet(metaInfDirectory, builder, directoryTraverser); return builder.build(); }
private ImmutableSortedSet<BuildRule> getTargetsAsRules(Collection<BuildTarget> buildTargets) { return BuildRules.toBuildRulesFor( originalBuildTarget, ruleResolver, buildTargets, /* allowNonExistentRules */ false); }
@Value.Lazy ImmutableSet<BuildRule> getCompileTimeClasspathUnfilteredFullDeps() { Iterable<BuildRule> firstOrderDeps = Iterables.concat( getAllFirstOrderNonProvidedDeps(), Preconditions.checkNotNull(getDeps()).getProvidedDeps()); ImmutableSet<BuildRule> rulesExportedByDependencies = BuildRules.getUnsortedExportedRules(firstOrderDeps); return RichStream.from(Iterables.concat(firstOrderDeps, rulesExportedByDependencies)) .collect(ImmutableSet.toImmutableSet()); }
@Override public AndroidInstrumentationTest createBuildRule( TargetGraph targetGraph, BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams params, BuildRuleResolver resolver, CellPathResolver cellRoots, AndroidInstrumentationTestDescriptionArg args) { BuildRule apk = resolver.getRule(args.getApk()); if (!(apk instanceof HasInstallableApk)) { throw new HumanReadableException( "In %s, instrumentation_apk='%s' must be an android_binary(), apk_genrule() or " + "android_instrumentation_apk(), but was %s().", buildTarget, apk.getFullyQualifiedName(), apk.getType()); } return new AndroidInstrumentationTest( buildTarget, projectFilesystem, toolchainProvider.getByName( AndroidPlatformTarget.DEFAULT_NAME, AndroidPlatformTarget.class), params.copyAppendingExtraDeps(BuildRules.getExportedRules(params.getDeclaredDeps().get())), (HasInstallableApk) apk, args.getLabels(), args.getContacts(), toolchainProvider .getByName(JavaOptionsProvider.DEFAULT_NAME, JavaOptionsProvider.class) .getJavaOptions() .getJavaRuntimeLauncher(), args.getTestRuleTimeoutMs() .map(Optional::of) .orElse(buckConfig.getDefaultTestRuleTimeoutMs()), getRelativePackagedResource(projectFilesystem, "ddmlib.jar"), getRelativePackagedResource(projectFilesystem, "kxml2.jar"), getRelativePackagedResource(projectFilesystem, "guava.jar"), getRelativePackagedResource(projectFilesystem, "android-tools-common.jar")); }
@Test public void runtimeDepOnDeps() throws Exception { ProjectFilesystem filesystem = new FakeProjectFilesystem(); BuildTarget leafBinaryTarget = BuildTargetFactory.newInstance("//:dep"); CxxBinaryBuilder leafCxxBinaryBuilder = new CxxBinaryBuilder(leafBinaryTarget, cxxBuckConfig); BuildTarget libraryTarget = BuildTargetFactory.newInstance("//:lib"); CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(leafBinaryTarget)); BuildTarget topLevelBinaryTarget = BuildTargetFactory.newInstance("//:bin"); CxxBinaryBuilder topLevelCxxBinaryBuilder = new CxxBinaryBuilder(topLevelBinaryTarget, cxxBuckConfig) .setDeps(ImmutableSortedSet.of(libraryTarget)); BuildRuleResolver resolver = new SingleThreadedBuildRuleResolver( TargetGraphFactory.newInstance( leafCxxBinaryBuilder.build(), cxxLibraryBuilder.build(), topLevelCxxBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer()); BuildRule leafCxxBinary = leafCxxBinaryBuilder.build(resolver, filesystem); cxxLibraryBuilder.build(resolver, filesystem); CxxBinary topLevelCxxBinary = topLevelCxxBinaryBuilder.build(resolver, filesystem); assertThat( BuildRules.getTransitiveRuntimeDeps(topLevelCxxBinary, resolver), Matchers.hasItem(leafCxxBinary.getBuildTarget())); }
@Test public void runtimeDepOnDeps() throws Exception { ProjectFilesystem filesystem = new FakeProjectFilesystem(); for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) { CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep")); PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")) .setSrcs( SourceList.ofUnnamedSources( ImmutableSortedSet.of(FakeSourcePath.of("something.py")))) .setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget())); PythonBinaryBuilder pythonBinaryBuilder = PythonBinaryBuilder.create(BuildTargetFactory.newInstance("//:bin")) .setMainModule("main") .setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget())) .setPackageStyle(packageStyle); TargetGraph targetGraph = TargetGraphFactory.newInstance( cxxBinaryBuilder.build(), pythonLibraryBuilder.build(), pythonBinaryBuilder.build()); BuildRuleResolver resolver = new SingleThreadedBuildRuleResolver( targetGraph, new DefaultTargetNodeToBuildRuleTransformer()); BuildRule cxxBinary = cxxBinaryBuilder.build(resolver, filesystem, targetGraph); pythonLibraryBuilder.build(resolver, filesystem, targetGraph); PythonBinary pythonBinary = pythonBinaryBuilder.build(resolver, filesystem, targetGraph); assertThat( String.format( "Transitive runtime deps of %s [%s]", pythonBinary, packageStyle.toString()), BuildRules.getTransitiveRuntimeDeps(pythonBinary, resolver), Matchers.hasItem(cxxBinary.getBuildTarget())); } }
@Test public void runtimeDepOnDeps() throws Exception { ProjectFilesystem filesystem = new FakeProjectFilesystem(); for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) { CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep")); PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")) .setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget())); PythonTestBuilder pythonTestBuilder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:test")) .setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget())) .setPackageStyle(packageStyle); TargetGraph targetGraph = TargetGraphFactory.newInstance( cxxBinaryBuilder.build(), pythonLibraryBuilder.build(), pythonTestBuilder.build()); BuildRuleResolver resolver = new SingleThreadedBuildRuleResolver( targetGraph, new DefaultTargetNodeToBuildRuleTransformer()); BuildRule cxxBinary = cxxBinaryBuilder.build(resolver, filesystem, targetGraph); pythonLibraryBuilder.build(resolver, filesystem, targetGraph); PythonTest pythonTest = pythonTestBuilder.build(resolver, filesystem, targetGraph); assertThat( String.format("Transitive runtime deps of %s [%s]", pythonTest, packageStyle.toString()), BuildRules.getTransitiveRuntimeDeps(pythonTest, resolver), Matchers.hasItem(cxxBinary.getBuildTarget())); } }
/** * @return a {@link CxxCompile} rule that preprocesses, compiles, and assembles the given * {@link CxxSource}. */ public static CxxCompile createCompileBuildRule( BuildRuleParams params, BuildRuleResolver resolver, Path compiler, CxxPreprocessorInput preprocessorInput, ImmutableList<String> compilerFlags, CxxSource source) { BuildTarget target = createCompileBuildTarget( params.getBuildTarget(), source.getName()); boolean cxx = !Files.getFileExtension(source.getName()).equals("c"); // The customized build rule params for each compilation. BuildRuleParams compileParams = params.copyWithChanges( COMPILE_TYPE, target, // Compile rules don't inherit any of the declared deps. /* declaredDeps */ ImmutableSortedSet.<BuildRule>of(), /* extraDeps */ ImmutableSortedSet.<BuildRule>naturalOrder() // Depend on the rule that generates the source we're compiling. .addAll(SourcePaths.filterBuildRuleInputs(ImmutableList.of(source.getSource()))) // Since compilation will consume our own headers, and the headers of our // dependencies, we need to depend on the rule that represent all headers. .addAll(BuildRules.toBuildRulesFor( params.getBuildTarget(), resolver, preprocessorInput.getRules(), false)) .build()); // Build the CxxCompile rule and add it to our sorted set of build rules. return new CxxCompile( compileParams, compiler, ImmutableList.<String>builder() .add("-x", cxx ? "c++" : "c") .addAll(cxx ? preprocessorInput.getCxxppflags() : preprocessorInput.getCppflags()) .addAll(compilerFlags) .build(), source.getObject(), source.getSource(), preprocessorInput.getIncludes(), preprocessorInput.getSystemIncludes()); }
/** * Construct a {@link CxxLink} rule that builds a native linkable from top-level input objects * and a dependency tree of {@link NativeLinkable} dependencies. */ public static CxxLink createCxxLinkableBuildRule( BuildRuleParams params, BuildRuleResolver resolver, Path linker, ImmutableList<String> cxxLdFlags, ImmutableList<String> ldFlags, BuildTarget target, Path output, Iterable<SourcePath> objects, Iterable<BuildRule> nativeLinkableDeps) { // Collect and topologically sort our deps that contribute to the link. NativeLinkableInput linkableInput = NativeLinkableInput.concat( FluentIterable .from(topoSort(nativeLinkableDeps).reverse()) .filter(NativeLinkable.class) .transform(NativeLinkable.GET_NATIVE_LINKABLE_INPUT)); // Construct our link build rule params. The important part here is combining the build rules // that construct our object file inputs and also the deps that build our dependencies. BuildRuleParams linkParams = params.copyWithChanges( NativeLinkable.NATIVE_LINKABLE_TYPE, target, ImmutableSortedSet.copyOf( Iterables.concat( // Add dependencies for build rules generating the object files. SourcePaths.filterBuildRuleInputs(objects), // Add dependencies for the target-node-level dependencies that // contribute to the link. BuildRules.toBuildRulesFor(target, resolver, linkableInput.getTargets(), false))), ImmutableSortedSet.<BuildRule>of()); // Build up the arguments to pass to the linker. ImmutableList<String> args = ImmutableList.<String>builder() .addAll(cxxLdFlags) .addAll( MoreIterables.zipAndConcat( Iterables.cycle("-Xlinker"), ldFlags)) .addAll( MoreIterables.zipAndConcat( Iterables.cycle("-Xlinker"), Iterables.concat( FluentIterable.from(objects) .transform(SourcePaths.TO_PATH) .transform(Functions.toStringFunction()), linkableInput.getArgs()))) .build(); // Build the C/C++ link step. return new CxxLink( linkParams, linker, output, ImmutableList.<SourcePath>builder() .addAll(objects) .addAll(SourcePaths.toSourcePathsSortedByNaturalOrder(linkableInput.getInputs())) .build(), args); }
private ImmutableSortedSet<BuildRule> getExportedDeps() { return BuildRules.getExportedRules(getBuildDeps()); }
private ImmutableSortedSet<BuildRule> getTargetsAsRules(Collection<BuildTarget> buildTargets) { return BuildRules.toBuildRulesFor(originalBuildTarget, ruleResolver, buildTargets); }