Search in sources :

Example 26 with FakeBuildRule

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

the class MavenCoordinatesMacroExpanderTest method testNonHasMavenCoordinatesBuildRule.

@Test
public void testNonHasMavenCoordinatesBuildRule() throws Exception {
    assumeFalse("Assuming that FakeBuildRule does not have maven coordinates", FakeBuildRule.class.isAssignableFrom(HasMavenCoordinates.class));
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildRule rule = new FakeBuildRule("//test:foo", sourcePathResolver);
    try {
        expander.getMavenCoordinates(rule);
        fail("Expected MacroException; Rule does not contain maven coordinates");
    } catch (MacroException e) {
        assertTrue("Expected MacroException that indicates target does not have maven coordinates", e.getMessage().contains("does not correspond to a rule with maven coordinates"));
    }
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) HasMavenCoordinates(com.facebook.buck.jvm.java.HasMavenCoordinates) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Test(org.junit.Test)

Example 27 with FakeBuildRule

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

the class ExportFileTest method shouldSetInputsFromSourcePaths.

@Test
public void shouldSetInputsFromSourcePaths() throws Exception {
    ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(target).setSrc(new FakeSourcePath("chips")).setOut("cake");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ExportFile exportFile = builder.build(resolver, projectFilesystem);
    assertIterablesEquals(singleton(Paths.get("chips")), pathResolver.filterInputsToCompareToOutput(exportFile.getSource()));
    resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule rule = resolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//example:one"), pathResolver));
    builder.setSrc(new DefaultBuildTargetSourcePath(rule.getBuildTarget()));
    exportFile = builder.build(resolver, projectFilesystem);
    assertThat(pathResolver.filterInputsToCompareToOutput(exportFile.getSource()), Matchers.empty());
    resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    builder.setSrc(null);
    exportFile = builder.build(resolver, projectFilesystem);
    assertIterablesEquals(singleton(projectFilesystem.getPath("example.html")), pathResolver.filterInputsToCompareToOutput(exportFile.getSource()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 28 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule 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()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 29 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule 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 30 with FakeBuildRule

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

the class JavaTestDescriptionTest method rulesExportedFromProvidedDepsBecomeFirstOrderDeps.

@Test
public void rulesExportedFromProvidedDepsBecomeFirstOrderDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule exportedRule = resolver.addToIndex(new FakeBuildRule("//:exported_rule", pathResolver));
    FakeExportDependenciesRule exportingRule = resolver.addToIndex(new FakeExportDependenciesRule("//:exporting_rule", pathResolver, exportedRule));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    JavaTest javaTest = JavaTestBuilder.createBuilder(target).addProvidedDep(exportingRule.getBuildTarget()).build(resolver);
    ImmutableSortedSet<BuildRule> deps = javaTest.getCompiledTestsLibrary().getDeps();
    assertThat(deps, Matchers.<BuildRule>hasItem(exportedRule));
}
Also used : FakeExportDependenciesRule(com.facebook.buck.rules.FakeExportDependenciesRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) 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

FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)48 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)46 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)46 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)44 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)43 Test (org.junit.Test)43 BuildTarget (com.facebook.buck.model.BuildTarget)34 BuildRule (com.facebook.buck.rules.BuildRule)24 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)14 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 RuleKey (com.facebook.buck.rules.RuleKey)11 SourcePath (com.facebook.buck.rules.SourcePath)10 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)9 BuckEventBus (com.facebook.buck.event.BuckEventBus)8 BuildEvent (com.facebook.buck.rules.BuildEvent)8 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)8 Clock (com.facebook.buck.timing.Clock)8 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 ParseEvent (com.facebook.buck.parser.ParseEvent)7