use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class GroovyTestDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule testRule = resolver.requireRule(testTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavacOptions javacOptions = JavacOptionsFactory.create(defaultJavacOptions, params, resolver, ruleFinder, args).withAbiGenerationMode(JavacOptions.AbiGenerationMode.CLASS);
GroovycToJarStepFactory stepFactory = new GroovycToJarStepFactory(groovyBuckConfig.getGroovyCompiler().get(), Optional.of(args.extraGroovycArguments), javacOptions);
BuildRuleParams testsLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(defaultJavacOptions.getInputs(ruleFinder)))).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), defaultJavacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
Optional.empty(), /* postprocessClassesCommands */
ImmutableList.of(), /* exportDeps */
ImmutableSortedSet.of(), /* providedDeps */
ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), stepFactory, args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses));
return new JavaTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, /* additionalClasspathEntries */
ImmutableSet.of(), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, /* nativeLibsEnvironment */
ImmutableMap.of(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel);
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class AndroidBinaryGraphEnhancerTest method testAllBuildablesExceptPreDexRule.
@Test
public void testAllBuildablesExceptPreDexRule() throws Exception {
// Create an android_build_config() as a dependency of the android_binary().
BuildTarget buildConfigBuildTarget = BuildTargetFactory.newInstance("//java/com/example:cfg");
BuildRuleParams buildConfigParams = new FakeBuildRuleParamsBuilder(buildConfigBuildTarget).build();
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
AndroidBuildConfigJavaLibrary buildConfigJavaLibrary = AndroidBuildConfigDescription.createBuildRule(buildConfigParams, "com.example.buck", /* values */
BuildConfigFields.empty(), /* valuesFile */
Optional.empty(), /* useConstantExpressions */
false, ANDROID_JAVAC_OPTIONS, ruleResolver);
BuildTarget apkTarget = BuildTargetFactory.newInstance("//java/com/example:apk");
BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(apkTarget).setDeclaredDeps(ImmutableSortedSet.of(buildConfigJavaLibrary)).build();
// set it up.
Keystore keystore = createStrictMock(Keystore.class);
AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
ImmutableSet.of(), new FakeSourcePath("AndroidManifest.xml"), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
ImmutableSet.of(), /* shouldBuildStringSourceMap */
false, /* shouldPreDex */
false, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), apkTarget, "%s/classes.dex"), DexSplitMode.NO_SPLIT, /* buildRulesToExcludeFromDex */
ImmutableSet.of(), /* resourcesToExclude */
ImmutableSet.of(), /* skipCrunchPngs */
false, /* includesVectorDrawables */
false, ANDROID_JAVAC_OPTIONS, EnumSet.of(ExopackageMode.SECONDARY_DEX), /* buildConfigValues */
BuildConfigFields.empty(), /* buildConfigValuesFiles */
Optional.empty(), /* xzCompressionLevel */
Optional.empty(), /* trimResourceIds */
false, /* keepResourcePattern */
Optional.empty(), /* nativePlatforms */
ImmutableMap.of(), /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), /* nativeLibraryMergeCodeGenerator */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, MoreExecutors.newDirectExecutorService(), /* manifestEntries */
ManifestEntries.empty(), CxxPlatformUtils.DEFAULT_CONFIG, new APKModuleGraph(TargetGraph.EMPTY, originalParams.getBuildTarget(), Optional.empty()), new DxConfig(FakeBuckConfig.builder().build()));
replay(keystore);
AndroidGraphEnhancementResult result = graphEnhancer.createAdditionalBuildables();
// Verify that android_build_config() was processed correctly.
Flavor flavor = InternalFlavor.of("buildconfig_com_example_buck");
final SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildTarget enhancedBuildConfigTarget = BuildTarget.builder(apkTarget).addFlavors(flavor).build();
assertEquals("The only classpath entry to dex should be the one from the AndroidBuildConfigJavaLibrary" + " created via graph enhancement.", ImmutableSet.of(BuildTargets.getGenPath(originalParams.getProjectFilesystem(), enhancedBuildConfigTarget, "lib__%s__output").resolve(enhancedBuildConfigTarget.getShortNameAndFlavorPostfix() + ".jar")), result.getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
BuildRule enhancedBuildConfigRule = ruleResolver.getRule(enhancedBuildConfigTarget);
assertTrue(enhancedBuildConfigRule instanceof AndroidBuildConfigJavaLibrary);
AndroidBuildConfigJavaLibrary enhancedBuildConfigJavaLibrary = (AndroidBuildConfigJavaLibrary) enhancedBuildConfigRule;
AndroidBuildConfig androidBuildConfig = enhancedBuildConfigJavaLibrary.getAndroidBuildConfig();
assertEquals("com.example.buck", androidBuildConfig.getJavaPackage());
assertTrue(androidBuildConfig.isUseConstantExpressions());
assertEquals("IS_EXOPACKAGE defaults to false, but should now be true. DEBUG should still be true.", BuildConfigFields.fromFields(ImmutableList.of(BuildConfigFields.Field.of("boolean", "DEBUG", "true"), BuildConfigFields.Field.of("boolean", "IS_EXOPACKAGE", "true"), BuildConfigFields.Field.of("int", "EXOPACKAGE_FLAGS", "1"))), androidBuildConfig.getBuildConfigFields());
ImmutableSortedSet<BuildRule> finalDeps = result.getFinalDeps();
BuildRule computeExopackageDepsAbiRule = findRuleOfType(ruleResolver, ComputeExopackageDepsAbi.class);
assertThat(finalDeps, Matchers.hasItem(computeExopackageDepsAbiRule));
FilteredResourcesProvider resourcesProvider = result.getAaptPackageResources().getFilteredResourcesProvider();
assertTrue(resourcesProvider instanceof ResourcesFilter);
BuildRule resourcesFilterRule = findRuleOfType(ruleResolver, ResourcesFilter.class);
BuildRule aaptPackageResourcesRule = findRuleOfType(ruleResolver, AaptPackageResources.class);
MoreAsserts.assertDepends("AaptPackageResources must depend on ResourcesFilter", aaptPackageResourcesRule, resourcesFilterRule);
BuildRule packageStringAssetsRule = findRuleOfType(ruleResolver, PackageStringAssets.class);
MoreAsserts.assertDepends("PackageStringAssets must depend on ResourcesFilter", packageStringAssetsRule, aaptPackageResourcesRule);
assertFalse(result.getPreDexMerge().isPresent());
MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on ResourcesFilter", computeExopackageDepsAbiRule, resourcesFilterRule);
MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on PackageStringAssets", computeExopackageDepsAbiRule, packageStringAssetsRule);
MoreAsserts.assertDepends("ComputeExopackageDepsAbi must depend on AaptPackageResources", computeExopackageDepsAbiRule, aaptPackageResourcesRule);
assertTrue(result.getPackageStringAssets().isPresent());
assertTrue(result.getComputeExopackageDepsAbi().isPresent());
verify(keystore);
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class AndroidBinaryGraphEnhancerTest method testResourceRulesBecomeDepsOfAaptPackageResources.
@Test
public void testResourceRulesBecomeDepsOfAaptPackageResources() throws Exception {
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource")).setRDotJavaPackage("package").setRes(Paths.get("res")).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AndroidResource resource = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
// set it up.
BuildTarget target = BuildTargetFactory.newInstance("//:target");
BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(resource)).build();
AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
ImmutableSet.of(), new FakeSourcePath("AndroidManifest.xml"), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
ImmutableSet.of(), /* shouldBuildStringSourceMap */
false, /* shouldPreDex */
false, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), target, "%s/classes.dex"), DexSplitMode.NO_SPLIT, /* buildRulesToExcludeFromDex */
ImmutableSet.of(), /* resourcesToExclude */
ImmutableSet.of(), /* skipCrunchPngs */
false, /* includesVectorDrawables */
false, ANDROID_JAVAC_OPTIONS, EnumSet.of(ExopackageMode.SECONDARY_DEX), /* buildConfigValues */
BuildConfigFields.empty(), /* buildConfigValuesFiles */
Optional.empty(), /* xzCompressionLevel */
Optional.empty(), /* trimResourceIds */
false, /* keepResourcePattern */
Optional.empty(), /* nativePlatforms */
ImmutableMap.of(), /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), /* nativeLibraryMergeCodeGenerator */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, MoreExecutors.newDirectExecutorService(), /* manifestEntries */
ManifestEntries.empty(), CxxPlatformUtils.DEFAULT_CONFIG, new APKModuleGraph(TargetGraph.EMPTY, originalParams.getBuildTarget(), Optional.empty()), new DxConfig(FakeBuckConfig.builder().build()));
graphEnhancer.createAdditionalBuildables();
BuildRule aaptPackageResourcesRule = findRuleOfType(ruleResolver, AaptPackageResources.class);
MoreAsserts.assertDepends("AaptPackageResources must depend on resource rules", aaptPackageResourcesRule, resource);
}
use of com.facebook.buck.rules.BuildRuleParams 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.BuildRuleParams in project buck by facebook.
the class AndroidManifestTest method createSimpleAndroidManifestRule.
private AndroidManifest createSimpleAndroidManifestRule() {
// First, create the AndroidManifest object.
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(MANIFEST_TARGET).build();
AndroidManifestDescription description = new AndroidManifestDescription();
AndroidManifestDescription.Arg arg = description.createUnpopulatedConstructorArg();
arg.skeleton = new FakeSourcePath("java/com/example/AndroidManifestSkeleton.xml");
arg.deps = ImmutableSortedSet.<BuildTarget>of();
return description.createBuildRule(TargetGraph.EMPTY, buildRuleParams, new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), arg);
}
Aggregations