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()));
}
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"));
}
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))));
}
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);
}
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));
}
Aggregations