Search in sources :

Example 6 with ImmutableSortedMap

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);
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 7 with ImmutableSortedMap

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);
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) PBXNativeTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget)

Example 8 with ImmutableSortedMap

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));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) PreprocessorFlags(com.facebook.buck.cxx.PreprocessorFlags) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) ExplicitCxxToolFlags(com.facebook.buck.cxx.ExplicitCxxToolFlags)

Example 9 with ImmutableSortedMap

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

Example 10 with ImmutableSortedMap

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);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) JavaFileParser(com.facebook.buck.jvm.java.JavaFileParser) BuildTarget(com.facebook.buck.model.BuildTarget) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Aggregations

ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)24 Map (java.util.Map)13 SourcePath (com.facebook.buck.rules.SourcePath)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 Path (java.nio.file.Path)10 PathSourcePath (com.facebook.buck.rules.PathSourcePath)8 BuildTarget (com.facebook.buck.model.BuildTarget)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 HashMap (java.util.HashMap)7 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)6 NSString (com.dd.plist.NSString)5 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 BuildRule (com.facebook.buck.rules.BuildRule)4 TargetNode (com.facebook.buck.rules.TargetNode)4 ImmutableList (com.google.common.collect.ImmutableList)4 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)3 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)3 ImmutableSet (com.google.common.collect.ImmutableSet)3