use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class WorkspaceAndProjectGenerator method addExtraWorkspaceSchemes.
private static void addExtraWorkspaceSchemes(TargetGraph projectGraph, AppleDependenciesCache dependenciesCache, ImmutableSortedMap<String, BuildTarget> extraSchemes, ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder, ImmutableSetMultimap.Builder<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNodeBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> extraTestNodesBuilder) {
for (Map.Entry<String, BuildTarget> extraSchemeEntry : extraSchemes.entrySet()) {
BuildTarget extraSchemeTarget = extraSchemeEntry.getValue();
Optional<TargetNode<?, ?>> extraSchemeNode = projectGraph.getOptional(extraSchemeTarget);
if (!extraSchemeNode.isPresent() || !(extraSchemeNode.get().getDescription() instanceof XcodeWorkspaceConfigDescription)) {
throw new HumanReadableException("Extra scheme target '%s' should be of type 'xcode_workspace_config'", extraSchemeTarget);
}
XcodeWorkspaceConfigDescription.Arg extraSchemeArg = (XcodeWorkspaceConfigDescription.Arg) extraSchemeNode.get().getConstructorArg();
String schemeName = extraSchemeEntry.getKey();
addWorkspaceScheme(projectGraph, dependenciesCache, schemeName, extraSchemeArg, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, extraTestNodesBuilder);
}
}
use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class ProjectGenerator method generateHalideLibraryTarget.
private Optional<PBXTarget> generateHalideLibraryTarget(PBXProject project, TargetNode<HalideLibraryDescription.Arg, ?> targetNode) throws IOException {
final BuildTarget buildTarget = targetNode.getBuildTarget();
boolean isFocusedOnTarget = buildTarget.matchesUnflavoredTargets(focusModules);
String productName = getProductNameForBuildTarget(buildTarget);
Path outputPath = getHalideOutputPath(targetNode.getFilesystem(), buildTarget);
Path scriptPath = halideBuckConfig.getXcodeCompileScriptPath();
Optional<String> script = projectFilesystem.readFileIfItExists(scriptPath);
PBXShellScriptBuildPhase scriptPhase = new PBXShellScriptBuildPhase();
scriptPhase.setShellScript(script.orElse(""));
NewNativeTargetProjectMutator mutator = new NewNativeTargetProjectMutator(pathRelativizer, this::resolveSourcePath);
mutator.setTargetName(getXcodeTargetName(buildTarget)).setProduct(ProductType.STATIC_LIBRARY, productName, outputPath).setPreBuildRunScriptPhases(ImmutableList.of(scriptPhase));
NewNativeTargetProjectMutator.Result targetBuilderResult;
targetBuilderResult = mutator.buildTargetAndAddToProject(project, isFocusedOnTarget);
BuildTarget compilerTarget = HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget);
Path compilerPath = BuildTargets.getGenPath(projectFilesystem, compilerTarget, "%s");
ImmutableMap<String, String> appendedConfig = ImmutableMap.of();
ImmutableMap<String, String> extraSettings = ImmutableMap.of();
ImmutableMap.Builder<String, String> defaultSettingsBuilder = ImmutableMap.builder();
defaultSettingsBuilder.put("REPO_ROOT", projectFilesystem.getRootPath().toAbsolutePath().normalize().toString());
defaultSettingsBuilder.put("HALIDE_COMPILER_PATH", compilerPath.toString());
// pass the source list to the xcode script
String halideCompilerSrcs;
Iterable<Path> compilerSrcFiles = Iterables.transform(targetNode.getConstructorArg().srcs, input -> resolveSourcePath(input.getSourcePath()));
halideCompilerSrcs = Joiner.on(" ").join(compilerSrcFiles);
defaultSettingsBuilder.put("HALIDE_COMPILER_SRCS", halideCompilerSrcs);
String halideCompilerFlags;
halideCompilerFlags = Joiner.on(" ").join(targetNode.getConstructorArg().compilerFlags);
defaultSettingsBuilder.put("HALIDE_COMPILER_FLAGS", halideCompilerFlags);
defaultSettingsBuilder.put("HALIDE_OUTPUT_PATH", outputPath.toString());
defaultSettingsBuilder.put("HALIDE_FUNC_NAME", buildTarget.getShortName());
defaultSettingsBuilder.put(PRODUCT_NAME, productName);
Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = getXcodeBuildConfigurationsForTargetNode(targetNode, appendedConfig);
PBXNativeTarget target = targetBuilderResult.target;
setTargetBuildConfigurations(getConfigurationNameToXcconfigPath(buildTarget), target, project.getMainGroup(), configs.get(), extraSettings, defaultSettingsBuilder.build(), appendedConfig);
return Optional.of(target);
}
use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class HaskellDescriptionUtils method createCompileRule.
/**
* Create a Haskell compile rule that compiles all the given haskell sources in one step and
* pulls interface files from all transitive haskell dependencies.
*/
private static HaskellCompileRule createCompileRule(BuildTarget target, final BuildRuleParams baseParams, final BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, ImmutableSet<BuildRule> deps, final CxxPlatform cxxPlatform, HaskellConfig haskellConfig, final Linker.LinkableDepType depType, Optional<String> main, Optional<HaskellPackageInfo> packageInfo, ImmutableList<String> flags, HaskellSources sources) throws NoSuchBuildTargetException {
final Map<BuildTarget, ImmutableList<String>> depFlags = new TreeMap<>();
final Map<BuildTarget, ImmutableList<SourcePath>> depIncludes = new TreeMap<>();
final ImmutableSortedMap.Builder<String, HaskellPackage> exposedPackagesBuilder = ImmutableSortedMap.naturalOrder();
final ImmutableSortedMap.Builder<String, HaskellPackage> packagesBuilder = ImmutableSortedMap.naturalOrder();
new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(deps) {
private final ImmutableSet<BuildRule> empty = ImmutableSet.of();
@Override
public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException {
ImmutableSet<BuildRule> ruleDeps = empty;
if (rule instanceof HaskellCompileDep) {
ruleDeps = rule.getDeps();
HaskellCompileInput compileInput = ((HaskellCompileDep) rule).getCompileInput(cxxPlatform, depType);
depFlags.put(rule.getBuildTarget(), compileInput.getFlags());
depIncludes.put(rule.getBuildTarget(), compileInput.getIncludes());
// We add packages from first-order deps as expose modules, and transitively included
// packages as hidden ones.
boolean firstOrderDep = deps.contains(rule);
for (HaskellPackage pkg : compileInput.getPackages()) {
if (firstOrderDep) {
exposedPackagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
} else {
packagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
}
}
}
return ruleDeps;
}
}.start();
Collection<CxxPreprocessorInput> cxxPreprocessorInputs = CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, deps);
ExplicitCxxToolFlags.Builder toolFlagsBuilder = CxxToolFlags.explicitBuilder();
PreprocessorFlags.Builder ppFlagsBuilder = PreprocessorFlags.builder();
toolFlagsBuilder.setPlatformFlags(CxxSourceTypes.getPlatformPreprocessFlags(cxxPlatform, CxxSource.Type.C));
for (CxxPreprocessorInput input : cxxPreprocessorInputs) {
ppFlagsBuilder.addAllIncludes(input.getIncludes());
ppFlagsBuilder.addAllFrameworkPaths(input.getFrameworks());
toolFlagsBuilder.addAllRuleFlags(input.getPreprocessorFlags().get(CxxSource.Type.C));
}
ppFlagsBuilder.setOtherFlags(toolFlagsBuilder.build());
PreprocessorFlags ppFlags = ppFlagsBuilder.build();
ImmutableList<String> compileFlags = ImmutableList.<String>builder().addAll(haskellConfig.getCompilerFlags()).addAll(flags).addAll(Iterables.concat(depFlags.values())).build();
ImmutableList<SourcePath> includes = ImmutableList.copyOf(Iterables.concat(depIncludes.values()));
ImmutableSortedMap<String, HaskellPackage> exposedPackages = exposedPackagesBuilder.build();
ImmutableSortedMap<String, HaskellPackage> packages = packagesBuilder.build();
return HaskellCompileRule.from(target, baseParams, ruleFinder, haskellConfig.getCompiler().resolve(resolver), haskellConfig.getHaskellVersion(), compileFlags, ppFlags, cxxPlatform, depType == Linker.LinkableDepType.STATIC ? CxxSourceRuleFactory.PicType.PDC : CxxSourceRuleFactory.PicType.PIC, main, packageInfo, includes, exposedPackages, packages, sources, CxxSourceTypes.getPreprocessor(cxxPlatform, CxxSource.Type.C).resolve(resolver));
}
use of com.google.common.collect.ImmutableSortedMap 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();
}
use of com.google.common.collect.ImmutableSortedMap in project buck by facebook.
the class JavaDepsFinder method createJavaDepsFinder.
public static JavaDepsFinder createJavaDepsFinder(BuckConfig buckConfig, final CellPathResolver cellNames, ObjectMapper objectMapper, BuildEngineBuildContext buildContext, ExecutionContext executionContext, BuildEngine buildEngine) {
Optional<String> javaPackageMappingOption = buckConfig.getValue(BUCK_CONFIG_SECTION, "java-package-mappings");
ImmutableSortedMap<String, BuildTarget> javaPackageMapping;
if (javaPackageMappingOption.isPresent()) {
Stream<Map.Entry<String, BuildTarget>> entries = Splitter.on(',').omitEmptyStrings().withKeyValueSeparator("=>").split(javaPackageMappingOption.get()).entrySet().stream().map(entry -> {
String originalKey = entry.getKey().trim();
boolean appearsToBeJavaPackage = !originalKey.endsWith(".") && CharMatcher.javaUpperCase().matchesNoneOf(originalKey);
String key = appearsToBeJavaPackage ? originalKey + "." : originalKey;
BuildTarget buildTarget = BuildTargetParser.INSTANCE.parse(entry.getValue().trim(), BuildTargetPatternParser.fullyQualified(), cellNames);
return Maps.immutableEntry(key, buildTarget);
});
javaPackageMapping = ImmutableSortedMap.copyOf((Iterable<Map.Entry<String, BuildTarget>>) entries::iterator, Comparator.reverseOrder());
} else {
javaPackageMapping = ImmutableSortedMap.of();
}
JavaBuckConfig javaBuckConfig = buckConfig.getView(JavaBuckConfig.class);
JavacOptions javacOptions = javaBuckConfig.getDefaultJavacOptions();
JavaFileParser javaFileParser = JavaFileParser.createJavaFileParser(javacOptions);
return new JavaDepsFinder(javaPackageMapping, javaFileParser, objectMapper, buildContext, executionContext, buildEngine);
}
Aggregations