Search in sources :

Example 6 with RuleKeyObjectSink

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

the class DefaultRuleKeyFactoryTest method annotatedAppendableBuildRulesIncludeTheirRuleKey.

@Test
public void annotatedAppendableBuildRulesIncludeTheirRuleKey() {
    BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
    BuildTarget depTarget = BuildTargetFactory.newInstance("//cheese:more-peas");
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildRule rule = new EmptyRule(target);
    FileHashCache fileHashCache = new NullFileHashCache();
    DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
    class AppendableRule extends EmptyRule {

        public AppendableRule(BuildTarget target) {
            super(target);
        }

        @Override
        public void appendToRuleKey(RuleKeyObjectSink sink) {
            sink.setReflectively("cheese", "brie");
        }
    }
    AppendableRule appendableRule = new AppendableRule(depTarget);
    RuleKey appendableSubKey = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, fileHashCache, factory).setReflectively("cheese", "brie").build();
    RuleKey ruleSubKey = factory.build(appendableRule);
    RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
    try (RuleKeyScopedHasher.Scope keyScope = builder.getScopedHasher().keyScope("field")) {
        try (RuleKeyScopedHasher.Scope appendableScope = builder.getScopedHasher().wrapperScope(RuleKeyHasher.Wrapper.BUILD_RULE)) {
            builder.getScopedHasher().getHasher().putRuleKey(ruleSubKey);
        }
    }
    RuleKey expected = builder.build().result;
    class RuleContainingAppendableRule extends EmptyRule {

        @AddToRuleKey
        private final AppendableRule field;

        public RuleContainingAppendableRule(BuildTarget target, AppendableRule appendableRule) {
            super(target);
            this.field = appendableRule;
        }
    }
    RuleKey seen = factory.build(new RuleContainingAppendableRule(target, appendableRule));
    assertEquals(expected, seen);
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 7 with RuleKeyObjectSink

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

the class LuaBinaryDescription method getInPlaceBinary.

private Tool getInPlaceBinary(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, final SourcePath starter, final LuaPackageComponents components) {
    final List<SourcePath> extraInputs = new ArrayList<>();
    final SymlinkTree modulesLinkTree = resolver.addToIndex(createSymlinkTree(getModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), components.getModules()));
    final List<SymlinkTree> pythonModulesLinktree = new ArrayList<>();
    if (!components.getPythonModules().isEmpty()) {
        // Add in any missing init modules into the python components.
        SourcePath emptyInit = PythonBinaryDescription.createEmptyInitModule(params, resolver);
        extraInputs.add(emptyInit);
        ImmutableMap<String, SourcePath> pythonModules = MoreMaps.transformKeys(PythonBinaryDescription.addMissingInitModules(MoreMaps.transformKeys(components.getPythonModules(), MorePaths.toPathFn(params.getProjectFilesystem().getRootPath().getFileSystem())), emptyInit), Object::toString);
        final SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getPythonModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getPythonModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), pythonModules));
        pythonModulesLinktree.add(symlinkTree);
    }
    final List<SymlinkTree> nativeLibsLinktree = new ArrayList<>();
    if (!components.getNativeLibraries().isEmpty()) {
        SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getNativeLibsSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getNativeLibsSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), addVersionLessLibraries(cxxPlatform, components.getNativeLibraries())));
        nativeLibsLinktree.add(symlinkTree);
    }
    return new Tool() {

        @Override
        public ImmutableCollection<BuildRule> getDeps(SourcePathRuleFinder ruleFinder) {
            return ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(starter)).addAll(components.getDeps(ruleFinder)).add(modulesLinkTree).addAll(nativeLibsLinktree).addAll(pythonModulesLinktree).addAll(ruleFinder.filterBuildRuleInputs(extraInputs)).build();
        }

        @Override
        public ImmutableCollection<SourcePath> getInputs() {
            return ImmutableSortedSet.<SourcePath>naturalOrder().add(starter).addAll(components.getInputs()).addAll(extraInputs).build();
        }

        @Override
        public ImmutableList<String> getCommandPrefix(SourcePathResolver resolver) {
            return ImmutableList.of(resolver.getAbsolutePath(starter).toString());
        }

        @Override
        public ImmutableMap<String, String> getEnvironment(SourcePathResolver resolver) {
            return ImmutableMap.of();
        }

        @Override
        public void appendToRuleKey(RuleKeyObjectSink sink) {
            sink.setReflectively("starter", starter).setReflectively("components", components);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Aggregations

RuleKeyObjectSink (com.facebook.buck.rules.RuleKeyObjectSink)7 Test (org.junit.Test)5 Path (java.nio.file.Path)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRule (com.facebook.buck.rules.BuildRule)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 CommandTool (com.facebook.buck.rules.CommandTool)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 Tool (com.facebook.buck.rules.Tool)2 RuleKeyAppendableFunction (com.facebook.buck.rules.args.RuleKeyAppendableFunction)2 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)2 FakeProcess (com.facebook.buck.util.FakeProcess)2 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)2 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1