Search in sources :

Example 71 with DefaultTargetNodeToBuildRuleTransformer

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

the class ArchiveTest method testThatInputChangesCauseRuleKeyChanges.

@Test
public void testThatInputChangesCauseRuleKeyChanges() {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put(AR.toString(), Strings.repeat("0", 40)).put(RANLIB.toString(), Strings.repeat("1", 40)).put("a.o", Strings.repeat("a", 40)).put("b.o", Strings.repeat("b", 40)).put("c.o", Strings.repeat("c", 40)).put(Paths.get("different").toString(), Strings.repeat("d", 40)).build());
    // Generate a rule key for the defaults.
    RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
    // Verify that changing the archiver causes a rulekey change.
    RuleKey archiverChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new GnuArchiver(new HashedFileTool(Paths.get("different"))), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, archiverChange);
    // Verify that changing the output path causes a rulekey change.
    RuleKey outputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, Paths.get("different"), DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, outputChange);
    // Verify that changing the inputs causes a rulekey change.
    RuleKey inputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("different"))));
    assertNotEquals(defaultRuleKey, inputChange);
    // Verify that changing the type of archiver causes a rulekey change.
    RuleKey archiverTypeChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new BsdArchiver(new HashedFileTool(AR)), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, archiverTypeChange);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 72 with DefaultTargetNodeToBuildRuleTransformer

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

the class ArchiveTest method flagsArePropagated.

@Test
public void flagsArePropagated() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of("-foo"), DEFAULT_RANLIB, ImmutableList.of("-bar"), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o")));
    BuildContext buildContext = BuildContext.builder().from(FakeBuildContext.NOOP_CONTEXT).setSourcePathResolver(pathResolver).build();
    ImmutableList<Step> steps = archive.getBuildSteps(buildContext, new FakeBuildableContext());
    Step archiveStep = FluentIterable.from(steps).filter(ArchiveStep.class).first().get();
    assertThat(archiveStep.getDescription(TestExecutionContext.newInstance()), containsString("-foo"));
    Step ranlibStep = FluentIterable.from(steps).filter(RanlibStep.class).first().get();
    assertThat(ranlibStep.getDescription(TestExecutionContext.newInstance()), containsString("-bar"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 73 with DefaultTargetNodeToBuildRuleTransformer

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

the class CxxBinaryDescriptionTest method platformLinkerFlagsLocationMacroWithoutMatch.

@Test
public void platformLinkerFlagsLocationMacroWithoutMatch() 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("nothing matches this string"), 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.not(Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver)))));
    assertThat(binary.getDeps(), Matchers.not(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)

Example 74 with DefaultTargetNodeToBuildRuleTransformer

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

the class CxxBinaryDescriptionTest method staticPicLinkStyle.

@Test
public void staticPicLinkStyle() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleResolver resolver = new BuildRuleResolver(prepopulateWithSandbox(target), new DefaultTargetNodeToBuildRuleTransformer());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    new CxxBinaryBuilder(target, cxxBuckConfig).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp"))))).build(resolver, filesystem);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 75 with DefaultTargetNodeToBuildRuleTransformer

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

the class CxxBinaryDescriptionTest method testBinaryWithStripFlavorHasStripLinkRuleWithCorrectStripStyle.

@Test
public void testBinaryWithStripFlavorHasStripLinkRuleWithCorrectStripStyle() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
    CxxBinaryBuilder binaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:foo").withFlavors(platform.getFlavor(), InternalFlavor.of("shared"), StripStyle.ALL_SYMBOLS.getFlavor()), cxxBuckConfig);
    binaryBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(binaryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule resultRule = binaryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(resultRule, Matchers.instanceOf(CxxBinary.class));
    assertThat(((CxxBinary) resultRule).getLinkRule(), Matchers.instanceOf(CxxStrip.class));
    CxxStrip strip = (CxxStrip) ((CxxBinary) resultRule).getLinkRule();
    assertThat(strip.getStripStyle(), equalTo(StripStyle.ALL_SYMBOLS));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)579 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)578 Test (org.junit.Test)527 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)375 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)352 BuildTarget (com.facebook.buck.model.BuildTarget)257 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)238 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)204 TargetGraph (com.facebook.buck.rules.TargetGraph)182 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)115 SourcePath (com.facebook.buck.rules.SourcePath)110 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 PathSourcePath (com.facebook.buck.rules.PathSourcePath)90 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)70 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)68 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)49