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();
}
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);
}
}
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();
}
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);
}
}
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();
}
Aggregations