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));
}
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);
}
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());
}
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();
}
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"))))));
}
Aggregations