Search in sources :

Example 21 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class SymlinkTreeTest method testSymlinkTreeInputBasedRuleKeysAreImmuneToLinkSourceContentChanges.

@Test
public void testSymlinkTreeInputBasedRuleKeysAreImmuneToLinkSourceContentChanges() throws Exception {
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(ruleResolver);
    symlinkTreeBuildRule = new SymlinkTree(buildTarget, projectFilesystem, outputPath, ImmutableMap.of(Paths.get("link"), dep.getSourcePathToOutput()), ruleFinder);
    // Generate an input-based rule key for the symlink tree with the contents of the link
    // target hashing to "aaaa".
    FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("out", "aaaa"));
    InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
    RuleKey ruleKey1 = inputBasedRuleKeyFactory.build(symlinkTreeBuildRule);
    // Generate an input-based rule key for the symlink tree with the contents of the link
    // target hashing to a different value: "bbbb".
    hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("out", "bbbb"));
    inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
    RuleKey ruleKey2 = inputBasedRuleKeyFactory.build(symlinkTreeBuildRule);
    // Verify that the rules keys are the same.
    assertEquals(ruleKey1, ruleKey2);
}
Also used : InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Genrule(com.facebook.buck.shell.Genrule) Test(org.junit.Test)

Example 22 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class AppleLibraryDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR, DefaultCxxPlatforms.FLAVOR);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(DefaultCxxPlatforms.FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR);
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    AppleLibraryBuilder builder = new AppleLibraryBuilder(target).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    BuildRule binary = builder.build(resolver);
    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 : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) 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 23 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class AppleTestDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
    AppleTestBuilder builder = new AppleTestBuilder(BuildTargetFactory.newInstance("//:rule#macosx-x86_64")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(depBuilder.getTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build(), depBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = depBuilder.build(resolver, targetGraph);
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    AppleTest test = builder.build(resolver, targetGraph);
    CxxStrip strip = (CxxStrip) RichStream.from(test.getDeps()).filter(AppleBundle.class).findFirst().get().getBinary().get();
    BuildRule binary = strip.getDeps().first();
    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 : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRule(com.facebook.buck.rules.BuildRule) Genrule(com.facebook.buck.shell.Genrule) CxxLink(com.facebook.buck.cxx.CxxLink) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxStrip(com.facebook.buck.cxx.CxxStrip) Test(org.junit.Test)

Example 24 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class CxxBinaryDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRuleResolver resolver = new BuildRuleResolver(prepopulateWithSandbox(target), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    CxxBinaryBuilder builder = new CxxBinaryBuilder(target, cxxBuckConfig).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    BuildRule binary = 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) BuildRule(com.facebook.buck.rules.BuildRule) Genrule(com.facebook.buck.shell.Genrule) 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 25 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class CxxBinaryDescriptionTest method platformLinkerFlagsLocationMacroWithMatch.

@Test
public void platformLinkerFlagsLocationMacroWithMatch() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRuleResolver resolver = new BuildRuleResolver(prepopulateWithSandbox(target), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    CxxBinaryBuilder builder = new CxxBinaryBuilder(target, cxxBuckConfig).setPlatformLinkerFlags(new PatternMatchedCollection.Builder<ImmutableList<StringWithMacros>>().add(Pattern.compile(Pattern.quote(CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor().toString())), ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).build());
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    BuildRule binary = 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) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableList(com.google.common.collect.ImmutableList) BuildRule(com.facebook.buck.rules.BuildRule) Genrule(com.facebook.buck.shell.Genrule) 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)

Aggregations

Genrule (com.facebook.buck.shell.Genrule)31 Test (org.junit.Test)30 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)24 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)17 BuildTarget (com.facebook.buck.model.BuildTarget)14 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 BuildRule (com.facebook.buck.rules.BuildRule)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TargetGraph (com.facebook.buck.rules.TargetGraph)7 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)6 PatternMatchedCollection (com.facebook.buck.rules.coercer.PatternMatchedCollection)4 GenruleBuilder (com.facebook.buck.shell.GenruleBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 CxxLink (com.facebook.buck.cxx.CxxLink)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 Path (java.nio.file.Path)2 CxxBinary (com.facebook.buck.cxx.CxxBinary)1