Search in sources :

Example 1 with ToolProvider

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

the class HaskellBuckConfig method getCompiler.

@Override
public ToolProvider getCompiler() {
    Optional<ToolProvider> configuredCompiler = delegate.getToolProvider(SECTION, "compiler");
    if (configuredCompiler.isPresent()) {
        return configuredCompiler.get();
    }
    Optional<Path> systemCompiler = getSystemCompiler();
    if (systemCompiler.isPresent()) {
        return new ConstantToolProvider(new HashedFileTool(systemCompiler.get()));
    }
    throw new HumanReadableException("No Haskell compiler 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 2 with ToolProvider

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

the class RustTestDescription method findDepsForTargetFromConstructorArgs.

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, RustTestDescription.Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
    ToolProvider compiler = rustBuckConfig.getRustCompiler();
    deps.addAll(compiler.getParseTimeDeps());
    deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValues()));
    return deps.build();
}
Also used : ToolProvider(com.facebook.buck.rules.ToolProvider) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 3 with ToolProvider

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

the class NdkCxxPlatforms method build.

@VisibleForTesting
static NdkCxxPlatform build(CxxBuckConfig config, ProjectFilesystem filesystem, Flavor flavor, Platform platform, Path ndkRoot, NdkCxxPlatformTargetConfiguration targetConfiguration, CxxRuntime cxxRuntime, ExecutableFinder executableFinder, boolean strictToolchainPaths) {
    // Create a version string to use when generating rule keys via the NDK tools we'll generate
    // below.  This will be used in lieu of hashing the contents of the tools, so that builds from
    // different host platforms (which produce identical output) will share the cache with one
    // another.
    NdkCxxPlatformCompiler.Type compilerType = targetConfiguration.getCompiler().getType();
    String version = Joiner.on('-').join(ImmutableList.of(readVersion(ndkRoot), targetConfiguration.getToolchain(), targetConfiguration.getTargetAppPlatform(), compilerType, targetConfiguration.getCompiler().getVersion(), targetConfiguration.getCompiler().getGccVersion(), cxxRuntime));
    Host host = Preconditions.checkNotNull(BUILD_PLATFORMS.get(platform));
    NdkCxxToolchainPaths toolchainPaths = new NdkCxxToolchainPaths(filesystem, ndkRoot, targetConfiguration, host.toString(), cxxRuntime, strictToolchainPaths);
    // Sanitized paths will have magic placeholders for parts of the paths that
    // are machine/host-specific. See comments on ANDROID_NDK_ROOT and
    // BUILD_HOST_SUBST above.
    NdkCxxToolchainPaths sanitizedPaths = toolchainPaths.getSanitizedPaths();
    // Build up the map of paths that must be sanitized.
    ImmutableBiMap.Builder<Path, Path> sanitizePathsBuilder = ImmutableBiMap.builder();
    sanitizePathsBuilder.put(toolchainPaths.getNdkToolRoot(), sanitizedPaths.getNdkToolRoot());
    if (compilerType != NdkCxxPlatformCompiler.Type.GCC) {
        sanitizePathsBuilder.put(toolchainPaths.getNdkGccToolRoot(), sanitizedPaths.getNdkGccToolRoot());
    }
    sanitizePathsBuilder.put(ndkRoot, Paths.get(ANDROID_NDK_ROOT));
    CxxToolProvider.Type type = compilerType == NdkCxxPlatformCompiler.Type.CLANG ? CxxToolProvider.Type.CLANG : CxxToolProvider.Type.GCC;
    ToolProvider ccTool = new ConstantToolProvider(getCTool(toolchainPaths, compilerType.getCc(), version, executableFinder));
    ToolProvider cxxTool = new ConstantToolProvider(getCTool(toolchainPaths, compilerType.getCxx(), version, executableFinder));
    CompilerProvider cc = new CompilerProvider(ccTool, type);
    PreprocessorProvider cpp = new PreprocessorProvider(ccTool, type);
    CompilerProvider cxx = new CompilerProvider(cxxTool, type);
    PreprocessorProvider cxxpp = new PreprocessorProvider(cxxTool, type);
    CxxPlatform.Builder cxxPlatformBuilder = CxxPlatform.builder();
    ImmutableBiMap<Path, Path> sanitizePaths = sanitizePathsBuilder.build();
    PrefixMapDebugPathSanitizer compilerDebugPathSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizePaths, filesystem.getRootPath().toAbsolutePath(), type, filesystem);
    MungingDebugPathSanitizer assemblerDebugPathSanitizer = new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizePaths);
    cxxPlatformBuilder.setFlavor(flavor).setAs(cc).addAllAsflags(getAsflags(targetConfiguration, toolchainPaths)).setAspp(cpp).setCc(cc).addAllCflags(getCflagsInternal(targetConfiguration, toolchainPaths)).setCpp(cpp).addAllCppflags(getCppflags(targetConfiguration, toolchainPaths)).setCxx(cxx).addAllCxxflags(getCxxflagsInternal(targetConfiguration, toolchainPaths)).setCxxpp(cxxpp).addAllCxxppflags(getCxxppflags(targetConfiguration, toolchainPaths)).setLd(new DefaultLinkerProvider(LinkerProvider.Type.GNU, new ConstantToolProvider(getCcLinkTool(targetConfiguration, toolchainPaths, compilerType.getCxx(), version, cxxRuntime, executableFinder)))).addAllLdflags(targetConfiguration.getLinkerFlags(compilerType)).addLdflags(// We use it to find symbols from arbitrary binaries.
    "-Wl,--build-id", // Enforce the NX (no execute) security feature
    "-Wl,-z,noexecstack", // Strip unused code
    "-Wl,--gc-sections", // Refuse to produce dynamic objects with undefined symbols
    "-Wl,-z,defs", // Forbid dangerous copy "relocations"
    "-Wl,-z,nocopyreloc", // means the resulting link will only use it if it was actually needed it.
    "-Wl,--as-needed").setStrip(getGccTool(toolchainPaths, "strip", version, executableFinder)).setSymbolNameTool(new PosixNmSymbolNameTool(getGccTool(toolchainPaths, "nm", version, executableFinder))).setAr(new GnuArchiver(getGccTool(toolchainPaths, "ar", version, executableFinder))).setRanlib(getGccTool(toolchainPaths, "ranlib", version, executableFinder)).setCompilerDebugPathSanitizer(compilerDebugPathSanitizer).setAssemblerDebugPathSanitizer(assemblerDebugPathSanitizer).setSharedLibraryExtension("so").setSharedLibraryVersionedExtensionFormat("so.%s").setStaticLibraryExtension("a").setObjectFileExtension("o").setSharedLibraryInterfaceFactory(config.shouldUseSharedLibraryInterfaces() ? Optional.of(ElfSharedLibraryInterfaceFactory.of(new ConstantToolProvider(getGccTool(toolchainPaths, "objcopy", version, executableFinder)))) : Optional.empty());
    // Add the NDK root path to the white-list so that headers from the NDK won't trigger the
    // verification warnings.  Ideally, long-term, we'd model NDK libs/headers via automatically
    // generated nodes/descriptions so that they wouldn't need to special case it here.
    HeaderVerification headerVerification = config.getHeaderVerification();
    try {
        headerVerification = headerVerification.withPlatformWhitelist(ImmutableList.of("^" + Pattern.quote(ndkRoot.toRealPath().toString() + File.separatorChar) + ".*"));
    } catch (IOException e) {
        LOG.warn(e, "NDK path could not be resolved: %s", ndkRoot);
    }
    cxxPlatformBuilder.setHeaderVerification(headerVerification);
    LOG.debug("NDK root: %s", ndkRoot.toString());
    LOG.debug("Headers verification platform whitelist: %s", headerVerification.getPlatformWhitelist());
    if (cxxRuntime != CxxRuntime.SYSTEM) {
        cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.SHARED, "-l" + cxxRuntime.getSharedName());
        cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC, "-l" + cxxRuntime.getStaticName());
    }
    CxxPlatform cxxPlatform = cxxPlatformBuilder.build();
    NdkCxxPlatform.Builder builder = NdkCxxPlatform.builder();
    builder.setCxxPlatform(cxxPlatform).setCxxRuntime(cxxRuntime).setObjdump(getGccTool(toolchainPaths, "objdump", version, executableFinder));
    if (cxxRuntime != CxxRuntime.SYSTEM) {
        builder.setCxxSharedRuntimePath(toolchainPaths.getCxxRuntimeLibsDirectory().resolve(cxxRuntime.getSoname()));
    }
    return builder.build();
}
Also used : ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) CompilerProvider(com.facebook.buck.cxx.CompilerProvider) GnuArchiver(com.facebook.buck.cxx.GnuArchiver) DefaultLinkerProvider(com.facebook.buck.cxx.DefaultLinkerProvider) HeaderVerification(com.facebook.buck.cxx.HeaderVerification) Path(java.nio.file.Path) ToolProvider(com.facebook.buck.rules.ToolProvider) CxxToolProvider(com.facebook.buck.cxx.CxxToolProvider) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) PrefixMapDebugPathSanitizer(com.facebook.buck.cxx.PrefixMapDebugPathSanitizer) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) MungingDebugPathSanitizer(com.facebook.buck.cxx.MungingDebugPathSanitizer) IOException(java.io.IOException) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) PreprocessorProvider(com.facebook.buck.cxx.PreprocessorProvider) CxxToolProvider(com.facebook.buck.cxx.CxxToolProvider) PosixNmSymbolNameTool(com.facebook.buck.cxx.PosixNmSymbolNameTool) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ToolProvider

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

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

Aggregations

ToolProvider (com.facebook.buck.rules.ToolProvider)6 ConstantToolProvider (com.facebook.buck.rules.ConstantToolProvider)4 Path (java.nio.file.Path)4 HashedFileTool (com.facebook.buck.rules.HashedFileTool)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 CompilerProvider (com.facebook.buck.cxx.CompilerProvider)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 CxxToolProvider (com.facebook.buck.cxx.CxxToolProvider)1 DefaultLinkerProvider (com.facebook.buck.cxx.DefaultLinkerProvider)1 GnuArchiver (com.facebook.buck.cxx.GnuArchiver)1 HeaderVerification (com.facebook.buck.cxx.HeaderVerification)1 MungingDebugPathSanitizer (com.facebook.buck.cxx.MungingDebugPathSanitizer)1 PosixNmSymbolNameTool (com.facebook.buck.cxx.PosixNmSymbolNameTool)1 PrefixMapDebugPathSanitizer (com.facebook.buck.cxx.PrefixMapDebugPathSanitizer)1 PreprocessorProvider (com.facebook.buck.cxx.PreprocessorProvider)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 IOException (java.io.IOException)1