Search in sources :

Example 26 with FakeBuildRuleParamsBuilder

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

the class CxxPreprocessAndCompileTest method usesColorFlagForPreprocessingWhenRequested.

@Test
public void usesColorFlagForPreprocessingWhenRequested() throws Exception {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    Path output = Paths.get("test.ii");
    Path input = Paths.get("test.cpp");
    Path scratchDir = Paths.get("scratch");
    CxxPreprocessAndCompile buildRule = CxxPreprocessAndCompile.preprocessAndCompile(params, new PreprocessorDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), DEFAULT_WORKING_DIR, PREPROCESSOR_WITH_COLOR_SUPPORT, PreprocessorFlags.builder().build(), DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, COMPILER_WITH_COLOR_SUPPORT, CxxToolFlags.of()), output, new FakeSourcePath(input.toString()), DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty());
    ImmutableList<String> command = buildRule.makeMainStep(pathResolver, scratchDir, false).makeCompileArguments(input.toString(), "c++", /* preprocessable */
    true, /* allowColorsInDiagnostics */
    false);
    assertThat(command, not(hasItem(PreprocessorWithColorSupport.COLOR_FLAG)));
    command = buildRule.makeMainStep(pathResolver, scratchDir, false).makeCompileArguments(input.toString(), "c++", /* preprocessable */
    true, /* allowColorsInDiagnostics */
    true);
    assertThat(command, hasItem(CompilerWithColorSupport.COLOR_FLAG));
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) 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) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 27 with FakeBuildRuleParamsBuilder

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

the class CxxPreprocessAndCompileTest method inputChangesCauseRuleKeyChangesForCompilation.

@Test
public void inputChangesCauseRuleKeyChangesForCompilation() throws Exception {
    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("preprocessor", Strings.repeat("a", 40)).put("compiler", Strings.repeat("a", 40)).put("test.o", Strings.repeat("b", 40)).put("test.cpp", Strings.repeat("c", 40)).put("different", Strings.repeat("d", 40)).put("foo/test.h", Strings.repeat("e", 40)).put("path/to/a/plugin.so", Strings.repeat("f", 40)).put("path/to/a/different/plugin.so", Strings.repeat("a0", 40)).build());
    // Generate a rule key for the defaults.
    RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    // Verify that changing the compiler causes a rulekey change.
    RuleKey compilerChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("different"))), DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    assertNotEquals(defaultRuleKey, compilerChange);
    // Verify that changing the operation causes a rulekey change.
    RuleKey operationChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.preprocessAndCompile(params, new PreprocessorDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), DEFAULT_WORKING_DIR, DEFAULT_PREPROCESSOR, PreprocessorFlags.builder().build(), DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    assertNotEquals(defaultRuleKey, operationChange);
    // Verify that changing the platform flags causes a rulekey change.
    RuleKey platformFlagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.explicitBuilder().addPlatformFlags("-different").setRuleFlags(DEFAULT_TOOL_FLAGS.getRuleFlags()).build()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    assertNotEquals(defaultRuleKey, platformFlagsChange);
    // Verify that changing the rule flags causes a rulekey change.
    RuleKey ruleFlagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.explicitBuilder().setPlatformFlags(DEFAULT_TOOL_FLAGS.getPlatformFlags()).addRuleFlags("-other", "flags").build()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    assertNotEquals(defaultRuleKey, ruleFlagsChange);
    // Verify that changing the input causes a rulekey change.
    RuleKey inputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, new FakeSourcePath("different"), DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
    assertNotEquals(defaultRuleKey, inputChange);
}
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) 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 28 with FakeBuildRuleParamsBuilder

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

the class CxxPreprocessablesTest method createHeaderSymlinkTreeBuildRuleHasNoDeps.

@Test
public void createHeaderSymlinkTreeBuildRuleHasNoDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    // Setup up the main build target and build params, which some random dep.  We'll make
    // sure the dep doesn't get propagated to the symlink rule below.
    FakeBuildRule dep = createFakeBuildRule(BuildTargetFactory.newInstance(filesystem, "//random:dep"), pathResolver);
    BuildTarget target = BuildTargetFactory.newInstance(filesystem, "//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
    Path root = Paths.get("root");
    // Setup a simple genrule we can wrap in a ExplicitBuildTargetSourcePath to model a input source
    // that is built by another rule.
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance(filesystem, "//:genrule")).setOut("foo/bar.o").build(resolver);
    // Setup the link map with both a regular path-based source path and one provided by
    // another build rule.
    ImmutableMap<Path, SourcePath> links = ImmutableMap.of(Paths.get("link1"), new FakeSourcePath("hello"), Paths.get("link2"), genrule.getSourcePathToOutput());
    // Build our symlink tree rule using the helper method.
    HeaderSymlinkTree symlinkTree = CxxPreprocessables.createHeaderSymlinkTreeBuildRule(target, params.getProjectFilesystem(), root, links, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY, ruleFinder);
    // Verify that the symlink tree has no deps.  This is by design, since setting symlinks can
    // be done completely independently from building the source that the links point to and
    // independently from the original deps attached to the input build rule params.
    assertTrue(symlinkTree.getDeps().isEmpty());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 29 with FakeBuildRuleParamsBuilder

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

the class CxxSourceRuleFactoryHelper method of.

public static CxxSourceRuleFactory of(Path cellRoot, BuildTarget target, CxxPlatform cxxPlatform, CxxBuckConfig cxxBuckConfig) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    return CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(new FakeProjectFilesystem(cellRoot)).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(cxxBuckConfig).setCxxPlatform(cxxPlatform).setPicType(CxxSourceRuleFactory.PicType.PDC).build();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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)

Example 30 with FakeBuildRuleParamsBuilder

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

the class CxxDescriptionEnhancerTest method nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary.

@Test
public void nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary() throws Exception {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
    BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
    FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
    ImmutableSortedSet.of());
    BuildTarget otherLibDepTarget = BuildTargetFactory.newInstance("//:other");
    BuildRuleParams otherLibDepParams = new FakeBuildRuleParamsBuilder(otherLibDepTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
    ImmutableList<CxxPreprocessorInput> otherInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(otherLibDepParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(otherLibDepParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
    Set<SourcePath> roots = new HashSet<>();
    for (CxxHeaders headers : CxxPreprocessorInput.concat(otherInput).getIncludes()) {
        roots.add(headers.getRoot());
    }
    assertThat("Non-test rule with library dep should include public and not private headers", roots, allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:symlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:privatesymlink"))))));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)108 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)102 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)102 Test (org.junit.Test)94 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)87 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)78 BuildTarget (com.facebook.buck.model.BuildTarget)77 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)74 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)50 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)32 SourcePath (com.facebook.buck.rules.SourcePath)30 BuildRule (com.facebook.buck.rules.BuildRule)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)25 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)22 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 Step (com.facebook.buck.step.Step)17 RuleKey (com.facebook.buck.rules.RuleKey)16 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)14