Search in sources :

Example 51 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class NdkCxxPlatformTest method constructCompileRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> cxxPlatforms) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    String source = "source.cpp";
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    ImmutableMap.Builder<NdkCxxPlatforms.TargetCpuType, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> entry : cxxPlatforms.entrySet()) {
        CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
        CxxPreprocessAndCompile rule;
        switch(operation) {
            case PREPROCESS_AND_COMPILE:
                rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
                break;
            case COMPILE:
                rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
                break;
            default:
                throw new IllegalStateException();
        }
        ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
    }
    return ruleKeys.build();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) 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) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 52 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class CxxLinkTest method sanitizedPathsInFlagsDoNotAffectRuleKey.

@Test
public void sanitizedPathsInFlagsDoNotAffectRuleKey() {
    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();
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40))), pathResolver, ruleFinder);
    // Set up a map to sanitize the differences in the flags.
    int pathSize = 10;
    DebugPathSanitizer sanitizer1 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("something"), Paths.get("A")));
    DebugPathSanitizer sanitizer2 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("different"), Paths.get("A")));
    // Generate a rule with a path we need to sanitize to a consistent value.
    ImmutableList<Arg> args1 = ImmutableList.of(new SanitizedArg(sanitizer1.sanitize(Optional.empty()), "-Lsomething/foo"));
    RuleKey ruleKey1 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args1, Optional.empty(), /* cacheable */
    true));
    // Generate another rule with a different path we need to sanitize to the
    // same consistent value as above.
    ImmutableList<Arg> args2 = ImmutableList.of(new SanitizedArg(sanitizer2.sanitize(Optional.empty()), "-Ldifferent/foo"));
    RuleKey ruleKey2 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args2, Optional.empty(), /* cacheable */
    true));
    assertEquals(ruleKey1, ruleKey2);
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) 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) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Arg(com.facebook.buck.rules.args.Arg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Test(org.junit.Test)

Example 53 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class CxxLinkTest 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.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40)));
    // Generate a rule key for the defaults.
    RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, DEFAULT_ARGS, Optional.empty(), /* cacheable */
    true));
    // Verify that changing the archiver causes a rulekey change.
    RuleKey linkerChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, new GnuLinker(new HashedFileTool(Paths.get("different"))), DEFAULT_OUTPUT, DEFAULT_ARGS, Optional.empty(), /* cacheable */
    true));
    assertNotEquals(defaultRuleKey, linkerChange);
    // Verify that changing the output path causes a rulekey change.
    RuleKey outputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, Paths.get("different"), DEFAULT_ARGS, Optional.empty(), /* cacheable */
    true));
    assertNotEquals(defaultRuleKey, outputChange);
    // Verify that changing the flags causes a rulekey change.
    RuleKey flagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, ImmutableList.of(SourcePathArg.of(new FakeSourcePath("different"))), Optional.empty(), /* cacheable */
    true));
    assertNotEquals(defaultRuleKey, flagsChange);
}
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 54 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class CxxPreprocessAndCompileTest method preprocessorFlagsRuleKeyChangesCauseRuleKeyChangesForPreprocessing.

@Test
public void preprocessorFlagsRuleKeyChangesCauseRuleKeyChangesForPreprocessing() throws Exception {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    final BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    final 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());
    class TestData {

        public RuleKey generate(PreprocessorFlags flags) throws Exception {
            return 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, flags, DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
            Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.of()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
        }
    }
    TestData testData = new TestData();
    PreprocessorFlags defaultFlags = PreprocessorFlags.builder().build();
    PreprocessorFlags alteredFlags = defaultFlags.withFrameworkPaths(FrameworkPath.ofSourcePath(new FakeSourcePath("different")));
    assertNotEquals(testData.generate(defaultFlags), testData.generate(alteredFlags));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) 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) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 55 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class PythonPackagedBinaryTest method testRuleKeysFromModuleLayouts.

@Test
public void testRuleKeysFromModuleLayouts() throws IOException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    // Create two different sources, which we'll swap in as different modules.
    Path main = tmpDir.newFile().toPath();
    Files.write(main, "main".getBytes(Charsets.UTF_8));
    Path source1 = tmpDir.newFile().toPath();
    Files.write(source1, "hello world".getBytes(Charsets.UTF_8));
    Path source2 = tmpDir.newFile().toPath();
    Files.write(source2, "goodbye world".getBytes(Charsets.UTF_8));
    Path mainRelative = MorePaths.relativize(tmpDir.getRoot().toPath(), main);
    Path source1Relative = MorePaths.relativize(tmpDir.getRoot().toPath(), source1);
    Path source2Relative = MorePaths.relativize(tmpDir.getRoot().toPath(), source2);
    // Setup a rulekey builder factory.
    FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of(mainRelative.toString(), Strings.repeat("a", 40), source1Relative.toString(), Strings.repeat("b", 40), source2Relative.toString(), Strings.repeat("c", 40)));
    // Calculate the rule keys for the various ways we can layout the source and modules
    // across different python libraries.
    RuleKey pair1 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/one.py", source1Relative, "module/two.py", source2Relative);
    RuleKey pair2 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/two.py", source2Relative, "module/one.py", source1Relative);
    RuleKey pair3 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/one.py", source2Relative, "module/two.py", source1Relative);
    RuleKey pair4 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/two.py", source1Relative, "module/one.py", source2Relative);
    // Make sure only cases where the actual module layouts are different result
    // in different rules keys.
    assertEquals(pair1, pair2);
    assertEquals(pair3, pair4);
    assertNotEquals(pair1, pair3);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) 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)

Aggregations

DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)58 Test (org.junit.Test)43 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)42 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)42 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)34 RuleKey (com.facebook.buck.rules.RuleKey)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)27 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)24 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)23 BuildTarget (com.facebook.buck.model.BuildTarget)22 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 FileHashCache (com.facebook.buck.util.cache.FileHashCache)18 BuildRule (com.facebook.buck.rules.BuildRule)17 SourcePath (com.facebook.buck.rules.SourcePath)16 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)11 ImmutableMap (com.google.common.collect.ImmutableMap)10