Search in sources :

Example 11 with FakeBuildRuleParamsBuilder

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));
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 12 with FakeBuildRuleParamsBuilder

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()));
}
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) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 13 with FakeBuildRuleParamsBuilder

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());
}
Also used : JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with FakeBuildRuleParamsBuilder

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());
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 15 with FakeBuildRuleParamsBuilder

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();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)108 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)102 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)102 Test (org.junit.Test)94 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)87 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)78 BuildTarget (com.facebook.buck.model.BuildTarget)77 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)74 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)50 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)32 SourcePath (com.facebook.buck.rules.SourcePath)30 BuildRule (com.facebook.buck.rules.BuildRule)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)25 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)22 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 Step (com.facebook.buck.step.Step)17 RuleKey (com.facebook.buck.rules.RuleKey)16 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)14