Search in sources :

Example 6 with HashedFileTool

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

the class DefaultCxxPlatforms method build.

public static CxxPlatform build(Platform platform, ProjectFilesystem filesystem, CxxBuckConfig config) {
    String sharedLibraryExtension;
    String sharedLibraryVersionedExtensionFormat;
    String staticLibraryExtension;
    String objectFileExtension;
    Path defaultCFrontend;
    Path defaultCxxFrontend;
    LinkerProvider.Type linkerType;
    Archiver archiver;
    DebugPathSanitizer compilerSanitizer;
    Optional<String> binaryExtension;
    ImmutableMap<String, String> env = config.getEnvironment();
    switch(platform) {
        case LINUX:
            sharedLibraryExtension = "so";
            sharedLibraryVersionedExtensionFormat = "so.%s";
            staticLibraryExtension = "a";
            objectFileExtension = "o";
            defaultCFrontend = getExecutablePath("gcc", DEFAULT_C_FRONTEND, env);
            defaultCxxFrontend = getExecutablePath("g++", DEFAULT_CXX_FRONTEND, env);
            linkerType = LinkerProvider.Type.GNU;
            archiver = new GnuArchiver(new HashedFileTool(getExecutablePath("ar", DEFAULT_AR, env)));
            compilerSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), ImmutableBiMap.of(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.GCC, filesystem);
            binaryExtension = Optional.empty();
            break;
        case MACOS:
            sharedLibraryExtension = "dylib";
            sharedLibraryVersionedExtensionFormat = ".%s.dylib";
            staticLibraryExtension = "a";
            objectFileExtension = "o";
            defaultCFrontend = getExecutablePath("clang", DEFAULT_OSX_C_FRONTEND, env);
            defaultCxxFrontend = getExecutablePath("clang++", DEFAULT_OSX_CXX_FRONTEND, env);
            linkerType = LinkerProvider.Type.DARWIN;
            archiver = new BsdArchiver(new HashedFileTool(getExecutablePath("ar", DEFAULT_AR, env)));
            compilerSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), ImmutableBiMap.of(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.CLANG, filesystem);
            binaryExtension = Optional.empty();
            break;
        case WINDOWS:
            sharedLibraryExtension = "dll";
            sharedLibraryVersionedExtensionFormat = "dll";
            staticLibraryExtension = "lib";
            objectFileExtension = "obj";
            defaultCFrontend = getExecutablePath("gcc", DEFAULT_C_FRONTEND, env);
            defaultCxxFrontend = getExecutablePath("g++", DEFAULT_CXX_FRONTEND, env);
            linkerType = LinkerProvider.Type.WINDOWS;
            archiver = new WindowsArchiver(new HashedFileTool(getExecutablePath("ar", DEFAULT_AR, env)));
            compilerSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), ImmutableBiMap.of(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.GCC, filesystem);
            binaryExtension = Optional.of("exe");
            break;
        case FREEBSD:
            sharedLibraryExtension = "so";
            sharedLibraryVersionedExtensionFormat = "so.%s";
            staticLibraryExtension = "a";
            objectFileExtension = "o";
            defaultCFrontend = getExecutablePath("gcc", DEFAULT_C_FRONTEND, env);
            defaultCxxFrontend = getExecutablePath("g++", DEFAULT_CXX_FRONTEND, env);
            linkerType = LinkerProvider.Type.GNU;
            archiver = new BsdArchiver(new HashedFileTool(getExecutablePath("ar", DEFAULT_AR, env)));
            compilerSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), ImmutableBiMap.of(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.GCC, filesystem);
            binaryExtension = Optional.empty();
            break;
        //$CASES-OMITTED$
        default:
            throw new RuntimeException(String.format("Unsupported platform: %s", platform));
    }
    PreprocessorProvider aspp = new PreprocessorProvider(defaultCFrontend, Optional.empty());
    CompilerProvider as = new CompilerProvider(defaultCFrontend, Optional.empty());
    PreprocessorProvider cpp = new PreprocessorProvider(defaultCFrontend, Optional.empty());
    CompilerProvider cc = new CompilerProvider(defaultCFrontend, Optional.empty());
    PreprocessorProvider cxxpp = new PreprocessorProvider(defaultCxxFrontend, Optional.empty());
    CompilerProvider cxx = new CompilerProvider(defaultCxxFrontend, Optional.empty());
    return CxxPlatforms.build(FLAVOR, platform, config, as, aspp, cc, cxx, cpp, cxxpp, new DefaultLinkerProvider(linkerType, new ConstantToolProvider(new HashedFileTool(defaultCxxFrontend))), ImmutableList.of(), new HashedFileTool(getExecutablePath("strip", DEFAULT_STRIP, env)), archiver, new HashedFileTool(getExecutablePath("ranlib", DEFAULT_RANLIB, env)), new PosixNmSymbolNameTool(new HashedFileTool(getExecutablePath("nm", DEFAULT_NM, env))), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), sharedLibraryExtension, sharedLibraryVersionedExtensionFormat, staticLibraryExtension, objectFileExtension, compilerSanitizer, new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), ImmutableBiMap.of()), ImmutableMap.of(), binaryExtension, config.getHeaderVerification());
}
Also used : Path(java.nio.file.Path) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool)

Example 7 with HashedFileTool

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

the class CxxCompilationDatabaseTest method testCompilationDatabase.

@Test
public void testCompilationDatabase() throws Exception {
    BuildTarget testBuildTarget = BuildTarget.builder(BuildTargetFactory.newInstance("//foo:baz")).addAllFlavors(ImmutableSet.of(CxxCompilationDatabase.COMPILATION_DATABASE)).build();
    final String root = "/Users/user/src";
    final Path fakeRoot = Paths.get(root);
    ProjectFilesystem filesystem = new FakeProjectFilesystem(fakeRoot);
    BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
    BuildRuleResolver testBuildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver testSourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(testBuildRuleResolver));
    HeaderSymlinkTree privateSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PRIVATE, true);
    testBuildRuleResolver.addToIndex(privateSymlinkTree);
    HeaderSymlinkTree exportedSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PUBLIC, true);
    testBuildRuleResolver.addToIndex(exportedSymlinkTree);
    BuildTarget compileTarget = BuildTarget.builder(testBuildRuleParams.getBuildTarget().getUnflavoredBuildTarget()).addFlavors(InternalFlavor.of("compile-test.cpp")).build();
    PreprocessorFlags preprocessorFlags = PreprocessorFlags.builder().addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/foo/bar")), CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/test"))).build();
    ImmutableSortedSet.Builder<CxxPreprocessAndCompile> rules = ImmutableSortedSet.naturalOrder();
    BuildRuleParams compileBuildRuleParams = new FakeBuildRuleParamsBuilder(compileTarget).setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(privateSymlinkTree, exportedSymlinkTree)).build();
    rules.add(testBuildRuleResolver.addToIndex(CxxPreprocessAndCompile.preprocessAndCompile(compileBuildRuleParams, new PreprocessorDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), filesystem.getRootPath(), new GccPreprocessor(new HashedFileTool(Paths.get("preprocessor"))), preprocessorFlags, new RuleKeyAppendableFunction<FrameworkPath, Path>() {

        @Override
        public void appendToRuleKey(RuleKeyObjectSink sink) {
        // Do nothing.
        }

        @Override
        public Path apply(FrameworkPath input) {
            throw new UnsupportedOperationException("should not be called");
        }
    }, Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("compiler"))), CxxToolFlags.of()), Paths.get("test.o"), new FakeSourcePath(filesystem, "test.cpp"), CxxSource.Type.CXX, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty())));
    CxxCompilationDatabase compilationDatabase = CxxCompilationDatabase.createCompilationDatabase(testBuildRuleParams, rules.build());
    testBuildRuleResolver.addToIndex(compilationDatabase);
    assertThat(compilationDatabase.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.contains(exportedSymlinkTree.getBuildTarget(), privateSymlinkTree.getBuildTarget()));
    assertEquals("getPathToOutput() should be a function of the build target.", BuildTargets.getGenPath(filesystem, testBuildTarget, "__%s.json"), testSourcePathResolver.getRelativePath(compilationDatabase.getSourcePathToOutput()));
    List<Step> buildSteps = compilationDatabase.getBuildSteps(FakeBuildContext.withSourcePathResolver(testSourcePathResolver), new FakeBuildableContext());
    assertEquals(2, buildSteps.size());
    assertTrue(buildSteps.get(0) instanceof MkdirStep);
    assertTrue(buildSteps.get(1) instanceof CxxCompilationDatabase.GenerateCompilationCommandsJson);
    CxxCompilationDatabase.GenerateCompilationCommandsJson step = (CxxCompilationDatabase.GenerateCompilationCommandsJson) buildSteps.get(1);
    Iterable<CxxCompilationDatabaseEntry> observedEntries = step.createEntries();
    Iterable<CxxCompilationDatabaseEntry> expectedEntries = ImmutableList.of(CxxCompilationDatabaseEntry.of(root, root + "/test.cpp", ImmutableList.of("compiler", "-isystem", "/foo/bar", "-isystem", "/test", "-x", "c++", "-c", "-MD", "-MF", "test.o.dep", "test.cpp", "-o", "test.o")));
    MoreAsserts.assertIterablesEquals(expectedEntries, observedEntries);
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) RuleKeyAppendableFunction(com.facebook.buck.rules.args.RuleKeyAppendableFunction) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Test(org.junit.Test)

Example 8 with HashedFileTool

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

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

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

the class CxxPlatformsTest method returnsKnownDefaultPlatformSetInConfig.

@Test
public void returnsKnownDefaultPlatformSetInConfig() {
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("default_platform", "borland_cxx_452"));
    CompilerProvider compiler = new CompilerProvider(Paths.get("borland"), Optional.of(CxxToolProvider.Type.GCC));
    PreprocessorProvider preprocessor = new PreprocessorProvider(Paths.get("borland"), Optional.of(CxxToolProvider.Type.GCC));
    CxxPlatform borlandCxx452Platform = CxxPlatform.builder().setFlavor(InternalFlavor.of("borland_cxx_452")).setAs(compiler).setAspp(preprocessor).setCc(compiler).setCpp(preprocessor).setCxx(compiler).setCxxpp(preprocessor).setLd(new DefaultLinkerProvider(LinkerProvider.Type.GNU, new ConstantToolProvider(new HashedFileTool(Paths.get("borland"))))).setStrip(new HashedFileTool(Paths.get("borland"))).setSymbolNameTool(new PosixNmSymbolNameTool(new HashedFileTool(Paths.get("borland")))).setAr(new GnuArchiver(new HashedFileTool(Paths.get("borland")))).setRanlib(new HashedFileTool(Paths.get("borland"))).setSharedLibraryExtension("so").setSharedLibraryVersionedExtensionFormat(".so.%s").setStaticLibraryExtension("a").setObjectFileExtension("so").setCompilerDebugPathSanitizer(CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER).setAssemblerDebugPathSanitizer(CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER).setHeaderVerification(CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification()).build();
    BuckConfig buckConfig = FakeBuckConfig.builder().setSections(sections).build();
    assertThat(CxxPlatforms.getConfigDefaultCxxPlatform(new CxxBuckConfig(buckConfig), ImmutableMap.of(borlandCxx452Platform.getFlavor(), borlandCxx452Platform), CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(borlandCxx452Platform));
}
Also used : ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) ImmutableMap(com.google.common.collect.ImmutableMap) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Test(org.junit.Test)

Aggregations

HashedFileTool (com.facebook.buck.rules.HashedFileTool)17 Path (java.nio.file.Path)11 BuildTarget (com.facebook.buck.model.BuildTarget)7 ConstantToolProvider (com.facebook.buck.rules.ConstantToolProvider)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 Test (org.junit.Test)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)5 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)5 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)3 CommandTool (com.facebook.buck.rules.CommandTool)3 RuleKey (com.facebook.buck.rules.RuleKey)3 ToolProvider (com.facebook.buck.rules.ToolProvider)3 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)3 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2