Search in sources :

Example 56 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class AppleCxxPlatforms method buildWithExecutableChecker.

@VisibleForTesting
static AppleCxxPlatform buildWithExecutableChecker(ProjectFilesystem filesystem, AppleSdk targetSdk, String minVersion, String targetArchitecture, final AppleSdkPaths sdkPaths, BuckConfig buckConfig, AppleConfig appleConfig, ExecutableFinder executableFinder, Optional<ProcessExecutor> processExecutor, Optional<AppleToolchain> swiftToolChain) {
    AppleCxxPlatform.Builder platformBuilder = AppleCxxPlatform.builder();
    ImmutableList.Builder<Path> toolSearchPathsBuilder = ImmutableList.builder();
    // Search for tools from most specific to least specific.
    toolSearchPathsBuilder.add(sdkPaths.getSdkPath().resolve(USR_BIN)).add(sdkPaths.getSdkPath().resolve("Developer").resolve(USR_BIN)).add(sdkPaths.getPlatformPath().resolve("Developer").resolve(USR_BIN));
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        toolSearchPathsBuilder.add(toolchainPath.resolve(USR_BIN));
    }
    if (sdkPaths.getDeveloperPath().isPresent()) {
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve(USR_BIN));
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve("Tools"));
    }
    // TODO(bhamiltoncx): Add more and better cflags.
    ImmutableList.Builder<String> cflagsBuilder = ImmutableList.builder();
    cflagsBuilder.add("-isysroot", sdkPaths.getSdkPath().toString());
    cflagsBuilder.add("-iquote", filesystem.getRootPath().toString());
    cflagsBuilder.add("-arch", targetArchitecture);
    cflagsBuilder.add(targetSdk.getApplePlatform().getMinVersionFlagPrefix() + minVersion);
    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        cflagsBuilder.add("-fembed-bitcode");
    }
    ImmutableList.Builder<String> ldflagsBuilder = ImmutableList.builder();
    ldflagsBuilder.addAll(Linkers.iXlinker("-sdk_version", targetSdk.getVersion(), "-ObjC"));
    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        ldflagsBuilder.addAll(Linkers.iXlinker("-bitcode_verify", "-bitcode_hide_symbols", "-bitcode_symbol_map"));
    }
    // Populate Xcode version keys from Xcode's own Info.plist if available.
    Optional<String> xcodeBuildVersion = Optional.empty();
    Optional<Path> developerPath = sdkPaths.getDeveloperPath();
    if (developerPath.isPresent()) {
        Path xcodeBundlePath = developerPath.get().getParent();
        if (xcodeBundlePath != null) {
            File xcodeInfoPlistPath = xcodeBundlePath.resolve("Info.plist").toFile();
            try {
                NSDictionary parsedXcodeInfoPlist = (NSDictionary) PropertyListParser.parse(xcodeInfoPlistPath);
                NSObject xcodeVersionObject = parsedXcodeInfoPlist.objectForKey("DTXcode");
                if (xcodeVersionObject != null) {
                    Optional<String> xcodeVersion = Optional.of(xcodeVersionObject.toString());
                    platformBuilder.setXcodeVersion(xcodeVersion);
                }
            } catch (IOException e) {
                LOG.warn("Error reading Xcode's info plist %s; ignoring Xcode versions", xcodeInfoPlistPath);
            } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
                LOG.warn("Error in parsing %s; ignoring Xcode versions", xcodeInfoPlistPath);
            }
        }
        // different than the build number in the Info.plist, sigh.
        if (processExecutor.isPresent()) {
            xcodeBuildVersion = appleConfig.getXcodeBuildVersionSupplier(developerPath.get(), processExecutor.get()).get();
            platformBuilder.setXcodeBuildVersion(xcodeBuildVersion);
            LOG.debug("Xcode build version is: " + xcodeBuildVersion.orElse("<absent>"));
        }
    }
    ImmutableList.Builder<String> versions = ImmutableList.builder();
    versions.add(targetSdk.getVersion());
    ImmutableList<String> toolchainVersions = targetSdk.getToolchains().stream().map(AppleToolchain::getVersion).flatMap(Optionals::toStream).collect(MoreCollectors.toImmutableList());
    if (toolchainVersions.isEmpty()) {
        if (!xcodeBuildVersion.isPresent()) {
            throw new HumanReadableException("Failed to read toolchain versions and Xcode version.");
        }
        versions.add(xcodeBuildVersion.get());
    } else {
        versions.addAll(toolchainVersions);
    }
    String version = Joiner.on(':').join(versions.build());
    ImmutableList<Path> toolSearchPaths = toolSearchPathsBuilder.build();
    Tool clangPath = VersionedTool.of(getToolPath("clang", toolSearchPaths, executableFinder), "apple-clang", version);
    Tool clangXxPath = VersionedTool.of(getToolPath("clang++", toolSearchPaths, executableFinder), "apple-clang++", version);
    Tool ar = VersionedTool.of(getToolPath("ar", toolSearchPaths, executableFinder), "apple-ar", version);
    Tool ranlib = VersionedTool.builder().setPath(getToolPath("ranlib", toolSearchPaths, executableFinder)).setName("apple-ranlib").setVersion(version).build();
    Tool strip = VersionedTool.of(getToolPath("strip", toolSearchPaths, executableFinder), "apple-strip", version);
    Tool nm = VersionedTool.of(getToolPath("nm", toolSearchPaths, executableFinder), "apple-nm", version);
    Tool actool = VersionedTool.of(getToolPath("actool", toolSearchPaths, executableFinder), "apple-actool", version);
    Tool ibtool = VersionedTool.of(getToolPath("ibtool", toolSearchPaths, executableFinder), "apple-ibtool", version);
    Tool momc = VersionedTool.of(getToolPath("momc", toolSearchPaths, executableFinder), "apple-momc", version);
    Tool xctest = VersionedTool.of(getToolPath("xctest", toolSearchPaths, executableFinder), "apple-xctest", version);
    Tool dsymutil = VersionedTool.of(getToolPath("dsymutil", toolSearchPaths, executableFinder), "apple-dsymutil", version);
    Tool lipo = VersionedTool.of(getToolPath("lipo", toolSearchPaths, executableFinder), "apple-lipo", version);
    Tool lldb = VersionedTool.of(getToolPath("lldb", toolSearchPaths, executableFinder), "lldb", version);
    Optional<Path> stubBinaryPath = targetSdk.getApplePlatform().getStubBinaryPath().map(input -> sdkPaths.getSdkPath().resolve(input));
    CxxBuckConfig config = new CxxBuckConfig(buckConfig);
    UserFlavor targetFlavor = UserFlavor.of(Flavor.replaceInvalidCharacters(targetSdk.getName() + "-" + targetArchitecture), String.format("SDK: %s, architecture: %s", targetSdk.getName(), targetArchitecture));
    ImmutableBiMap.Builder<Path, Path> sanitizerPaths = ImmutableBiMap.builder();
    sanitizerPaths.put(sdkPaths.getSdkPath(), Paths.get("APPLE_SDKROOT"));
    sanitizerPaths.put(sdkPaths.getPlatformPath(), Paths.get("APPLE_PLATFORM_DIR"));
    if (sdkPaths.getDeveloperPath().isPresent()) {
        sanitizerPaths.put(sdkPaths.getDeveloperPath().get(), Paths.get("APPLE_DEVELOPER_DIR"));
    }
    DebugPathSanitizer compilerDebugPathSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.CLANG, filesystem);
    DebugPathSanitizer assemblerDebugPathSanitizer = new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build());
    ImmutableList<String> cflags = cflagsBuilder.build();
    ImmutableMap.Builder<String, String> macrosBuilder = ImmutableMap.builder();
    macrosBuilder.put("SDKROOT", sdkPaths.getSdkPath().toString());
    macrosBuilder.put("PLATFORM_DIR", sdkPaths.getPlatformPath().toString());
    macrosBuilder.put("CURRENT_ARCH", targetArchitecture);
    if (sdkPaths.getDeveloperPath().isPresent()) {
        macrosBuilder.put("DEVELOPER_DIR", sdkPaths.getDeveloperPath().get().toString());
    }
    ImmutableMap<String, String> macros = macrosBuilder.build();
    Optional<String> buildVersion = Optional.empty();
    Path platformVersionPlistPath = sdkPaths.getPlatformPath().resolve("version.plist");
    try (InputStream versionPlist = Files.newInputStream(platformVersionPlistPath)) {
        NSDictionary versionInfo = (NSDictionary) PropertyListParser.parse(versionPlist);
        if (versionInfo != null) {
            NSObject productBuildVersion = versionInfo.objectForKey("ProductBuildVersion");
            if (productBuildVersion != null) {
                buildVersion = Optional.of(productBuildVersion.toString());
            } else {
                LOG.warn("In %s, missing ProductBuildVersion. Build version will be unset for this platform.", platformVersionPlistPath);
            }
        } else {
            LOG.warn("Empty version plist in %s. Build version will be unset for this platform.", platformVersionPlistPath);
        }
    } catch (NoSuchFileException e) {
        LOG.warn("%s does not exist. Build version will be unset for this platform.", platformVersionPlistPath);
    } catch (PropertyListFormatException | SAXException | ParserConfigurationException | ParseException | IOException e) {
        // Some other error occurred, print the exception since it may contain error details.
        LOG.warn(e, "Failed to parse %s. Build version will be unset for this platform.", platformVersionPlistPath);
    }
    PreprocessorProvider aspp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    CompilerProvider as = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cpp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    CompilerProvider cc = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cxxpp = new PreprocessorProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
    CompilerProvider cxx = new CompilerProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
    ImmutableList.Builder<String> whitelistBuilder = ImmutableList.builder();
    whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getSdkPath().toString()) + "\\/.*");
    whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getPlatformPath().toString() + "/Developer/Library/Frameworks") + "\\/.*");
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        LOG.debug("Apple toolchain path: %s", toolchainPath);
        try {
            whitelistBuilder.add("^" + Pattern.quote(toolchainPath.toRealPath().toString()) + "\\/.*");
        } catch (IOException e) {
            LOG.warn(e, "Apple toolchain path could not be resolved: %s", toolchainPath);
        }
    }
    HeaderVerification headerVerification = config.getHeaderVerification().withPlatformWhitelist(whitelistBuilder.build());
    LOG.debug("Headers verification platform whitelist: %s", headerVerification.getPlatformWhitelist());
    CxxPlatform cxxPlatform = CxxPlatforms.build(targetFlavor, Platform.MACOS, config, as, aspp, cc, cxx, cpp, cxxpp, new DefaultLinkerProvider(LinkerProvider.Type.DARWIN, new ConstantToolProvider(clangXxPath)), ImmutableList.<String>builder().addAll(cflags).addAll(ldflagsBuilder.build()).build(), strip, new BsdArchiver(ar), ranlib, new PosixNmSymbolNameTool(nm), cflagsBuilder.build(), ImmutableList.of(), cflags, ImmutableList.of(), "dylib", "%s.dylib", "a", "o", compilerDebugPathSanitizer, assemblerDebugPathSanitizer, macros, Optional.empty(), headerVerification);
    ApplePlatform applePlatform = targetSdk.getApplePlatform();
    ImmutableList.Builder<Path> swiftOverrideSearchPathBuilder = ImmutableList.builder();
    AppleSdkPaths.Builder swiftSdkPathsBuilder = AppleSdkPaths.builder().from(sdkPaths);
    if (swiftToolChain.isPresent()) {
        swiftOverrideSearchPathBuilder.add(swiftToolChain.get().getPath().resolve(USR_BIN));
        swiftSdkPathsBuilder.setToolchainPaths(ImmutableList.of(swiftToolChain.get().getPath()));
    }
    Optional<SwiftPlatform> swiftPlatform = getSwiftPlatform(applePlatform.getName(), targetArchitecture + "-apple-" + applePlatform.getSwiftName().orElse(applePlatform.getName()) + minVersion, version, swiftSdkPathsBuilder.build(), swiftOverrideSearchPathBuilder.addAll(toolSearchPaths).build(), executableFinder);
    platformBuilder.setCxxPlatform(cxxPlatform).setSwiftPlatform(swiftPlatform).setAppleSdk(targetSdk).setAppleSdkPaths(sdkPaths).setMinVersion(minVersion).setBuildVersion(buildVersion).setActool(actool).setIbtool(ibtool).setMomc(momc).setCopySceneKitAssets(getOptionalTool("copySceneKitAssets", toolSearchPaths, executableFinder, version)).setXctest(xctest).setDsymutil(dsymutil).setLipo(lipo).setStubBinary(stubBinaryPath).setLldb(lldb).setCodesignAllocate(getOptionalTool("codesign_allocate", toolSearchPaths, executableFinder, version)).setCodesignProvider(appleConfig.getCodesignProvider());
    return platformBuilder.build();
}
Also used : NSDictionary(com.dd.plist.NSDictionary) NoSuchFileException(java.nio.file.NoSuchFileException) CompilerProvider(com.facebook.buck.cxx.CompilerProvider) SAXException(org.xml.sax.SAXException) DefaultLinkerProvider(com.facebook.buck.cxx.DefaultLinkerProvider) MungingDebugPathSanitizer(com.facebook.buck.cxx.MungingDebugPathSanitizer) DebugPathSanitizer(com.facebook.buck.cxx.DebugPathSanitizer) PrefixMapDebugPathSanitizer(com.facebook.buck.cxx.PrefixMapDebugPathSanitizer) VersionedTool(com.facebook.buck.rules.VersionedTool) PosixNmSymbolNameTool(com.facebook.buck.cxx.PosixNmSymbolNameTool) Tool(com.facebook.buck.rules.Tool) BsdArchiver(com.facebook.buck.cxx.BsdArchiver) MungingDebugPathSanitizer(com.facebook.buck.cxx.MungingDebugPathSanitizer) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyListFormatException(com.dd.plist.PropertyListFormatException) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) PreprocessorProvider(com.facebook.buck.cxx.PreprocessorProvider) File(java.io.File) PosixNmSymbolNameTool(com.facebook.buck.cxx.PosixNmSymbolNameTool) SwiftPlatform(com.facebook.buck.swift.SwiftPlatform) NSObject(com.dd.plist.NSObject) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) ImmutableList(com.google.common.collect.ImmutableList) HeaderVerification(com.facebook.buck.cxx.HeaderVerification) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Path(java.nio.file.Path) PrefixMapDebugPathSanitizer(com.facebook.buck.cxx.PrefixMapDebugPathSanitizer) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) InputStream(java.io.InputStream) IOException(java.io.IOException) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) HumanReadableException(com.facebook.buck.util.HumanReadableException) UserFlavor(com.facebook.buck.model.UserFlavor) ParseException(java.text.ParseException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 57 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class AppleDescriptions method createBuildRuleForTransitiveAssetCatalogDependencies.

public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver, ApplePlatform applePlatform, Tool actool) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
    ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));
    ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();
    Optional<String> appIcon = Optional.empty();
    Optional<String> launchImage = Optional.empty();
    AppleAssetCatalogDescription.Optimization optimization = null;
    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        if (optimization == null) {
            optimization = arg.optimization;
        }
        assetCatalogDirsBuilder.addAll(arg.dirs);
        if (arg.appIcon.isPresent()) {
            if (appIcon.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a app_icon", params.getBuildTarget());
            }
            appIcon = arg.appIcon;
        }
        if (arg.launchImage.isPresent()) {
            if (launchImage.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a launch_image", params.getBuildTarget());
            }
            launchImage = arg.launchImage;
        }
        if (arg.optimization != optimization) {
            throw new HumanReadableException("At most one asset catalog optimisation style can be " + "specified in the dependencies %s", params.getBuildTarget());
        }
    }
    ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();
    if (assetCatalogDirs.isEmpty()) {
        return Optional.empty();
    }
    Preconditions.checkNotNull(optimization, "optimization was null even though assetCatalogArgs was not empty");
    for (SourcePath assetCatalogDir : assetCatalogDirs) {
        Path baseName = sourcePathResolver.getRelativePath(assetCatalogDir).getFileName();
        if (!baseName.toString().endsWith(".xcassets")) {
            throw new HumanReadableException("Target %s had asset catalog dir %s - asset catalog dirs must end with .xcassets", params.getBuildTarget(), assetCatalogDir);
        }
    }
    BuildRuleParams assetCatalogParams = params.withAppendedFlavor(AppleAssetCatalog.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    return Optional.of(new AppleAssetCatalog(assetCatalogParams, applePlatform.getName(), actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet)

Example 58 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class PreDexMerge method addStepsForSplitDex.

private void addStepsForSplitDex(ImmutableList.Builder<Step> steps, BuildableContext buildableContext) {
    // Collect all of the DexWithClasses objects to use for merging.
    ImmutableMultimap.Builder<APKModule, DexWithClasses> dexFilesToMergeBuilder = ImmutableMultimap.builder();
    dexFilesToMergeBuilder.putAll(FluentIterable.from(preDexDeps.entries()).transform(input -> new AbstractMap.SimpleEntry<>(input.getKey(), DexWithClasses.TO_DEX_WITH_CLASSES.apply(input.getValue()))).filter(input -> input.getValue() != null).toSet());
    final SplitDexPaths paths = new SplitDexPaths();
    final ImmutableSet.Builder<Path> secondaryDexDirectories = ImmutableSet.builder();
    if (dexSplitMode.getDexStore() == DexStore.RAW) {
        // Raw classes*.dex files go in the top-level of the APK.
        secondaryDexDirectories.add(paths.jarfilesSubdir);
    } else {
        // Otherwise, we want to include the metadata and jars as assets.
        secondaryDexDirectories.add(paths.metadataDir);
        secondaryDexDirectories.add(paths.jarfilesDir);
    }
    //always add additional dex stores and metadata as assets
    secondaryDexDirectories.add(paths.additionalJarfilesDir);
    // Do not clear existing directory which might contain secondary dex files that are not
    // re-merged (since their contents did not change).
    steps.add(new MkdirStep(getProjectFilesystem(), paths.jarfilesSubdir));
    steps.add(new MkdirStep(getProjectFilesystem(), paths.additionalJarfilesSubdir));
    steps.add(new MkdirStep(getProjectFilesystem(), paths.successDir));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.metadataSubdir));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.scratchDir));
    buildableContext.addMetadata(SECONDARY_DEX_DIRECTORIES_KEY, secondaryDexDirectories.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
    buildableContext.recordArtifact(primaryDexPath);
    buildableContext.recordArtifact(paths.jarfilesSubdir);
    buildableContext.recordArtifact(paths.metadataSubdir);
    buildableContext.recordArtifact(paths.successDir);
    buildableContext.recordArtifact(paths.additionalJarfilesSubdir);
    PreDexedFilesSorter preDexedFilesSorter = new PreDexedFilesSorter(Optional.ofNullable(DexWithClasses.TO_DEX_WITH_CLASSES.apply(dexForUberRDotJava)), dexFilesToMergeBuilder.build(), dexSplitMode.getPrimaryDexPatterns(), apkModuleGraph, paths.scratchDir, // to set the dex weight limit during pre-dex merging.
    dexSplitMode.getLinearAllocHardLimit(), dexSplitMode.getDexStore(), paths.jarfilesSubdir, paths.additionalJarfilesSubdir);
    final ImmutableMap<String, PreDexedFilesSorter.Result> sortResults = preDexedFilesSorter.sortIntoPrimaryAndSecondaryDexes(getProjectFilesystem(), steps);
    PreDexedFilesSorter.Result rootApkModuleResult = sortResults.get(APKModuleGraph.ROOT_APKMODULE_NAME);
    if (rootApkModuleResult == null) {
        throw new HumanReadableException("No classes found in primary or secondary dexes");
    }
    Multimap<Path, Path> aggregatedOutputToInputs = HashMultimap.create();
    ImmutableMap.Builder<Path, Sha1HashCode> dexInputHashesBuilder = ImmutableMap.builder();
    for (PreDexedFilesSorter.Result result : sortResults.values()) {
        if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
            Path dexOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName());
            steps.add(new MkdirStep(getProjectFilesystem(), dexOutputPath));
        }
        aggregatedOutputToInputs.putAll(result.secondaryOutputToInputs);
        dexInputHashesBuilder.putAll(result.dexInputHashes);
    }
    final ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesBuilder.build();
    steps.add(new SmartDexingStep(getProjectFilesystem(), primaryDexPath, Suppliers.ofInstance(rootApkModuleResult.primaryDexInputs), Optional.of(paths.jarfilesSubdir), Optional.of(Suppliers.ofInstance(aggregatedOutputToInputs)), () -> dexInputHashes, paths.successDir, DX_MERGE_OPTIONS, dxExecutorService, xzCompressionLevel, dxMaxHeapSize));
    // Record the primary dex SHA1 so exopackage apks can use it to compute their ABI keys.
    // Single dex apks cannot be exopackages, so they will never need ABI keys.
    steps.add(new RecordFileSha1Step(getProjectFilesystem(), primaryDexPath, PRIMARY_DEX_HASH_KEY, buildableContext));
    for (PreDexedFilesSorter.Result result : sortResults.values()) {
        if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
            Path dexMetadataOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName()).resolve("metadata.txt");
            addMetadataWriteStep(result, steps, dexMetadataOutputPath);
        }
    }
    addMetadataWriteStep(rootApkModuleResult, steps, paths.metadataFile);
}
Also used : Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Multimap(com.google.common.collect.Multimap) BuildOutput(com.facebook.buck.android.PreDexMerge.BuildOutput) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) BuildOutputInitializer(com.facebook.buck.rules.BuildOutputInitializer) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap) InitializableFromDisk(com.facebook.buck.rules.InitializableFromDisk) BuildableContext(com.facebook.buck.rules.BuildableContext) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) OnDiskBuildInfo(com.facebook.buck.rules.OnDiskBuildInfo) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) List(java.util.List) Paths(java.nio.file.Paths) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) BuildContext(com.facebook.buck.rules.BuildContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BuildTargets(com.facebook.buck.model.BuildTargets) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Collections(java.util.Collections) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MkdirStep(com.facebook.buck.step.fs.MkdirStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableMap(com.google.common.collect.ImmutableMap) HumanReadableException(com.facebook.buck.util.HumanReadableException) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 59 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class AppleDescriptions method getFlavoredBinaryRule.

private static BuildRule getFlavoredBinaryRule(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, TargetGraph targetGraph, ImmutableSet<Flavor> flavors, BuildRuleResolver resolver, BuildTarget binary) throws NoSuchBuildTargetException {
    // Don't flavor genrule deps.
    if (targetGraph.get(binary).getDescription() instanceof AbstractGenruleDescription) {
        return resolver.requireRule(binary);
    }
    // Cxx targets must have one Platform Flavor set otherwise nothing gets compiled.
    if (flavors.contains(AppleDescriptions.FRAMEWORK_FLAVOR)) {
        flavors = ImmutableSet.<Flavor>builder().addAll(flavors).add(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    }
    flavors = ImmutableSet.copyOf(Sets.difference(flavors, ImmutableSet.of(AppleDescriptions.FRAMEWORK_FLAVOR, AppleBinaryDescription.APP_FLAVOR)));
    if (!cxxPlatformFlavorDomain.containsAnyOf(flavors)) {
        flavors = new ImmutableSet.Builder<Flavor>().addAll(flavors).add(defaultCxxPlatform.getFlavor()).build();
    }
    BuildTarget.Builder buildTargetBuilder = BuildTarget.builder(binary.getUnflavoredBuildTarget()).addAllFlavors(flavors);
    if (!(AppleLibraryDescription.LIBRARY_TYPE.getFlavor(flavors).isPresent())) {
        buildTargetBuilder.addAllFlavors(binary.getFlavors());
    } else {
        buildTargetBuilder.addAllFlavors(Sets.difference(binary.getFlavors(), AppleLibraryDescription.LIBRARY_TYPE.getFlavors()));
    }
    BuildTarget buildTarget = buildTargetBuilder.build();
    final TargetNode<?, ?> binaryTargetNode = targetGraph.get(buildTarget);
    if (binaryTargetNode.getDescription() instanceof AppleTestDescription) {
        return resolver.getRule(binary);
    }
    // must be specified.
    if (binaryTargetNode.getDescription() instanceof AppleLibraryDescription && (Sets.intersection(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS, buildTarget.getFlavors()).size() != 1)) {
        throw new HumanReadableException("AppleExtension bundle [%s] must have exactly one of these flavors: [%s].", binaryTargetNode.getBuildTarget().toString(), Joiner.on(", ").join(AppleBundleDescription.SUPPORTED_LIBRARY_FLAVORS));
    }
    if (!StripStyle.FLAVOR_DOMAIN.containsAnyOf(buildTarget.getFlavors())) {
        buildTarget = buildTarget.withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
    }
    return resolver.requireRule(buildTarget);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) AbstractGenruleDescription(com.facebook.buck.shell.AbstractGenruleDescription) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 60 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class AppleDescriptions method convertToFlatCxxHeaders.

/**
   * Convert {@link SourcePath} to a mapping of {@code include path -> file path}.
   * <p/>
   * {@code include path} is the path that can be referenced in {@code #include} directives.
   * {@code file path} is the actual path to the file on disk.
   *
   * @throws HumanReadableException when two {@code SourcePath} yields the same IncludePath.
   */
@VisibleForTesting
static ImmutableSortedMap<String, SourcePath> convertToFlatCxxHeaders(Path headerPathPrefix, Function<SourcePath, Path> sourcePathResolver, Set<SourcePath> headerPaths) {
    Set<String> includeToFile = new HashSet<String>(headerPaths.size());
    ImmutableSortedMap.Builder<String, SourcePath> builder = ImmutableSortedMap.naturalOrder();
    for (SourcePath headerPath : headerPaths) {
        Path fileName = sourcePathResolver.apply(headerPath).getFileName();
        String key = headerPathPrefix.resolve(fileName).toString();
        if (includeToFile.contains(key)) {
            ImmutableSortedMap<String, SourcePath> result = builder.build();
            throw new HumanReadableException("The same include path maps to multiple files:\n" + "  Include path: %s\n" + "  Conflicting files:\n" + "    %s\n" + "    %s", key, headerPath, result.get(key));
        }
        includeToFile.add(key);
        builder.put(key, headerPath);
    }
    return builder.build();
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15