Search in sources :

Example 51 with FakeBuildRuleParamsBuilder

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

the class ShTestTest method depsAreRuntimeDeps.

@Test
public void depsAreRuntimeDeps() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildRule extraDep = new FakeBuildRule("//:extra_dep", pathResolver);
    BuildRule dep = new FakeBuildRule("//:dep", pathResolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    ShTest shTest = new ShTest(new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setExtraDeps(ImmutableSortedSet.of(extraDep)).build(), ruleFinder, new FakeSourcePath("run_test.sh"), /* args */
    ImmutableList.of(), /* env */
    ImmutableMap.of(), /* resources */
    ImmutableSortedSet.of(), Optional.empty(), /* runTestSeparately */
    false, /* labels */
    ImmutableSet.of(), /* contacts */
    ImmutableSet.of());
    assertThat(shTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), containsInAnyOrder(dep.getBuildTarget(), extraDep.getBuildTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 52 with FakeBuildRuleParamsBuilder

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

the class SwiftLibraryIntegrationTest method headersOfDependentTargetsAreIncluded.

@Test
public void headersOfDependentTargetsAreIncluded() throws Exception {
    // The output path used by the buildable for the link tree.
    BuildTarget symlinkTarget = BuildTargetFactory.newInstance("//:symlink");
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(tmpDir.getRoot());
    Path symlinkTreeRoot = BuildTargets.getGenPath(projectFilesystem, symlinkTarget, "%s/symlink-tree-root");
    // Setup the map representing the link tree.
    ImmutableMap<Path, SourcePath> links = ImmutableMap.of();
    HeaderSymlinkTreeWithHeaderMap symlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(symlinkTarget, projectFilesystem, symlinkTreeRoot, links, ruleFinder);
    resolver.addToIndex(symlinkTreeBuildRule);
    BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
    BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
    FakeCxxLibrary depRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), symlinkTarget, BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", ImmutableSortedSet.of());
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#iphoneos-x86_64");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.of(depRule)).build();
    SwiftLibraryDescription.Arg args = createDummySwiftArg();
    SwiftCompile buildRule = (SwiftCompile) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraph.EMPTY, params, resolver, args);
    ImmutableList<String> swiftIncludeArgs = buildRule.getSwiftIncludeArgs(pathResolver);
    assertThat(swiftIncludeArgs.size(), Matchers.equalTo(1));
    assertThat(swiftIncludeArgs.get(0), Matchers.startsWith("-I"));
    assertThat(swiftIncludeArgs.get(0), Matchers.endsWith("symlink.hmap"));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) FakeCxxLibrary(com.facebook.buck.cxx.FakeCxxLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) HeaderSymlinkTreeWithHeaderMap(com.facebook.buck.cxx.HeaderSymlinkTreeWithHeaderMap) Test(org.junit.Test)

Example 53 with FakeBuildRuleParamsBuilder

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

the class SwiftLibraryIntegrationTest method testSwiftCompileAndLinkArgs.

@Test
public void testSwiftCompileAndLinkArgs() throws NoSuchBuildTargetException {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#iphoneos-x86_64");
    BuildTarget swiftCompileTarget = buildTarget.withAppendedFlavors(SwiftLibraryDescription.SWIFT_COMPILE_FLAVOR);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(swiftCompileTarget).build();
    SwiftLibraryDescription.Arg args = createDummySwiftArg();
    SwiftCompile buildRule = (SwiftCompile) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraph.EMPTY, params, resolver, args);
    resolver.addToIndex(buildRule);
    ImmutableList<Arg> astArgs = buildRule.getAstLinkArgs();
    assertThat(astArgs, Matchers.hasSize(3));
    assertThat(astArgs.get(0), Matchers.equalTo(StringArg.of("-Xlinker")));
    assertThat(astArgs.get(1), Matchers.equalTo(StringArg.of("-add_ast_path")));
    assertThat(astArgs.get(2), Matchers.instanceOf(SourcePathArg.class));
    SourcePathArg sourcePathArg = (SourcePathArg) astArgs.get(2);
    assertThat(sourcePathArg.getPath(), Matchers.equalTo(new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.swiftmodule"))));
    Arg objArg = buildRule.getFileListLinkArg();
    assertThat(objArg, Matchers.instanceOf(FileListableLinkerInputArg.class));
    FileListableLinkerInputArg fileListArg = (FileListableLinkerInputArg) objArg;
    ExplicitBuildTargetSourcePath fileListSourcePath = new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.o"));
    assertThat(fileListArg.getPath(), Matchers.equalTo(fileListSourcePath));
    BuildTarget linkTarget = buildTarget.withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR);
    CxxLink linkRule = (CxxLink) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraphFactory.newInstance(FakeTargetNodeBuilder.build(buildRule)), params.withBuildTarget(linkTarget), resolver, args);
    assertThat(linkRule.getArgs(), Matchers.hasItem(objArg));
    assertThat(linkRule.getArgs(), Matchers.not(Matchers.hasItem(SourcePathArg.of(fileListSourcePath))));
}
Also used : SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) CxxLink(com.facebook.buck.cxx.CxxLink) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 54 with FakeBuildRuleParamsBuilder

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

the class PrecompiledHeaderFeatureTest method preconfiguredSourceRuleFactoryBuilder.

/**
   * Configures a CxxSourceRuleFactory.Builder with some sane defaults for PCH tests.
   * Note: doesn't call "setPrefixHeader", which actually sets the PCH parameters; caller
   * needs to do that in their various tests.
   */
private static CxxSourceRuleFactory.Builder preconfiguredSourceRuleFactoryBuilder(String targetPath, BuildRuleResolver ruleResolver) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance(targetPath);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    return CxxSourceRuleFactory.builder().setParams(params).setResolver(ruleResolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setPicType(AbstractCxxSourceRuleFactory.PicType.PDC);
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 55 with FakeBuildRuleParamsBuilder

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

the class OmnibusTest method unusedStaticDepsAreNotIncludedInBody.

@Test
public void unusedStaticDepsAreNotIncludedInBody() throws NoSuchBuildTargetException {
    NativeLinkable a = new OmnibusNode("//:a", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.STATIC);
    NativeLinkable b = new OmnibusNode("//:b");
    NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a, b));
    // Verify the spec.
    Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of());
    assertThat(spec.getGraph().getNodes(), Matchers.containsInAnyOrder(b.getBuildTarget()));
    assertThat(spec.getBody().keySet(), Matchers.containsInAnyOrder(b.getBuildTarget()));
    assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
    assertThat(spec.getDeps().keySet(), Matchers.empty());
    assertThat(spec.getExcluded().keySet(), Matchers.empty());
    // Verify the libs.
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of()));
    assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), "libomnibus.so"));
    assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM), a.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
    assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get("libomnibus.so")), pathResolver, b.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

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