Search in sources :

Example 51 with ImmutableMap

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

the class AppleDescriptions method collectFirstLevelAppleDependencyBundles.

private static ImmutableMap<SourcePath, String> collectFirstLevelAppleDependencyBundles(ImmutableSortedSet<BuildRule> deps, AppleBundleDestinations destinations) {
    ImmutableMap.Builder<SourcePath, String> extensionBundlePaths = ImmutableMap.builder();
    // do not get pulled in to the top-level Bundle.
    for (BuildRule rule : deps) {
        if (rule instanceof AppleBundle) {
            AppleBundle appleBundle = (AppleBundle) rule;
            SourcePath sourcePath = Preconditions.checkNotNull(appleBundle.getSourcePathToOutput(), "Path cannot be null for AppleBundle [%s].", appleBundle);
            if (AppleBundleExtension.APPEX.toFileExtension().equals(appleBundle.getExtension()) || AppleBundleExtension.APP.toFileExtension().equals(appleBundle.getExtension())) {
                Path destinationPath;
                String platformName = appleBundle.getPlatformName();
                if ((platformName.equals(ApplePlatform.WATCHOS.getName()) || platformName.equals(ApplePlatform.WATCHSIMULATOR.getName())) && appleBundle.getExtension().equals(AppleBundleExtension.APP.toFileExtension())) {
                    destinationPath = destinations.getWatchAppPath();
                } else if (appleBundle.isLegacyWatchApp()) {
                    destinationPath = destinations.getResourcesPath();
                } else {
                    destinationPath = destinations.getPlugInsPath();
                }
                extensionBundlePaths.put(sourcePath, destinationPath.toString());
            } else if (AppleBundleExtension.FRAMEWORK.toFileExtension().equals(appleBundle.getExtension())) {
                extensionBundlePaths.put(sourcePath, destinations.getFrameworksPath().toString());
            }
        }
    }
    return extensionBundlePaths.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) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 52 with ImmutableMap

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

the class MergeAndroidResourcesStep method doExecute.

private void doExecute() throws IOException, DuplicateResourceException {
    // In order to convert a symbols file to R.java, all resources of the same type are grouped
    // into a static class of that name. The static class contains static values that correspond to
    // the resource (type, name, value) tuples. See RDotTxtEntry.
    //
    // The first step is to merge symbol files of the same package type and resource type/name.
    // That is, within a package type, each resource type/name pair must be unique. If there are
    // multiple pairs, only one will be written to the R.java file.
    //
    // Because the resulting files do not match their respective resources.arsc, the values are
    // meaningless and do not represent the usable final result.  This is why the R.java file is
    // written without using final so that javac will not inline the values.  Unfortunately,
    // though Robolectric doesn't read resources.arsc, it does assert that all the R.java resource
    // ids are unique.  This forces us to re-enumerate new unique ids.
    ImmutableMap.Builder<Path, String> rDotTxtToPackage = ImmutableMap.builder();
    ImmutableMap.Builder<Path, HasAndroidResourceDeps> symbolsFileToResourceDeps = ImmutableMap.builder();
    for (HasAndroidResourceDeps res : androidResourceDeps) {
        // TODO(shs96c): These have to be absolute for this all to work with multi-repo.
        // This is because each `androidResourceDeps` might be from a different repo, so we can't
        // assume that they exist in the calling rule's projectfilesystem.
        Path rDotTxtPath = pathResolver.getRelativePath(res.getPathToTextSymbolsFile());
        rDotTxtToPackage.put(rDotTxtPath, res.getRDotJavaPackage());
        symbolsFileToResourceDeps.put(rDotTxtPath, res);
    }
    Optional<ImmutableMap<RDotTxtEntry, String>> uberRDotTxtIds;
    if (uberRDotTxt.isPresent()) {
        // re-assign Ids
        uberRDotTxtIds = Optional.of(FluentIterable.from(RDotTxtEntry.readResources(filesystem, uberRDotTxt.get())).toMap(input -> input.idValue));
    } else {
        uberRDotTxtIds = Optional.empty();
    }
    ImmutableMap<Path, String> symbolsFileToRDotJavaPackage = rDotTxtToPackage.build();
    SortedSetMultimap<String, RDotTxtEntry> rDotJavaPackageToResources = sortSymbols(symbolsFileToRDotJavaPackage, uberRDotTxtIds, symbolsFileToResourceDeps.build(), bannedDuplicateResourceTypes, filesystem, useOldStyleableFormat);
    // unless they are already present.
    if (unionPackage.isPresent()) {
        String unionPackageName = unionPackage.get();
        // Create a temporary list to avoid concurrent modification problems.
        for (Map.Entry<String, RDotTxtEntry> entry : new ArrayList<>(rDotJavaPackageToResources.entries())) {
            if (rDotJavaPackageToResources.containsEntry(unionPackageName, entry.getValue())) {
                continue;
            }
            rDotJavaPackageToResources.put(unionPackageName, entry.getValue());
        }
    }
    writePerPackageRDotJava(rDotJavaPackageToResources, filesystem);
    Set<String> emptyPackages = Sets.difference(ImmutableSet.copyOf(symbolsFileToRDotJavaPackage.values()), rDotJavaPackageToResources.keySet());
    if (!emptyPackages.isEmpty()) {
        writeEmptyRDotJavaForPackages(emptyPackages, filesystem);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) RDotTxtEntry(com.facebook.buck.android.aapt.RDotTxtEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 53 with ImmutableMap

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

the class MiniAapt method getResourceTypes.

private static ImmutableMap<String, RType> getResourceTypes() {
    ImmutableMap.Builder<String, RType> types = ImmutableMap.builder();
    for (RType rType : RType.values()) {
        types.put(rType.toString(), rType);
    }
    types.put("string-array", RType.ARRAY);
    types.put("integer-array", RType.ARRAY);
    types.put("declare-styleable", RType.STYLEABLE);
    return types.build();
}
Also used : RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 54 with ImmutableMap

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

the class JavaBuildGraphProcessor method run.

/**
   * Creates the appropriate target graph and other resources needed for the {@link Processor} and
   * runs it. This method will take responsibility for cleaning up the executor service after it
   * runs.
   */
static void run(final CommandRunnerParams params, final AbstractCommand command, final Processor processor) throws ExitCodeException, InterruptedException, IOException {
    final ConcurrencyLimit concurrencyLimit = command.getConcurrencyLimit(params.getBuckConfig());
    try (CommandThreadManager pool = new CommandThreadManager(command.getClass().getName(), concurrencyLimit)) {
        Cell cell = params.getCell();
        WeightedListeningExecutorService executorService = pool.getExecutor();
        // Ideally, we should be able to construct the TargetGraph quickly assuming most of it is
        // already in memory courtesy of buckd. Though we could make a performance optimization where
        // we pass an option to buck.py that tells it to ignore reading the BUCK.autodeps files when
        // parsing the BUCK files because we never need to consider the existing auto-generated deps
        // when creating the new auto-generated deps. If we did so, we would have to make sure to keep
        // the nodes for that version of the graph separate from the ones that are actually used for
        // building.
        TargetGraph graph;
        try {
            graph = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), cell, command.getEnableParserProfiling(), executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), cell.getRoot()))), /* ignoreBuckAutodepsFiles */
            true).getTargetGraph();
        } catch (BuildTargetException | BuildFileParseException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            throw new ExitCodeException(1);
        }
        BuildRuleResolver buildRuleResolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        LocalCachingBuildEngineDelegate cachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
        BuildEngine buildEngine = new CachingBuildEngine(cachingBuildEngineDelegate, executorService, executorService, new DefaultStepRunner(), CachingBuildEngine.BuildMode.SHALLOW, cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), buildRuleResolver, cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> cachingBuildEngineDelegate.getFileHashCache(), buildRuleResolver, cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), new DefaultRuleKeyCache<>()));
        // Create a BuildEngine because we store symbol information as build artifacts.
        BuckEventBus eventBus = params.getBuckEventBus();
        ExecutionContext executionContext = ExecutionContext.builder().setConsole(params.getConsole()).setConcurrencyLimit(concurrencyLimit).setBuckEventBus(eventBus).setEnvironment(/* environment */
        ImmutableMap.of()).setExecutors(ImmutableMap.<ExecutorPool, ListeningExecutorService>of(ExecutorPool.CPU, executorService)).setJavaPackageFinder(params.getJavaPackageFinder()).setObjectMapper(params.getObjectMapper()).setPlatform(params.getPlatform()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
        SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
        BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(executionContext.getJavaPackageFinder()).setEventBus(eventBus).build()).setClock(params.getClock()).setArtifactCache(params.getArtifactCacheFactory().newInstance()).setBuildId(eventBus.getBuildId()).setObjectMapper(params.getObjectMapper()).setEnvironment(executionContext.getEnvironment()).setKeepGoing(false).build();
        // Traverse the TargetGraph to find all of the auto-generated dependencies.
        JavaDepsFinder javaDepsFinder = JavaDepsFinder.createJavaDepsFinder(params.getBuckConfig(), params.getCell().getCellPathResolver(), params.getObjectMapper(), buildContext, executionContext, buildEngine);
        processor.process(graph, javaDepsFinder, executorService);
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ActionGraph(com.facebook.buck.rules.ActionGraph) TargetNodePredicateSpec(com.facebook.buck.parser.TargetNodePredicateSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) MoreExceptions(com.facebook.buck.util.MoreExceptions) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Cell(com.facebook.buck.rules.Cell) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) BuildFileSpec(com.facebook.buck.parser.BuildFileSpec) DefaultRuleKeyCache(com.facebook.buck.rules.keys.DefaultRuleKeyCache) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTargetException(com.facebook.buck.model.BuildTargetException) IOException(java.io.IOException) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) JavaDepsFinder(com.facebook.buck.jvm.java.autodeps.JavaDepsFinder) BuildEngineBuildContext(com.facebook.buck.rules.BuildEngineBuildContext) Paths(java.nio.file.Paths) ExecutorPool(com.facebook.buck.step.ExecutorPool) BuildEngine(com.facebook.buck.rules.BuildEngine) BuildContext(com.facebook.buck.rules.BuildContext) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BuckEventBus(com.facebook.buck.event.BuckEventBus) JavaDepsFinder(com.facebook.buck.jvm.java.autodeps.JavaDepsFinder) DefaultRuleKeyCache(com.facebook.buck.rules.keys.DefaultRuleKeyCache) TargetGraph(com.facebook.buck.rules.TargetGraph) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) BuildEngineBuildContext(com.facebook.buck.rules.BuildEngineBuildContext) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Cell(com.facebook.buck.rules.Cell) BuildTargetException(com.facebook.buck.model.BuildTargetException) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) ActionGraph(com.facebook.buck.rules.ActionGraph) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) BuildEngine(com.facebook.buck.rules.BuildEngine) ExecutionContext(com.facebook.buck.step.ExecutionContext) ExecutorPool(com.facebook.buck.step.ExecutorPool) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 55 with ImmutableMap

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

the class BuckConfig method getResourceAmountsPerRuleType.

public ImmutableMap<String, ResourceAmounts> getResourceAmountsPerRuleType() {
    ImmutableMap.Builder<String, ResourceAmounts> result = ImmutableMap.builder();
    ImmutableMap<String, String> entries = getEntriesForSection(RESOURCES_PER_RULE_SECTION_HEADER);
    for (String ruleName : entries.keySet()) {
        ImmutableList<String> configAmounts = getListWithoutComments(RESOURCES_PER_RULE_SECTION_HEADER, ruleName);
        Preconditions.checkArgument(configAmounts.size() == ResourceAmounts.RESOURCE_TYPE_COUNT, "Buck config entry [%s].%s contains %s values, but expected to contain %s values " + "in the following order: cpu, memory, disk_io, network_io", RESOURCES_PER_RULE_SECTION_HEADER, ruleName, configAmounts.size(), ResourceAmounts.RESOURCE_TYPE_COUNT);
        ResourceAmounts amounts = ResourceAmounts.of(Integer.valueOf(configAmounts.get(0)), Integer.valueOf(configAmounts.get(1)), Integer.valueOf(configAmounts.get(2)), Integer.valueOf(configAmounts.get(3)));
        result.put(ruleName, amounts);
    }
    return result.build();
}
Also used : ResourceAmounts(com.facebook.buck.util.concurrent.ResourceAmounts) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)702 Map (java.util.Map)346 Test (org.junit.Test)195 HashMap (java.util.HashMap)144 ImmutableList (com.google.common.collect.ImmutableList)126 Path (java.nio.file.Path)104 List (java.util.List)100 ImmutableSet (com.google.common.collect.ImmutableSet)89 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)74 Set (java.util.Set)69 Optional (java.util.Optional)61 BuildTarget (com.facebook.buck.model.BuildTarget)57 File (java.io.File)57 Collectors (java.util.stream.Collectors)45 HashSet (java.util.HashSet)44 SourcePath (com.facebook.buck.rules.SourcePath)41 VisibleForTesting (com.google.common.annotations.VisibleForTesting)39 Nullable (javax.annotation.Nullable)39 LinkedHashMap (java.util.LinkedHashMap)36