Search in sources :

Example 36 with BuildRuleResolver

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

the class AppleBinaryDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule#sandbox," + FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_I386_PLATFORM.getFlavor());
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleBinaryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    AppleBinaryBuilder builder = new AppleBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    BuildRule binary = ((CxxBinary) builder.build(resolver)).getLinkRule();
    assertThat(binary, Matchers.instanceOf(CxxLink.class));
    assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
    assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) CxxBinary(com.facebook.buck.cxx.CxxBinary) BuildRule(com.facebook.buck.rules.BuildRule) Genrule(com.facebook.buck.shell.Genrule) CxxLink(com.facebook.buck.cxx.CxxLink) 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 37 with BuildRuleResolver

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

the class NdkLibraryDescriptionTest method transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule.

@Test
public void transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule transitiveInput = resolver.addToIndex(new FakeBuildRule("//:transitive_input", pathResolver));
    transitiveInput.setOutputFile("out");
    FakeNativeLinkable transitiveDep = resolver.addToIndex(new FakeNativeLinkable("//:transitive_dep", pathResolver, transitiveInput.getSourcePathToOutput()));
    FakeBuildRule firstOrderInput = resolver.addToIndex(new FakeBuildRule("//:first_order_input", pathResolver));
    firstOrderInput.setOutputFile("out");
    FakeNativeLinkable firstOrderDep = resolver.addToIndex(new FakeNativeLinkable("//:first_order_dep", pathResolver, firstOrderInput.getSourcePathToOutput(), transitiveDep));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule ndkLibrary = new NdkLibraryBuilder(target).addDep(firstOrderDep.getBuildTarget()).build(resolver);
    assertThat(ndkLibrary.getDeps(), Matchers.allOf(Matchers.<BuildRule>hasItem(firstOrderInput), Matchers.<BuildRule>hasItem(transitiveInput)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) 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 38 with BuildRuleResolver

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

the class NdkLibraryTest method testSimpleNdkLibraryRule.

@Test
public void testSimpleNdkLibraryRule() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildContext context = FakeBuildContext.NOOP_CONTEXT;
    String basePath = "java/src/com/facebook/base";
    BuildTarget target = BuildTargetFactory.newInstance(String.format("//%s:base", basePath));
    NdkLibrary ndkLibrary = new NdkLibraryBuilder(target).setFlags(ImmutableList.of("flag1", "flag2")).setIsAsset(true).build(ruleResolver, projectFilesystem);
    assertEquals("ndk_library", ndkLibrary.getType());
    assertTrue(ndkLibrary.getProperties().is(ANDROID));
    assertTrue(ndkLibrary.isAsset());
    assertEquals(projectFilesystem.getBuckPaths().getGenDir().resolve(basePath).resolve("__libbase"), ndkLibrary.getLibraryPath());
    List<Step> steps = ndkLibrary.getBuildSteps(context, new FakeBuildableContext());
    String libbase = projectFilesystem.getBuckPaths().getScratchDir().resolve(basePath).resolve("__libbase").toString();
    MoreAsserts.assertShellCommands("ndk_library() should invoke ndk-build on the given path with some -j value", ImmutableList.of(String.format("%s -j %d -C %s flag1 flag2 " + "APP_PROJECT_PATH=%s " + "APP_BUILD_SCRIPT=%s " + "NDK_OUT=%s " + "NDK_LIBS_OUT=%s " + "BUCK_PROJECT_DIR=../../../../.. " + "host-echo-build-step=%s " + "--silent", ndkBuildCommand, Runtime.getRuntime().availableProcessors(), Paths.get(basePath).toString(), /* APP_PROJECT_PATH */
    projectFilesystem.resolve(libbase) + File.separator, /* APP_BUILD_SCRIPT */
    projectFilesystem.resolve(NdkLibraryDescription.getGeneratedMakefilePath(target, projectFilesystem)), /* NDK_OUT */
    projectFilesystem.resolve(libbase) + File.separator, /* NDK_LIBS_OUT */
    projectFilesystem.resolve(Paths.get(libbase, "libs")), /* host-echo-build-step */
    Platform.detect() == Platform.WINDOWS ? "@REM" : "@#")), steps.subList(3, 4), executionContext);
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 39 with BuildRuleResolver

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

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage.

@Test
public void testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage() throws IOException {
    BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
    MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
    false, Optional.of("resM"), /* rName */
    Optional.empty(), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
    String resMjava = filesystem.readFileIfItExists(Paths.get("output/resM/R.java")).get();
    assertThat(res1java, StringContains.containsString("id1"));
    assertThat(resMjava, StringContains.containsString("id1"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 40 with BuildRuleResolver

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

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithRName.

@Test
public void testGenerateRDotJavaWithRName() throws IOException {
    BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000", "int id id2 0x7f020002")));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
    MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
    true, Optional.of("res1"), Optional.of("R2"), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    String resR2Java = filesystem.readFileIfItExists(Paths.get("output/res1/R2.java")).get();
    assertThat(resR2Java, StringContains.containsString("static final int id1=0x07f01001;"));
    assertThat(resR2Java, StringContains.containsString("static final int id2=0x07f01002;"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)622 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)578 Test (org.junit.Test)540 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)402 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)376 BuildTarget (com.facebook.buck.model.BuildTarget)287 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)240 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)211 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 TargetGraph (com.facebook.buck.rules.TargetGraph)196 BuildRule (com.facebook.buck.rules.BuildRule)185 Path (java.nio.file.Path)136 SourcePath (com.facebook.buck.rules.SourcePath)133 PathSourcePath (com.facebook.buck.rules.PathSourcePath)104 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)83 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)75 RuleKey (com.facebook.buck.rules.RuleKey)71 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)54