Search in sources :

Example 26 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class AndroidBinaryGraphEnhancer method createAdditionalBuildables.

AndroidGraphEnhancementResult createAdditionalBuildables() throws NoSuchBuildTargetException {
    ImmutableSortedSet.Builder<BuildRule> enhancedDeps = ImmutableSortedSet.naturalOrder();
    enhancedDeps.addAll(originalDeps);
    ImmutableList.Builder<BuildRule> additionalJavaLibrariesBuilder = ImmutableList.builder();
    AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildTarget, buildTargetsToExcludeFromDex, resourcesToExclude, apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalDeps));
    AndroidPackageableCollection packageableCollection = collector.build();
    AndroidPackageableCollection.ResourceDetails resourceDetails = packageableCollection.getResourceDetails();
    AndroidNativeLibsGraphEnhancementResult nativeLibsEnhancementResult = nativeLibsEnhancer.enhance(packageableCollection);
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibraries = nativeLibsEnhancementResult.getCopyNativeLibraries();
    if (copyNativeLibraries.isPresent()) {
        ruleResolver.addAllToIndex(copyNativeLibraries.get().values());
        enhancedDeps.addAll(copyNativeLibraries.get().values());
    }
    Optional<ImmutableSortedMap<String, String>> sonameMergeMap = nativeLibsEnhancementResult.getSonameMergeMap();
    if (sonameMergeMap.isPresent() && nativeLibraryMergeCodeGenerator.isPresent()) {
        BuildRule generatorRule = ruleResolver.getRule(nativeLibraryMergeCodeGenerator.get());
        GenerateCodeForMergedLibraryMap generateCodeForMergedLibraryMap = new GenerateCodeForMergedLibraryMap(buildRuleParams.withAppendedFlavor(GENERATE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generatorRule)), Suppliers.ofInstance(ImmutableSortedSet.of())), sonameMergeMap.get(), generatorRule);
        ruleResolver.addToIndex(generateCodeForMergedLibraryMap);
        BuildRuleParams paramsForCompileGenCode = buildRuleParams.withAppendedFlavor(COMPILE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generateCodeForMergedLibraryMap)), Suppliers.ofInstance(ImmutableSortedSet.of()));
        DefaultJavaLibrary compileMergedNativeLibMapGenCode = new DefaultJavaLibrary(paramsForCompileGenCode, pathResolver, ruleFinder, ImmutableSet.of(generateCodeForMergedLibraryMap.getSourcePathToOutput()), /* resources */
        ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
        Optional.empty(), /* postprocessClassesCommands */
        ImmutableList.of(), /* exportedDeps */
        ImmutableSortedSet.of(), /* providedDeps */
        ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileGenCode.getDeps()), /* trackClassUsage */
        false, /* additionalClasspathEntries */
        ImmutableSet.of(), new JavacToJarStepFactory(// to 6 in their .buckconfig.
        javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
        Optional.empty(), /* manifest file */
        Optional.empty(), /* mavenCoords */
        Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
        ImmutableSet.of());
        ruleResolver.addToIndex(compileMergedNativeLibMapGenCode);
        additionalJavaLibrariesBuilder.add(compileMergedNativeLibMapGenCode);
        enhancedDeps.add(compileMergedNativeLibMapGenCode);
    }
    ImmutableSortedSet<BuildRule> resourceRules = getTargetsAsRules(resourceDetails.getResourcesWithNonEmptyResDir());
    ImmutableCollection<BuildRule> rulesWithResourceDirectories = ruleFinder.filterBuildRuleInputs(resourceDetails.getResourceDirectories());
    FilteredResourcesProvider filteredResourcesProvider;
    boolean needsResourceFiltering = resourceFilter.isEnabled() || resourceCompressionMode.isStoreStringsAsAssets() || !locales.isEmpty();
    if (needsResourceFiltering) {
        BuildRuleParams paramsForResourcesFilter = buildRuleParams.withAppendedFlavor(RESOURCES_FILTER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(resourceRules).addAll(rulesWithResourceDirectories).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        ResourcesFilter resourcesFilter = new ResourcesFilter(paramsForResourcesFilter, resourceDetails.getResourceDirectories(), ImmutableSet.copyOf(resourceDetails.getWhitelistedStringDirectories()), locales, resourceCompressionMode, resourceFilter);
        ruleResolver.addToIndex(resourcesFilter);
        filteredResourcesProvider = resourcesFilter;
        enhancedDeps.add(resourcesFilter);
        resourceRules = ImmutableSortedSet.of(resourcesFilter);
    } else {
        filteredResourcesProvider = new IdentityResourcesProvider(resourceDetails.getResourceDirectories().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()));
    }
    // Create the AaptPackageResourcesBuildable.
    BuildRuleParams paramsForAaptPackageResources = buildRuleParams.withAppendedFlavor(AAPT_PACKAGE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    AaptPackageResources aaptPackageResources = new AaptPackageResources(paramsForAaptPackageResources, ruleFinder, ruleResolver, manifest, filteredResourcesProvider, getTargetsAsResourceDeps(resourceDetails.getResourcesWithNonEmptyResDir()), getTargetsAsRules(resourceDetails.getResourcesWithEmptyResButNonEmptyAssetsDir()), packageableCollection.getAssetsDirectories(), resourceUnionPackage, shouldBuildStringSourceMap, skipCrunchPngs, includesVectorDrawables, bannedDuplicateResourceTypes, manifestEntries);
    ruleResolver.addToIndex(aaptPackageResources);
    enhancedDeps.add(aaptPackageResources);
    Optional<PackageStringAssets> packageStringAssets = Optional.empty();
    if (resourceCompressionMode.isStoreStringsAsAssets()) {
        BuildRuleParams paramsForPackageStringAssets = buildRuleParams.withAppendedFlavor(PACKAGE_STRING_ASSETS_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(resourceRules).addAll(rulesWithResourceDirectories).addAll(Iterables.filter(ImmutableList.of(filteredResourcesProvider), BuildRule.class)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        packageStringAssets = Optional.of(new PackageStringAssets(paramsForPackageStringAssets, locales, filteredResourcesProvider, aaptPackageResources));
        ruleResolver.addToIndex(packageStringAssets.get());
        enhancedDeps.add(packageStringAssets.get());
    }
    // already been added to the APK under test.
    if (packageType != PackageType.INSTRUMENTED) {
        ImmutableSortedSet<JavaLibrary> buildConfigDepsRules = addBuildConfigDeps(buildRuleParams, packageType, exopackageModes, buildConfigValues, buildConfigValuesFile, ruleResolver, javacOptions, packageableCollection);
        enhancedDeps.addAll(buildConfigDepsRules);
        additionalJavaLibrariesBuilder.addAll(buildConfigDepsRules);
    }
    ImmutableList<BuildRule> additionalJavaLibraries = additionalJavaLibrariesBuilder.build();
    ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> preDexedLibraries = ImmutableMultimap.of();
    if (shouldPreDex) {
        preDexedLibraries = createPreDexRulesForLibraries(// TODO(dreiss): Put R.java here.
        additionalJavaLibraries, packageableCollection);
    }
    // Create rule to trim uber R.java sources.
    Collection<DexProducedFromJavaLibrary> preDexedLibrariesForResourceIdFiltering = trimResourceIds ? preDexedLibraries.values() : ImmutableList.of();
    BuildRuleParams paramsForTrimUberRDotJava = buildRuleParams.withAppendedFlavor(TRIM_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(preDexedLibrariesForResourceIdFiltering).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    TrimUberRDotJava trimUberRDotJava = new TrimUberRDotJava(paramsForTrimUberRDotJava, aaptPackageResources, preDexedLibrariesForResourceIdFiltering, keepResourcePattern);
    ruleResolver.addToIndex(trimUberRDotJava);
    // Create rule to compile uber R.java sources.
    BuildRuleParams paramsForCompileUberRDotJava = buildRuleParams.withAppendedFlavor(COMPILE_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(trimUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    JavaLibrary compileUberRDotJava = new DefaultJavaLibrary(paramsForCompileUberRDotJava, pathResolver, ruleFinder, ImmutableSet.of(trimUberRDotJava.getSourcePathToOutput()), /* resources */
    ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), /* exportedDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    ImmutableSortedSet.of(), // we can just use its output as the ABI.
    JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileUberRDotJava.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new JavacToJarStepFactory(javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
    Optional.empty(), /* manifest file */
    Optional.empty(), /* mavenCoords */
    Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of());
    ruleResolver.addToIndex(compileUberRDotJava);
    // Create rule to dex uber R.java sources.
    BuildRuleParams paramsForDexUberRDotJava = buildRuleParams.withAppendedFlavor(DEX_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(compileUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
    DexProducedFromJavaLibrary dexUberRDotJava = new DexProducedFromJavaLibrary(paramsForDexUberRDotJava, compileUberRDotJava);
    ruleResolver.addToIndex(dexUberRDotJava);
    Optional<PreDexMerge> preDexMerge = Optional.empty();
    if (shouldPreDex) {
        preDexMerge = Optional.of(createPreDexMergeRule(preDexedLibraries, dexUberRDotJava));
        enhancedDeps.add(preDexMerge.get());
    } else {
        enhancedDeps.addAll(getTargetsAsRules(packageableCollection.getJavaLibrariesToDex()));
        // If not pre-dexing, AndroidBinary needs to ProGuard and/or dex the compiled R.java.
        enhancedDeps.add(compileUberRDotJava);
    }
    // Add dependencies on all the build rules generating third-party JARs.  This is mainly to
    // correctly capture deps when a prebuilt_jar forwards the output from another build rule.
    enhancedDeps.addAll(ruleFinder.filterBuildRuleInputs(packageableCollection.getPathsToThirdPartyJars()));
    Optional<ComputeExopackageDepsAbi> computeExopackageDepsAbi = Optional.empty();
    if (!exopackageModes.isEmpty()) {
        BuildRuleParams paramsForComputeExopackageAbi = buildRuleParams.withAppendedFlavor(CALCULATE_ABI_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(enhancedDeps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
        computeExopackageDepsAbi = Optional.of(new ComputeExopackageDepsAbi(paramsForComputeExopackageAbi, exopackageModes, packageableCollection, copyNativeLibraries, preDexMerge));
        ruleResolver.addToIndex(computeExopackageDepsAbi.get());
        enhancedDeps.add(computeExopackageDepsAbi.get());
    }
    return AndroidGraphEnhancementResult.builder().setPackageableCollection(packageableCollection).setAaptPackageResources(aaptPackageResources).setCompiledUberRDotJava(compileUberRDotJava).setCopyNativeLibraries(copyNativeLibraries).setPackageStringAssets(packageStringAssets).setPreDexMerge(preDexMerge).setComputeExopackageDepsAbi(computeExopackageDepsAbi).setClasspathEntriesToDex(ImmutableSet.<SourcePath>builder().addAll(packageableCollection.getClasspathEntriesToDex()).addAll(additionalJavaLibraries.stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList())).build()).setFinalDeps(enhancedDeps.build()).setAPKModuleGraph(apkModuleGraph).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) JavacToJarStepFactory(com.facebook.buck.jvm.java.JavacToJarStepFactory) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary)

Example 27 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class ConcatStep method getDescription.

@Override
public String getDescription(ExecutionContext context) {
    ImmutableList<Path> list = inputs.get();
    ImmutableList.Builder<String> desc = ImmutableList.builder();
    desc.add(getShortName());
    for (Path p : list) {
        desc.add(p.toString());
    }
    desc.add(">");
    desc.add(output.toString());
    return Joiner.on(" ").join(desc.build());
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList)

Example 28 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class AppleSdkDiscovery method buildSdkFromPath.

private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
    try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
        BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
        NSDictionary sdkSettings;
        try {
            sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
        } catch (PropertyListFormatException | ParseException | SAXException e) {
            LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
            return false;
        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        }
        String name = sdkSettings.objectForKey("CanonicalName").toString();
        String version = sdkSettings.objectForKey("Version").toString();
        NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
        Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
        boolean foundToolchain = false;
        if (!toolchains.isPresent()) {
            NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
            if (settingsToolchains != null) {
                toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
            }
        }
        if (toolchains.isPresent()) {
            for (String toolchainId : toolchains.get()) {
                AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
                if (toolchain != null) {
                    foundToolchain = true;
                    sdkBuilder.addToolchains(toolchain);
                } else {
                    LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
                }
            }
        }
        if (!foundToolchain && defaultToolchain.isPresent()) {
            foundToolchain = true;
            sdkBuilder.addToolchains(defaultToolchain.get());
        }
        if (!foundToolchain) {
            LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
            return false;
        } else {
            NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
            ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
            sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
            ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
            sdkBuilder.addAllArchitectures(architectures);
            return true;
        }
    } catch (NoSuchFileException e) {
        LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
        return false;
    }
}
Also used : NSArray(com.dd.plist.NSArray) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 29 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class AppleTest method getTestCommand.

public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand(ExecutionContext context, TestRunningOptions options, SourcePathResolver pathResolver, TestRule.TestReportingCallback testReportingCallback) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ExternalTestRunnerTestSpec.Builder externalSpec = ExternalTestRunnerTestSpec.builder().setTarget(getBuildTarget()).setLabels(getLabels()).setContacts(getContacts());
    Path resolvedTestBundleDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testBundle.getSourcePathToOutput()));
    Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
    Path resolvedTestLogsPath = getProjectFilesystem().resolve(testLogsPath);
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), resolvedTestLogsPath));
    Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath);
    Optional<Path> testHostAppPath = Optional.empty();
    if (testHostApp.isPresent()) {
        Path resolvedTestHostAppDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testHostApp.get().getSourcePathToOutput()));
        testHostAppPath = Optional.of(resolvedTestHostAppDirectory.resolve(testHostApp.get().getUnzippedOutputFilePathToBinary()));
    }
    if (!useXctest) {
        if (!xctool.isPresent()) {
            throw new HumanReadableException("Set xctool_path = /path/to/xctool or xctool_zip_target = //path/to:xctool-zip " + "in the [apple] section of .buckconfig to run this test");
        }
        ImmutableSet.Builder<Path> logicTestPathsBuilder = ImmutableSet.builder();
        ImmutableMap.Builder<Path, Path> appTestPathsToHostAppsBuilder = ImmutableMap.builder();
        if (testHostAppPath.isPresent()) {
            appTestPathsToHostAppsBuilder.put(resolvedTestBundleDirectory, testHostAppPath.get());
        } else {
            logicTestPathsBuilder.add(resolvedTestBundleDirectory);
        }
        xctoolStdoutReader = Optional.of(new AppleTestXctoolStdoutReader(testReportingCallback));
        Optional<String> destinationSpecifierArg;
        if (!destinationSpecifier.get().isEmpty()) {
            destinationSpecifierArg = Optional.of(Joiner.on(',').join(Iterables.transform(destinationSpecifier.get().entrySet(), input -> input.getKey() + "=" + input.getValue())));
        } else {
            destinationSpecifierArg = defaultDestinationSpecifier;
        }
        Optional<String> snapshotReferenceImagesPath = Optional.empty();
        if (this.snapshotReferenceImagesPath.isPresent()) {
            if (this.snapshotReferenceImagesPath.get().isLeft()) {
                snapshotReferenceImagesPath = Optional.of(pathResolver.getAbsolutePath(this.snapshotReferenceImagesPath.get().getLeft()).toString());
            } else if (this.snapshotReferenceImagesPath.get().isRight()) {
                snapshotReferenceImagesPath = Optional.of(getProjectFilesystem().getPathForRelativePath(this.snapshotReferenceImagesPath.get().getRight()).toString());
            }
        }
        XctoolRunTestsStep xctoolStep = new XctoolRunTestsStep(getProjectFilesystem(), pathResolver.getAbsolutePath(xctool.get()), options.getEnvironmentOverrides(), xctoolStutterTimeout, platformName, destinationSpecifierArg, logicTestPathsBuilder.build(), appTestPathsToHostAppsBuilder.build(), resolvedTestOutputPath, xctoolStdoutReader, xcodeDeveloperDirSupplier, options.getTestSelectorList(), context.isDebugEnabled(), Optional.of(testLogDirectoryEnvironmentVariable), Optional.of(resolvedTestLogsPath), Optional.of(testLogLevelEnvironmentVariable), Optional.of(testLogLevel), testRuleTimeoutMs, snapshotReferenceImagesPath);
        steps.add(xctoolStep);
        externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic"));
        externalSpec.setCommand(xctoolStep.getCommand());
        externalSpec.setEnv(xctoolStep.getEnv(context));
    } else {
        xctestOutputReader = Optional.of(new AppleTestXctestOutputReader(testReportingCallback));
        HashMap<String, String> environment = new HashMap<>();
        environment.putAll(xctest.getEnvironment(pathResolver));
        environment.putAll(options.getEnvironmentOverrides());
        if (testHostAppPath.isPresent()) {
            environment.put("XCInjectBundleInto", testHostAppPath.get().toString());
        }
        XctestRunTestsStep xctestStep = new XctestRunTestsStep(getProjectFilesystem(), ImmutableMap.copyOf(environment), xctest.getCommandPrefix(pathResolver), resolvedTestBundleDirectory, resolvedTestOutputPath, xctestOutputReader, xcodeDeveloperDirSupplier);
        steps.add(xctestStep);
        externalSpec.setType("xctest");
        externalSpec.setCommand(xctestStep.getCommand());
        externalSpec.setEnv(xctestStep.getEnv(context));
    }
    return new Pair<>(steps.build(), externalSpec.build());
}
Also used : Path(java.nio.file.Path) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) OptionalCompat(com.facebook.buck.util.OptionalCompat) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) TestResults(com.facebook.buck.test.TestResults) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Pair(com.facebook.buck.model.Pair) TestRule(com.facebook.buck.rules.TestRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableContext(com.facebook.buck.rules.BuildableContext) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) List(java.util.List) Stream(java.util.stream.Stream) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) Supplier(com.google.common.base.Supplier) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Label(com.facebook.buck.rules.Label) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) MoreCollectors(com.facebook.buck.util.MoreCollectors) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Files(java.nio.file.Files) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) InputStreamReader(java.io.InputStreamReader) BuildContext(com.facebook.buck.rules.BuildContext) Preconditions(com.google.common.base.Preconditions) BufferedReader(java.io.BufferedReader) BuildTargets(com.facebook.buck.model.BuildTargets) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Pair(com.facebook.buck.model.Pair)

Example 30 with ImmutableList

use of com.google.common.collect.ImmutableList in project buck by facebook.

the class AppleTestDescription method getXctool.

private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
    // can use that directly.
    if (appleConfig.getXctoolZipTarget().isPresent()) {
        final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
        BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
        final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
        if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
            BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
            resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {

                @Override
                public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
                    buildableContext.recordArtifact(outputDirectory);
                    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
                }

                @Override
                public SourcePath getSourcePathToOutput() {
                    return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
                }
            });
        }
        return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
    } else if (appleConfig.getXctoolPath().isPresent()) {
        return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
    } else {
        return Optional.empty();
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) UnzipStep(com.facebook.buck.zip.UnzipStep) ImmutableList(com.google.common.collect.ImmutableList) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) BuildableContext(com.facebook.buck.rules.BuildableContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)523 Path (java.nio.file.Path)128 List (java.util.List)105 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)77 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)65 IOException (java.io.IOException)62 ArrayList (java.util.ArrayList)60 Map (java.util.Map)59 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 ImmutableSet (com.google.common.collect.ImmutableSet)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 Optional (java.util.Optional)36 BuildRule (com.facebook.buck.rules.BuildRule)34