Search in sources :

Example 71 with BuildRuleParams

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)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 72 with BuildRuleParams

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())))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 73 with BuildRuleParams

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));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 74 with BuildRuleParams

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"));
}
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 75 with BuildRuleParams

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))));
}
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)

Aggregations

BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)145 BuildTarget (com.facebook.buck.model.BuildTarget)113 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)99 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)90 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)80 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)74 Test (org.junit.Test)73 BuildRule (com.facebook.buck.rules.BuildRule)72 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)69 SourcePath (com.facebook.buck.rules.SourcePath)58 Path (java.nio.file.Path)47 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)40 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)31 ImmutableList (com.google.common.collect.ImmutableList)27 PathSourcePath (com.facebook.buck.rules.PathSourcePath)26 Optional (java.util.Optional)26 Flavor (com.facebook.buck.model.Flavor)23 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)23 TargetGraph (com.facebook.buck.rules.TargetGraph)22 HumanReadableException (com.facebook.buck.util.HumanReadableException)22