Search in sources :

Example 1 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class ApkGenruleDescription method createBuildRule.

@Override
protected <A extends ApkGenruleDescription.Arg> BuildRule createBuildRule(BuildRuleParams params, BuildRuleResolver resolver, A args, Optional<com.facebook.buck.rules.args.Arg> cmd, Optional<com.facebook.buck.rules.args.Arg> bash, Optional<com.facebook.buck.rules.args.Arg> cmdExe) {
    final BuildRule apk = resolver.getRule(args.apk);
    if (!(apk instanceof HasInstallableApk)) {
        throw new HumanReadableException("The 'apk' argument of %s, %s, must correspond to an " + "installable rule, such as android_binary() or apk_genrule().", params.getBuildTarget(), args.apk.getFullyQualifiedName());
    }
    HasInstallableApk installableApk = (HasInstallableApk) apk;
    final Supplier<ImmutableSortedSet<BuildRule>> originalExtraDeps = params.getExtraDeps();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    return new ApkGenrule(params.copyReplacingExtraDeps(Suppliers.memoize(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(originalExtraDeps.get()).add(installableApk).build())), ruleFinder, args.srcs, cmd, bash, cmdExe, args.type.isPresent() ? args.type : Optional.of("apk"), installableApk.getSourcePathToOutput());
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 2 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AndroidLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    if (params.getBuildTarget().getFlavors().contains(JavaLibrary.SRC_JAR)) {
        return new JavaSourceJar(params, args.srcs, args.mavenCoords);
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
    final ImmutableSet.Builder<BuildRule> queriedDepsBuilder = ImmutableSet.builder();
    if (args.depsQuery.isPresent()) {
        queriedDepsBuilder.addAll(QueryUtils.resolveDepQuery(params, args.depsQuery.get(), resolver, targetGraph).collect(Collectors.toList()));
    }
    final ImmutableSet<BuildRule> queriedDeps = queriedDepsBuilder.build();
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(queriedDeps).addAll(resolver.getAllRules(args.exportedDeps)).build())), javacOptions, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, args.resourceUnionPackage, args.finalRName, false);
    boolean hasDummyRDotJavaFlavor = params.getBuildTarget().getFlavors().contains(DUMMY_R_DOT_JAVA_FLAVOR);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        if (hasDummyRDotJavaFlavor) {
            return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
        }
        BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
    hasDummyRDotJavaFlavor);
    if (hasDummyRDotJavaFlavor) {
        return dummyRDotJava.get();
    } else {
        ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
        if (dummyRDotJava.isPresent()) {
            additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
            ImmutableSortedSet<BuildRule> newDeclaredDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).add(dummyRDotJava.get()).build();
            params = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(newDeclaredDeps), params.getExtraDeps());
        }
        AndroidLibraryCompiler compiler = compilerFactory.getCompiler(args.language.orElse(JvmLanguage.JAVA));
        ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
        ImmutableSortedSet.Builder<BuildRule> declaredDepsBuilder = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(queriedDeps).addAll(compiler.getDeclaredDeps(args, resolver));
        ImmutableSortedSet<BuildRule> declaredDeps = declaredDepsBuilder.build();
        ImmutableSortedSet<BuildRule> extraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(declaredDeps, exportedDeps, resolver.getAllRules(args.providedDeps)))).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).addAll(compiler.getExtraDeps(args, resolver)).build();
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        BuildRuleParams androidLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(declaredDeps), Suppliers.ofInstance(extraDeps));
        return new AndroidLibrary(androidLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, androidLibraryParams.getDeps()), additionalClasspathEntries, javacOptions, compiler.trackClassUsage(javacOptions), compiler.compileToJar(args, javacOptions, resolver), args.resourcesRoot, args.mavenCoords, args.manifest, args.tests);
    }
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ImmutableSet(com.google.common.collect.ImmutableSet) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) JavaSourceJar(com.facebook.buck.jvm.java.JavaSourceJar)

Example 3 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AndroidLibraryGraphEnhancer method getBuildableForAndroidResourcesAbi.

public CalculateAbi getBuildableForAndroidResourcesAbi(BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder) throws NoSuchBuildTargetException {
    Preconditions.checkState(CalculateAbi.isAbiTarget(dummyRDotJavaBuildTarget));
    BuildTarget resourcesTarget = CalculateAbi.getLibraryTarget(dummyRDotJavaBuildTarget);
    BuildRule resourcesRule = resolver.requireRule(resourcesTarget);
    return CalculateAbi.of(dummyRDotJavaBuildTarget, ruleFinder, originalBuildRuleParams, Preconditions.checkNotNull(resourcesRule.getSourcePathToOutput()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Example 4 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AndroidLibraryGraphEnhancer method getBuildableForAndroidResources.

public Optional<DummyRDotJava> getBuildableForAndroidResources(BuildRuleResolver ruleResolver, boolean createBuildableIfEmptyDeps) {
    Preconditions.checkState(!CalculateAbi.isAbiTarget(dummyRDotJavaBuildTarget));
    Optional<BuildRule> previouslyCreated = ruleResolver.getRuleOptional(dummyRDotJavaBuildTarget);
    if (previouslyCreated.isPresent()) {
        return previouslyCreated.map(input -> (DummyRDotJava) input);
    }
    ImmutableSortedSet<BuildRule> originalDeps = originalBuildRuleParams.getDeps();
    ImmutableSet<HasAndroidResourceDeps> androidResourceDeps;
    switch(resourceDependencyMode) {
        case FIRST_ORDER:
            androidResourceDeps = FluentIterable.from(originalDeps).filter(HasAndroidResourceDeps.class).filter(input -> input.getRes() != null).toSet();
            break;
        case TRANSITIVE:
            androidResourceDeps = UnsortedAndroidResourceDeps.createFrom(originalDeps, Optional.empty()).getResourceDeps();
            break;
        default:
            throw new IllegalStateException("Invalid resource dependency mode: " + resourceDependencyMode);
    }
    if (androidResourceDeps.isEmpty() && !createBuildableIfEmptyDeps) {
        return Optional.empty();
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    BuildRuleParams dummyRDotJavaParams = originalBuildRuleParams.withBuildTarget(dummyRDotJavaBuildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder)))), Suppliers.ofInstance(ImmutableSortedSet.of()));
    DummyRDotJava dummyRDotJava = new DummyRDotJava(dummyRDotJavaParams, ruleFinder, androidResourceDeps, javacOptions, forceFinalResourceIds, resourceUnionPackage, finalRName, useOldStyleableFormat);
    ruleResolver.addToIndex(dummyRDotJava);
    return Optional.of(dummyRDotJava);
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 5 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AndroidManifestDescription method createBuildRule.

@Override
public <A extends Arg> AndroidManifest createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    AndroidTransitiveDependencyGraph transitiveDependencyGraph = new AndroidTransitiveDependencyGraph(resolver.getAllRules(args.deps));
    ImmutableSet<SourcePath> manifestFiles = transitiveDependencyGraph.findManifestFiles();
    // The only rules that need to be built before this AndroidManifest are those
    // responsible for generating the AndroidManifest.xml files in the manifestFiles set (and
    // possibly the skeleton).
    //
    // If the skeleton is a BuildTargetSourcePath, then its build rule must also be in the deps.
    // The skeleton does not appear to be in either params.getDeclaredDeps() or
    // params.getExtraDeps(), even though the type of Arg.skeleton is SourcePath.
    // TODO(shs96c): t4744625 This should happen automagically.
    ImmutableSortedSet<BuildRule> newDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(Sets.union(manifestFiles, Collections.singleton(args.skeleton)))).build();
    return new AndroidManifest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(newDeps), params.getExtraDeps()), args.skeleton, manifestFiles);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Aggregations

BuildRule (com.facebook.buck.rules.BuildRule)361 BuildTarget (com.facebook.buck.model.BuildTarget)199 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)190 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 Test (org.junit.Test)175 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)165 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)162 SourcePath (com.facebook.buck.rules.SourcePath)118 Path (java.nio.file.Path)95 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)70 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)66 TargetGraph (com.facebook.buck.rules.TargetGraph)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)61 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)61 ImmutableList (com.google.common.collect.ImmutableList)58 PathSourcePath (com.facebook.buck.rules.PathSourcePath)51 ImmutableSet (com.google.common.collect.ImmutableSet)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 RuleKey (com.facebook.buck.rules.RuleKey)43