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);
}
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());
}
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());
}
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());
}
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()));
}
Aggregations