Search in sources :

Example 11 with HashedFileTool

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

the class BuckConfig method getToolProvider.

/**
   * @return a {@link Tool} identified by a @{link BuildTarget} or {@link Path} reference
   *     by the given section:field, if set.
   */
public Optional<ToolProvider> getToolProvider(String section, String field) {
    Optional<String> value = getValue(section, field);
    if (!value.isPresent()) {
        return Optional.empty();
    }
    Optional<BuildTarget> target = getMaybeBuildTarget(section, field);
    if (target.isPresent()) {
        return Optional.of(new BinaryBuildRuleToolProvider(target.get(), String.format("[%s] %s", section, field)));
    } else {
        checkPathExists(value.get(), String.format("Overridden %s:%s path not found: ", section, field));
        return Optional.of(new ConstantToolProvider(new HashedFileTool(getPathFromVfs(value.get()))));
    }
}
Also used : ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) BinaryBuildRuleToolProvider(com.facebook.buck.rules.BinaryBuildRuleToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 12 with HashedFileTool

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

the class AppleConfig method getCodesignProvider.

public ToolProvider getCodesignProvider() {
    final String codesignField = "codesign";
    Optional<BuildTarget> target = delegate.getMaybeBuildTarget(APPLE_SECTION, codesignField);
    String source = String.format("[%s] %s", APPLE_SECTION, codesignField);
    if (target.isPresent()) {
        return new BinaryBuildRuleToolProvider(target.get(), source);
    } else {
        Optional<Path> codesignPath = delegate.getPath(APPLE_SECTION, codesignField);
        Path defaultCodesignPath = Paths.get("/usr/bin/codesign");
        HashedFileTool codesign = new HashedFileTool(codesignPath.orElse(defaultCodesignPath));
        return new ConstantToolProvider(codesign);
    }
}
Also used : Path(java.nio.file.Path) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) BinaryBuildRuleToolProvider(com.facebook.buck.rules.BinaryBuildRuleToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 13 with HashedFileTool

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

the class HaskellBuckConfig method getPackager.

@Override
public ToolProvider getPackager() {
    Optional<ToolProvider> configuredPackager = delegate.getToolProvider(SECTION, "packager");
    if (configuredPackager.isPresent()) {
        return configuredPackager.get();
    }
    Optional<Path> systemPackager = getSystemPackager();
    if (systemPackager.isPresent()) {
        return new ConstantToolProvider(new HashedFileTool(systemPackager.get()));
    }
    throw new HumanReadableException("No Haskell packager found in .buckconfig (%s.compiler) or on system", SECTION);
}
Also used : ToolProvider(com.facebook.buck.rules.ToolProvider) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) Path(java.nio.file.Path) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 14 with HashedFileTool

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

the class HaskellBuckConfig method getLinker.

@Override
public ToolProvider getLinker() {
    Optional<ToolProvider> configuredLinker = delegate.getToolProvider(SECTION, "linker");
    if (configuredLinker.isPresent()) {
        return configuredLinker.get();
    }
    Optional<Path> systemLinker = getSystemCompiler();
    if (systemLinker.isPresent()) {
        return new ConstantToolProvider(new HashedFileTool(systemLinker.get()));
    }
    throw new HumanReadableException("No Haskell linker found in .buckconfig (%s.compiler) or on system", SECTION);
}
Also used : ToolProvider(com.facebook.buck.rules.ToolProvider) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) Path(java.nio.file.Path) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 15 with HashedFileTool

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

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