use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidLibraryGraphEnhancerTest method testDummyRDotJavaRuleInheritsJavacOptionsDeps.
@Test
public void testDummyRDotJavaRuleInheritsJavacOptionsDeps() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
FakeBuildRule dep = new FakeBuildRule(BuildTargetFactory.newInstance("//:dep"), pathResolver);
dep.setOutputFile("foo");
resolver.addToIndex(dep);
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
JavacOptions options = JavacOptions.builder().setSourceLevel("5").setTargetLevel("5").setJavacJarPath(dep.getSourcePathToOutput()).build();
AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(target, new FakeBuildRuleParamsBuilder(target).build(), options, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
false, /* unionPackage */
Optional.empty(), /* rName */
Optional.empty(), false);
Optional<DummyRDotJava> result = graphEnhancer.getBuildableForAndroidResources(resolver, /* createdBuildableIfEmptyDeps */
true);
assertTrue(result.isPresent());
assertThat(result.get().getDeps(), Matchers.<BuildRule>hasItem(dep));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AndroidNativeLibsPackageableGraphEnhancerTest method testNdkLibrary.
@Test
public void testNdkLibrary() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
NdkLibrary ndkLibrary = new NdkLibraryBuilder(BuildTargetFactory.newInstance("//:ndklib")).build(ruleResolver);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(ndkLibrary)).build();
APKModuleGraph apkModuleGraph = new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty());
AndroidNativeLibsPackageableGraphEnhancer enhancer = new AndroidNativeLibsPackageableGraphEnhancer(ruleResolver, originalParams, ImmutableMap.of(), ImmutableSet.of(), CxxPlatformUtils.DEFAULT_CONFIG, /* nativeLibraryMergeMap */
Optional.empty(), /* nativeLibraryMergeGlue */
Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
AndroidPackageableCollector collector = new AndroidPackageableCollector(target, ImmutableSet.of(), ImmutableSet.of(), apkModuleGraph);
collector.addPackageables(AndroidPackageableCollector.getPackageableRules(ImmutableSet.of(ndkLibrary)));
Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibrariesOptional = enhancer.enhance(collector.build()).getCopyNativeLibraries();
CopyNativeLibraries copyNativeLibraries = copyNativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule());
assertThat(copyNativeLibraries.getStrippedObjectDescriptions(), Matchers.empty());
assertThat(copyNativeLibraries.getNativeLibDirectories().stream().map(sourcePathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()), Matchers.contains(ndkLibrary.getLibraryPath()));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class DexProducedFromJavaLibraryThatContainsClassFilesTest method getOutputDoesNotAccessWrappedJavaLibrary.
@Test
public void getOutputDoesNotAccessWrappedJavaLibrary() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
JavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).build(ruleResolver);
BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:target")).build();
DexProducedFromJavaLibrary dexProducedFromJavaLibrary = new DexProducedFromJavaLibrary(params, javaLibrary);
ObjectMapper mapper = ObjectMappers.newDefaultInstance();
FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo().putMetadata(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "0").putMetadata(DexProducedFromJavaLibrary.CLASSNAMES_TO_HASHES, mapper.writeValueAsString(ImmutableMap.<String, String>of()));
initialize(dexProducedFromJavaLibrary, onDiskBuildInfo);
assertFalse(dexProducedFromJavaLibrary.hasOutput());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class DummyRDotJavaTest method testRDotJavaBinFolder.
@Test
public void testRDotJavaBinFolder() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
DummyRDotJava dummyRDotJava = new DummyRDotJava(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//java/com/example:library")).build(), ruleFinder, ImmutableSet.of(), ANDROID_JAVAC_OPTIONS, /* forceFinalResourceIds */
false, Optional.empty(), Optional.empty(), false);
assertEquals(BuildTargets.getScratchPath(dummyRDotJava.getProjectFilesystem(), dummyRDotJava.getBuildTarget(), "__%s_rdotjava_bin__"), dummyRDotJava.getRDotJavaBinFolder());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class AppleCxxPlatformsTest method constructCompileRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
String source = "source.cpp";
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
CxxPreprocessAndCompile rule;
switch(operation) {
case PREPROCESS_AND_COMPILE:
rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
break;
case COMPILE:
rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
break;
default:
throw new IllegalStateException();
}
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
Aggregations