use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final Path output = Paths.get("output");
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
};
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class ExecutableMacroExpanderTest method testBuildTimeDependencies.
@Test
public void testBuildTimeDependencies() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
final BuildRule dep1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep1")).setOut("arg1").build(ruleResolver, filesystem);
final BuildRule dep2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep2")).setOut("arg2").build(ruleResolver, filesystem);
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {
@Override
public Tool getExecutableCommand() {
return new CommandTool.Builder().addArg(SourcePathArg.of(dep1.getSourcePathToOutput())).addArg(SourcePathArg.of(dep2.getSourcePathToOutput())).build();
}
});
// Verify that the correct cmd was created.
ExecutableMacroExpander expander = new ExecutableMacroExpander();
assertThat(expander.extractBuildTimeDeps(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.containsInAnyOrder(dep1, dep2));
assertThat(expander.expand(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(String.format("%s %s", pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep1.getSourcePathToOutput())), pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep2.getSourcePathToOutput())))));
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class ExecutableMacroExpanderTest method extractRuleKeyAppendable.
@Test
public void extractRuleKeyAppendable() throws MacroException {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
final Tool tool = new CommandTool.Builder().addArg("command").build();
ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {
@Override
public Tool getExecutableCommand() {
return tool;
}
});
ExecutableMacroExpander expander = new ExecutableMacroExpander();
assertThat(expander.extractRuleKeyAppendables(target, createCellRoots(params.getProjectFilesystem()), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(tool));
}
use of com.facebook.buck.rules.BuildRuleParams 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.BuildRuleParams 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))));
}
Aggregations