Search in sources :

Example 16 with ExplicitBuildTargetSourcePath

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

the class ReactNativeLibraryGraphEnhancer method enhanceForAndroid.

public AndroidReactNativeLibrary enhanceForAndroid(BuildRuleParams params, BuildRuleResolver resolver, AndroidReactNativeLibraryDescription.Args args) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    BuildTarget originalBuildTarget = params.getBuildTarget();
    ReactNativeBundle bundle = createReactNativeBundle(params, resolver, ruleFinder, BuildTarget.builder(originalBuildTarget).addFlavors(REACT_NATIVE_BUNDLE_FLAVOR).build(), args, ReactNativePlatform.ANDROID);
    resolver.addToIndex(bundle);
    ImmutableList.Builder<BuildRule> extraDeps = ImmutableList.builder();
    extraDeps.add(bundle);
    if (args.rDotJavaPackage.isPresent()) {
        BuildRuleParams paramsForResource = params.withAppendedFlavor(REACT_NATIVE_ANDROID_RES_FLAVOR).copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(bundle)));
        SourcePath resources = new ExplicitBuildTargetSourcePath(bundle.getBuildTarget(), bundle.getResources());
        BuildRule resource = new AndroidResource(paramsForResource, ruleFinder, /* deps */
        ImmutableSortedSet.of(), resources, /* resSrcs */
        ImmutableSortedMap.of(), args.rDotJavaPackage.get(), /* assets */
        null, /* assetsSrcs */
        ImmutableSortedMap.of(), /* manifest */
        null, /* hasWhitelistedStrings */
        false);
        resolver.addToIndex(resource);
        extraDeps.add(resource);
    }
    return new AndroidReactNativeLibrary(params.copyAppendingExtraDeps(extraDeps.build()), bundle);
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableList(com.google.common.collect.ImmutableList) BuildRule(com.facebook.buck.rules.BuildRule) AndroidResource(com.facebook.buck.android.AndroidResource) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 17 with ExplicitBuildTargetSourcePath

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

the class AndroidManifestDescriptionTest method testGeneratedSkeletonAppearsInDeps.

@Test
public void testGeneratedSkeletonAppearsInDeps() {
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule ruleWithOutput = new FakeBuildRule(BuildTargetFactory.newInstance("//foo:bar"), new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver))) {

        @Override
        public SourcePath getSourcePathToOutput() {
            return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("buck-out/gen/foo/bar/AndroidManifest.xml"));
        }
    };
    SourcePath skeleton = ruleWithOutput.getSourcePathToOutput();
    buildRuleResolver.addToIndex(ruleWithOutput);
    AndroidManifestDescription.Arg arg = new AndroidManifestDescription.Arg();
    arg.skeleton = skeleton;
    arg.deps = ImmutableSortedSet.of();
    BuildRuleParams params = new FakeBuildRuleParamsBuilder("//foo:baz").setDeclaredDeps(buildRuleResolver.getAllRules(arg.deps)).build();
    BuildRule androidManifest = new AndroidManifestDescription().createBuildRule(TargetGraph.EMPTY, params, buildRuleResolver, arg);
    assertEquals(ImmutableSortedSet.of(ruleWithOutput), androidManifest.getDeps());
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 18 with ExplicitBuildTargetSourcePath

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

the class AndroidManifestTest method testSimpleObserverMethods.

@Test
public void testSimpleObserverMethods() {
    AndroidManifest androidManifest = createSimpleAndroidManifestRule();
    assertEquals(new ExplicitBuildTargetSourcePath(androidManifest.getBuildTarget(), BuildTargets.getGenPath(new FakeProjectFilesystem(), BuildTargetFactory.newInstance(MANIFEST_TARGET), "AndroidManifest__%s__.xml")), androidManifest.getSourcePathToOutput());
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 19 with ExplicitBuildTargetSourcePath

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

the class AndroidBuildConfigTest method testGetPathToOutput.

@Test
public void testGetPathToOutput() {
    AndroidBuildConfig buildConfig = createSimpleBuildConfigRule();
    assertEquals(new ExplicitBuildTargetSourcePath(BUILD_TARGET, BuildTargets.getGenPath(filesystem, BUILD_TARGET, "__%s__/BuildConfig.java")), buildConfig.getSourcePathToOutput());
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 20 with ExplicitBuildTargetSourcePath

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

the class AndroidPrebuiltAarDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    ImmutableSet<Flavor> flavors = params.getBuildTarget().getFlavors();
    if (flavors.contains(AAR_UNZIP_FLAVOR)) {
        Preconditions.checkState(flavors.size() == 1);
        BuildRuleParams unzipAarParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(args.aar))));
        return new UnzipAar(unzipAarParams, args.aar);
    }
    BuildRule unzipAarRule = buildRuleResolver.requireRule(params.getBuildTarget().withFlavors(AAR_UNZIP_FLAVOR));
    Preconditions.checkState(unzipAarRule instanceof UnzipAar, "aar_unzip flavor created rule of unexpected type %s for target %s", unzipAarRule.getClass(), params.getBuildTarget());
    UnzipAar unzipAar = (UnzipAar) unzipAarRule;
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, new ExplicitBuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getPathToClassesJar()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Iterable<PrebuiltJar> javaDeps = Iterables.concat(Iterables.filter(buildRuleResolver.getAllRules(args.deps), PrebuiltJar.class), Iterables.transform(Iterables.filter(buildRuleResolver.getAllRules(args.deps), AndroidPrebuiltAar.class), AndroidPrebuiltAar::getPrebuiltJar));
    if (flavors.contains(AAR_PREBUILT_JAR_FLAVOR)) {
        Preconditions.checkState(flavors.size() == 1, "Expected only flavor to be %s but also found %s", AAR_PREBUILT_JAR_FLAVOR, flavors);
        BuildRuleParams buildRuleParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(javaDeps)), Suppliers.ofInstance(ImmutableSortedSet.of(unzipAar)));
        return new PrebuiltJar(/* params */
        buildRuleParams, /* resolver */
        pathResolver, /* binaryJar */
        new ExplicitBuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getPathToClassesJar()), /* sourceJar */
        Optional.empty(), /* gwtJar */
        Optional.empty(), /* javadocUrl */
        Optional.empty(), /* mavenCoords */
        Optional.empty(), /* provided */
        false);
    }
    BuildRule prebuiltJarRule = buildRuleResolver.requireRule(BuildTargets.createFlavoredBuildTarget(params.getBuildTarget().checkUnflavored(), AAR_PREBUILT_JAR_FLAVOR));
    Preconditions.checkState(prebuiltJarRule instanceof PrebuiltJar, "%s flavor created rule of unexpected type %s for target %s", AAR_PREBUILT_JAR_FLAVOR, unzipAarRule.getType(), params.getBuildTarget());
    PrebuiltJar prebuiltJar = (PrebuiltJar) prebuiltJarRule;
    Preconditions.checkArgument(flavors.isEmpty(), "Unexpected flavors for android_prebuilt_aar: %s", flavors);
    BuildRuleParams androidLibraryParams = params.copyReplacingDeclaredAndExtraDeps(/* declaredDeps */
    Suppliers.ofInstance(ImmutableSortedSet.of(prebuiltJar)), /* extraDeps */
    Suppliers.ofInstance(ImmutableSortedSet.of(unzipAar)));
    return new AndroidPrebuiltAar(androidLibraryParams, /* resolver */
    pathResolver, ruleFinder, /* proguardConfig */
    new ExplicitBuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getProguardConfig()), /* nativeLibsDirectory */
    new ExplicitBuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getNativeLibsDirectory()), /* prebuiltJar */
    prebuiltJar, /* unzipRule */
    unzipAar, /* javacOptions */
    javacOptions, new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), /* exportedDeps */
    javaDeps, JavaLibraryRules.getAbiInputs(buildRuleResolver, androidLibraryParams.getDeps()));
}
Also used : JavacToJarStepFactory(com.facebook.buck.jvm.java.JavacToJarStepFactory) PrebuiltJar(com.facebook.buck.jvm.java.PrebuiltJar) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildRule(com.facebook.buck.rules.BuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Aggregations

ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)21 SourcePath (com.facebook.buck.rules.SourcePath)13 BuildTarget (com.facebook.buck.model.BuildTarget)10 Path (java.nio.file.Path)9 BuildRule (com.facebook.buck.rules.BuildRule)8 Test (org.junit.Test)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ImmutableList (com.google.common.collect.ImmutableList)6 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)3 NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 Flavor (com.facebook.buck.model.Flavor)3 InternalFlavor (com.facebook.buck.model.InternalFlavor)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)3 Step (com.facebook.buck.step.Step)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3