List of usage examples for com.google.common.collect ImmutableSortedSet contains
@Override public boolean contains(@Nullable Object object)
From source file:com.facebook.buck.js.JsBundleGenruleDescription.java
@Override protected BuildRule createBuildRule(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams params, ActionGraphBuilder graphBuilder, JsBundleGenruleDescriptionArg args, Optional<Arg> cmd, Optional<Arg> bash, Optional<Arg> cmdExe) { ImmutableSortedSet<Flavor> flavors = buildTarget.getFlavors(); BuildTarget bundleTarget = args.getJsBundle().withAppendedFlavors(flavors); BuildRule jsBundle = graphBuilder.requireRule(bundleTarget); if (flavors.contains(JsFlavors.SOURCE_MAP) || flavors.contains(JsFlavors.DEPENDENCY_FILE) || flavors.contains(JsFlavors.MISC)) { // SOURCE_MAP is a special flavor that allows accessing the written source map, typically // via export_file in reference mode // DEPENDENCY_FILE is a special flavor that triggers building a single file (format defined by // the worker) // MISC_DIR allows accessing the "misc" directory that can contain diverse assets not meant // to be part of the app being shipped. SourcePath output;//from ww w . ja v a 2s . co m if (args.getRewriteSourcemap() && flavors.contains(JsFlavors.SOURCE_MAP)) { output = ((JsBundleOutputs) graphBuilder .requireRule(buildTarget.withoutFlavors(JsFlavors.SOURCE_MAP))).getSourcePathToSourceMap(); } else if (args.getRewriteMisc() && flavors.contains(JsFlavors.MISC)) { output = ((JsBundleOutputs) graphBuilder.requireRule(buildTarget.withoutFlavors(JsFlavors.MISC))) .getSourcePathToMisc(); } else { output = Preconditions.checkNotNull(jsBundle.getSourcePathToOutput(), "%s has no output", jsBundle.getBuildTarget()); } Path fileName = DefaultSourcePathResolver.from(new SourcePathRuleFinder(graphBuilder)) .getRelativePath(output).getFileName(); return new ExportFile(buildTarget, projectFilesystem, new SourcePathRuleFinder(graphBuilder), fileName.toString(), ExportFileDescription.Mode.REFERENCE, output, // TODO(27131551): temporary allow directory export until a proper fix is implemented ExportFileDirectoryAction.ALLOW); } if (!(jsBundle instanceof JsBundleOutputs)) { throw new HumanReadableException( "The 'js_bundle' argument of %s, %s, must correspond to a js_bundle() rule.", buildTarget, bundleTarget); } Supplier<? extends SortedSet<BuildRule>> originalExtraDeps = params.getExtraDeps(); JsBundleOutputs bundleOutputs = (JsBundleOutputs) jsBundle; return new JsBundleGenrule(buildTarget, projectFilesystem, graphBuilder, params.withExtraDeps(MoreSuppliers.memoize(() -> ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(originalExtraDeps.get()).add(jsBundle).build())), sandboxExecutionStrategy, args, cmd, bash, cmdExe, args.getEnvironmentExpansionSeparator(), toolchainProvider.getByNameIfPresent(AndroidPlatformTarget.DEFAULT_NAME, AndroidPlatformTarget.class), toolchainProvider.getByNameIfPresent(AndroidNdk.DEFAULT_NAME, AndroidNdk.class), toolchainProvider.getByNameIfPresent(AndroidSdkLocation.DEFAULT_NAME, AndroidSdkLocation.class), bundleOutputs, args.computeBundleName(buildTarget.getFlavors(), bundleOutputs::getBundleName)); }
From source file:com.facebook.buck.features.js.JsBundleGenruleDescription.java
@Override protected BuildRule createBuildRule(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams params, ActionGraphBuilder graphBuilder, JsBundleGenruleDescriptionArg args, Optional<Arg> cmd, Optional<Arg> bash, Optional<Arg> cmdExe) { ImmutableSortedSet<Flavor> flavors = buildTarget.getFlavors(); BuildTarget bundleTarget = args.getJsBundle().withAppendedFlavors(flavors); BuildRule jsBundle = graphBuilder.requireRule(bundleTarget); if (flavors.contains(JsFlavors.SOURCE_MAP) || flavors.contains(JsFlavors.DEPENDENCY_FILE) || flavors.contains(JsFlavors.MISC)) { // SOURCE_MAP is a special flavor that allows accessing the written source map, typically // via export_file in reference mode // DEPENDENCY_FILE is a special flavor that triggers building a single file (format defined by // the worker) // MISC_DIR allows accessing the "misc" directory that can contain diverse assets not meant // to be part of the app being shipped. SourcePath output;/*from w w w. ja v a 2 s .c o m*/ if (args.getRewriteSourcemap() && flavors.contains(JsFlavors.SOURCE_MAP)) { output = ((JsBundleOutputs) graphBuilder .requireRule(buildTarget.withoutFlavors(JsFlavors.SOURCE_MAP))).getSourcePathToSourceMap(); } else if (args.getRewriteMisc() && flavors.contains(JsFlavors.MISC)) { output = ((JsBundleOutputs) graphBuilder.requireRule(buildTarget.withoutFlavors(JsFlavors.MISC))) .getSourcePathToMisc(); } else if (args.getRewriteDepsFile() && flavors.contains(JsFlavors.DEPENDENCY_FILE)) { output = ((JsDependenciesOutputs) graphBuilder .requireRule(buildTarget.withoutFlavors(JsFlavors.DEPENDENCY_FILE))) .getSourcePathToDepsFile(); } else { output = Preconditions.checkNotNull(jsBundle.getSourcePathToOutput(), "%s has no output", jsBundle.getBuildTarget()); } Path fileName = DefaultSourcePathResolver.from(new SourcePathRuleFinder(graphBuilder)) .getRelativePath(output).getFileName(); return new ExportFile(buildTarget, projectFilesystem, new SourcePathRuleFinder(graphBuilder), fileName.toString(), ExportFileDescription.Mode.REFERENCE, output, // TODO(27131551): temporary allow directory export until a proper fix is implemented ExportFileDirectoryAction.ALLOW); } if (!(jsBundle instanceof JsBundleOutputs)) { throw new HumanReadableException( "The 'js_bundle' argument of %s, %s, must correspond to a js_bundle() rule.", buildTarget, bundleTarget); } Supplier<? extends SortedSet<BuildRule>> originalExtraDeps = params.getExtraDeps(); JsBundleOutputs bundleOutputs = (JsBundleOutputs) jsBundle; JsDependenciesOutputs jsDepsFileRule = bundleOutputs.getJsDependenciesOutputs(graphBuilder); return new JsBundleGenrule(buildTarget, projectFilesystem, graphBuilder, params.withExtraDeps(MoreSuppliers.memoize(() -> ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(originalExtraDeps.get()).add(jsBundle).add(jsDepsFileRule).build())), sandboxExecutionStrategy, args, cmd, bash, cmdExe, args.getEnvironmentExpansionSeparator(), toolchainProvider.getByNameIfPresent(AndroidPlatformTarget.DEFAULT_NAME, AndroidPlatformTarget.class), toolchainProvider.getByNameIfPresent(AndroidNdk.DEFAULT_NAME, AndroidNdk.class), toolchainProvider.getByNameIfPresent(AndroidSdkLocation.DEFAULT_NAME, AndroidSdkLocation.class), bundleOutputs, jsDepsFileRule, args.computeBundleName(buildTarget.getFlavors(), bundleOutputs::getBundleName)); }
From source file:com.facebook.buck.apple.AppleBinaryDescription.java
private boolean shouldUseStubBinary(BuildRuleParams params) { ImmutableSortedSet<Flavor> flavors = params.getBuildTarget().getFlavors(); return (flavors.contains(AppleBundleDescription.WATCH_OS_FLAVOR) || flavors.contains(AppleBundleDescription.WATCH_SIMULATOR_FLAVOR) || flavors.contains(LEGACY_WATCH_FLAVOR)); }
From source file:org.onosproject.onosjar.OnosJarDescription.java
@Override public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException { SourcePathResolver pathResolver = new SourcePathResolver(resolver); BuildTarget target = params.getBuildTarget(); // We know that the flavour we're being asked to create is valid, since the check is done when // creating the action graph from the target graph. ImmutableSortedSet<Flavor> flavors = target.getFlavors(); BuildRuleParams paramsWithMavenFlavor = null; if (flavors.contains(JavaLibrary.MAVEN_JAR)) { paramsWithMavenFlavor = params;//from w w w.j ava 2s .c o m // Maven rules will depend upon their vanilla versions, so the latter have to be constructed // without the maven flavor to prevent output-path conflict params = params.copyWithBuildTarget( params.getBuildTarget().withoutFlavors(ImmutableSet.of(JavaLibrary.MAVEN_JAR))); } if (flavors.contains(JavaLibrary.SRC_JAR)) { args.mavenCoords = args.mavenCoords.transform(new Function<String, String>() { @Override public String apply(String input) { return AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES); } }); if (!flavors.contains(JavaLibrary.MAVEN_JAR)) { return new JavaSourceJar(params, pathResolver, args.srcs.get(), args.mavenCoords); } else { return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), pathResolver, args.srcs.get(), args.mavenCoords, Optional.absent()); //FIXME } } if (flavors.contains(JavaLibrary.JAVADOC_JAR)) { args.mavenCoords = args.mavenCoords.transform(new Function<String, String>() { @Override public String apply(String input) { return AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_JAVADOC); } }); JavadocJar.JavadocArgs.Builder javadocArgs = JavadocJar.JavadocArgs.builder() .addArg("-windowtitle", target.getShortName()) .addArg("-link", "http://docs.oracle.com/javase/8/docs/api") .addArg("-tag", "onos.rsModel:a:\"onos model\""); //FIXME from buckconfig + rule final ImmutableSortedMap.Builder<SourcePath, Path> javadocFiles = ImmutableSortedMap.naturalOrder(); if (args.javadocFiles.isPresent()) { for (SourcePath path : args.javadocFiles.get()) { javadocFiles.put(path, JavadocJar.getDocfileWithPath(pathResolver, path, args.javadocFilesRoot.orNull())); } } if (!flavors.contains(JavaLibrary.MAVEN_JAR)) { return new JavadocJar(params, pathResolver, args.srcs.get(), javadocFiles.build(), javadocArgs.build(), args.mavenCoords); } else { return MavenUberJar.MavenJavadocJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), pathResolver, args.srcs.get(), javadocFiles.build(), javadocArgs.build(), args.mavenCoords, Optional.absent()); //FIXME } } JavacOptions javacOptions = JavacOptionsFactory.create(defaultJavacOptions, params, resolver, pathResolver, args); BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR); ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps.get()); // Build the resources string List<String> resourceMappings = Lists.newArrayList(); if (args.includeResources.isPresent()) { args.includeResources.get().entrySet() .forEach(p -> resourceMappings.add(String.format("%s=%s", p.getKey(), p.getValue()))); } if (args.apiTitle.isPresent()) { resourceMappings.add("WEB-INF/classes/apidoc/swagger.json=swagger.json"); } Optional<String> includedResourcesString = Optional.of(String.join(",", resourceMappings)); final DefaultJavaLibrary defaultJavaLibrary; if (!flavors.contains(NON_OSGI_JAR)) { defaultJavaLibrary = resolver.addToIndex(new OnosJar( params.appendExtraDeps(Iterables.concat( BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps.get()))), pathResolver.filterBuildRuleInputs(javacOptions.getInputs(pathResolver)))), pathResolver, args.srcs.get(), validateResources(pathResolver, params.getProjectFilesystem(), args.resources.get()), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig.transform(SourcePaths.toSourcePath(params.getProjectFilesystem())), args.postprocessClassesCommands.get(), // FIXME this should be forbidden exportedDeps, resolver.getAllRules(args.providedDeps.get()), new BuildTargetSourcePath(abiJarTarget), javacOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.<Path>of(), new OnosJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY, args.webContext, args.apiTitle, args.apiVersion, args.apiPackage, args.apiDescription, args.resources, args.groupId, args.bundleName, args.bundleVersion, args.bundleLicense, args.bundleDescription, args.importPackages, args.exportPackages, includedResourcesString, args.dynamicimportPackages), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests.get(), javacOptions.getClassesToRemoveFromJar(), args.webContext, args.apiTitle, args.apiVersion, args.apiPackage, args.apiDescription, args.includeResources)); } else { defaultJavaLibrary = resolver.addToIndex(new DefaultJavaLibrary( params.appendExtraDeps(Iterables.concat( BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps.get()))), pathResolver.filterBuildRuleInputs(javacOptions.getInputs(pathResolver)))), pathResolver, args.srcs.get(), validateResources(pathResolver, params.getProjectFilesystem(), args.resources.get()), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig.transform(SourcePaths.toSourcePath(params.getProjectFilesystem())), args.postprocessClassesCommands.get(), exportedDeps, resolver.getAllRules(args.providedDeps.get()), new BuildTargetSourcePath(abiJarTarget), javacOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.<Path>of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests.get(), javacOptions.getClassesToRemoveFromJar())); } resolver.addToIndex(CalculateAbi.of(abiJarTarget, pathResolver, params, new BuildTargetSourcePath(defaultJavaLibrary.getBuildTarget()))); return defaultJavaLibrary; }
From source file:com.facebook.buck.android.exopackage.ExopackageInstaller.java
public void installMissingFiles(ImmutableSortedSet<Path> presentFiles, ImmutableMap<Path, Path> wantedFilesToInstall, String filesType) throws Exception { ImmutableSortedMap<Path, Path> filesToInstall = wantedFilesToInstall.entrySet().stream() .filter(entry -> !presentFiles.contains(entry.getKey())).collect(ImmutableSortedMap .toImmutableSortedMap(Ordering.natural(), Map.Entry::getKey, Map.Entry::getValue)); installFiles(filesType, filesToInstall); }
From source file:com.facebook.buck.features.js.JsBundleDescription.java
@Override public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget, BuildRuleParams params, JsBundleDescriptionArg args) { ActionGraphBuilder graphBuilder = context.getActionGraphBuilder(); ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); ImmutableSortedSet<Flavor> flavors = buildTarget.getFlavors(); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); // Source maps are exposed individually using a special flavor if (flavors.contains(JsFlavors.SOURCE_MAP)) { BuildTarget bundleTarget = buildTarget.withoutFlavors(JsFlavors.SOURCE_MAP); graphBuilder.requireRule(bundleTarget); JsBundleOutputs bundleOutputs = graphBuilder.getRuleWithType(bundleTarget, JsBundleOutputs.class); return new ExportFile(buildTarget, projectFilesystem, ruleFinder, bundleOutputs.getBundleName() + ".map", ExportFileDescription.Mode.REFERENCE, bundleOutputs.getSourcePathToSourceMap(), ExportFileDirectoryAction.FAIL); }/*from ww w.j a v a 2 s . c o m*/ if (flavors.contains(JsFlavors.MISC)) { BuildTarget bundleTarget = buildTarget.withoutFlavors(JsFlavors.MISC); graphBuilder.requireRule(bundleTarget); JsBundleOutputs bundleOutputs = graphBuilder.getRuleWithType(bundleTarget, JsBundleOutputs.class); return new ExportFile(buildTarget, projectFilesystem, ruleFinder, bundleOutputs.getBundleName() + "-misc", ExportFileDescription.Mode.REFERENCE, bundleOutputs.getSourcePathToMisc(), // TODO(27131551): temporary allow directory export until a proper fix is implemented ExportFileDirectoryAction.ALLOW); } // For Android, we bundle JS output as assets, and images etc. as resources. // To facilitate this, we return a build rule that in turn depends on a `JsBundle` and // an `AndroidResource`. The `AndroidResource` rule also depends on the `JsBundle` // if the `FORCE_JS_BUNDLE` flavor is present, we create the `JsBundle` instance itself. if (flavors.contains(JsFlavors.ANDROID) && !flavors.contains(JsFlavors.FORCE_JS_BUNDLE) && !flavors.contains(JsFlavors.DEPENDENCY_FILE)) { return createAndroidRule(toolchainProvider, buildTarget, projectFilesystem, graphBuilder, ruleFinder, args.getAndroidPackage()); } Either<ImmutableSet<String>, String> entryPoint = args.getEntry(); TransitiveLibraryDependencies libsResolver = new TransitiveLibraryDependencies(buildTarget, context.getTargetGraph(), graphBuilder, ruleFinder); ImmutableSet<JsLibrary> flavoredLibraryDeps = libsResolver.collect(args.getDeps()); Stream<BuildRule> generatedDeps = findGeneratedSources(ruleFinder, flavoredLibraryDeps.stream()) .map(graphBuilder::requireRule); // Flavors are propagated from js_bundle targets to their js_library dependencies // for that reason, dependencies of libraries are handled manually, and as a first step, // all dependencies to libraries are replaced with dependencies to flavored library targets. BuildRuleParams paramsWithFlavoredLibraries = params.withoutDeclaredDeps() .copyAppendingExtraDeps(Stream.concat(flavoredLibraryDeps.stream(), generatedDeps)::iterator); ImmutableSortedSet<SourcePath> libraries = flavoredLibraryDeps.stream() .map(JsLibrary::getSourcePathToOutput) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); ImmutableSet<String> entryPoints = entryPoint.isLeft() ? entryPoint.getLeft() : ImmutableSet.of(entryPoint.getRight()); Optional<Arg> extraJson = JsUtil.getExtraJson(args, buildTarget, graphBuilder, context.getCellPathResolver()); // If {@link JsFlavors.DEPENDENCY_FILE} is specified, the worker will output a file containing // all dependencies between files that go into the final bundle if (flavors.contains(JsFlavors.DEPENDENCY_FILE)) { return new JsDependenciesFile(buildTarget, projectFilesystem, paramsWithFlavoredLibraries, libraries, entryPoints, extraJson, graphBuilder.getRuleWithType(args.getWorker(), WorkerTool.class)); } String bundleName = args.computeBundleName(buildTarget.getFlavors(), () -> args.getName() + ".js"); return new JsBundle(buildTarget, projectFilesystem, paramsWithFlavoredLibraries, libraries, entryPoints, extraJson, bundleName, graphBuilder.getRuleWithType(args.getWorker(), WorkerTool.class)); }
From source file:com.facebook.buck.js.JsBundleDescription.java
@Override public BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, CellPathResolver cellRoots, Arg args) throws NoSuchBuildTargetException { final ImmutableSortedSet<Flavor> flavors = params.getBuildTarget().getFlavors(); // For Android, we bundle JS output as assets, and images etc. as resources. // To facilitate this, we return a build rule that in turn depends on a `JsBundle` and // an `AndroidResource`. The `AndroidResource` rule also depends on the `JsBundle` // if the `FORCE_JS_BUNDLE` flavor is present, we create the `JsBundle` instance itself. if (flavors.contains(JsFlavors.ANDROID) && !flavors.contains(JsFlavors.FORCE_JS_BUNDLE)) { return createAndroidRule(params.copyInvalidatingDeps(), resolver, args.rDotJavaPackage); }/*w w w . java2s .c o m*/ // Flavors are propagated from js_bundle targets to their js_library dependencies // for that reason, dependencies of libraries are handled manually, and as a first step, // all dependencies to libraries are removed params = JsUtil.withWorkerDependencyOnly(params, resolver, args.worker); final Either<ImmutableSet<String>, String> entryPoint = args.entry; ImmutableSortedSet<JsLibrary> libraryDeps = new TransitiveLibraryDependencies(params.getBuildTarget(), targetGraph, resolver).collect(args.deps); return new JsBundle(params.copyAppendingExtraDeps(libraryDeps), libraryDeps.stream().map(JsLibrary::getSourcePathToOutput) .collect(MoreCollectors.toImmutableSortedSet()), entryPoint.isLeft() ? entryPoint.getLeft() : ImmutableSet.of(entryPoint.getRight()), args.bundleName.orElse(params.getBuildTarget().getShortName() + ".js"), resolver.getRuleWithType(args.worker, WorkerTool.class)); }
From source file:com.facebook.buck.features.js.JsDependenciesFile.java
private ObjectBuilder getJobArgs(SourcePathResolver sourcePathResolver, SourcePath outputFilePath) { ImmutableSortedSet<Flavor> flavors = getBuildTarget().getFlavors(); return JsonBuilder.object() .addString("outputFilePath", sourcePathResolver.getAbsolutePath(outputFilePath).toString()) .addString("command", "dependencies") .addArray("entryPoints", entryPoints.stream().collect(JsonBuilder.toArrayOfStrings())) .addArray("libraries", libraries.stream().map(sourcePathResolver::getAbsolutePath).map(Path::toString) .collect(JsonBuilder.toArrayOfStrings())) .addString("platform", JsUtil.getPlatformString(flavors)) .addBoolean("release", flavors.contains(JsFlavors.RELEASE)) .addString("rootPath", getProjectFilesystem().getRootPath().toString()) .addRaw("extraData", extraJson.map(a -> Arg.stringify(a, sourcePathResolver))); }
From source file:com.facebook.buck.swift.SwiftLibraryDescription.java
@Override public <A extends SwiftLibraryDescription.Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException { Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN .getValue(params.getBuildTarget()); params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode); final BuildTarget buildTarget = params.getBuildTarget(); // See if we're building a particular "type" and "platform" of this library, and if so, extract // them from the flavors attached to the build target. Optional<Map.Entry<Flavor, CxxPlatform>> platform = cxxPlatformFlavorDomain.getFlavorAndValue(buildTarget); final ImmutableSortedSet<Flavor> buildFlavors = buildTarget.getFlavors(); ImmutableSortedSet<BuildRule> filteredExtraDeps = FluentIterable .from(params.getExtraDeps().get()).filter(input -> !input.getBuildTarget() .getUnflavoredBuildTarget().equals(buildTarget.getUnflavoredBuildTarget())) .toSortedSet(Ordering.natural()); params = params.copyWithExtraDeps(Suppliers.ofInstance(filteredExtraDeps)); if (!buildFlavors.contains(SWIFT_COMPANION_FLAVOR) && platform.isPresent()) { final CxxPlatform cxxPlatform = platform.get().getValue(); Optional<SwiftPlatform> swiftPlatform = swiftPlatformFlavorDomain.getValue(buildTarget); if (!swiftPlatform.isPresent()) { throw new HumanReadableException("Platform %s is missing swift compiler", cxxPlatform); }/* w w w. j a v a 2s. co m*/ // See if we're building a particular "type" and "platform" of this library, and if so, // extract them from the flavors attached to the build target. Optional<Map.Entry<Flavor, Type>> type = LIBRARY_TYPE.getFlavorAndValue(buildTarget); if (!buildFlavors.contains(SWIFT_COMPILE_FLAVOR) && type.isPresent()) { Set<Flavor> flavors = Sets.newHashSet(params.getBuildTarget().getFlavors()); flavors.remove(type.get().getKey()); BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()) .addAllFlavors(flavors).build(); if (flavoredLinkerMapMode.isPresent()) { target = target.withAppendedFlavors(flavoredLinkerMapMode.get().getFlavor()); } BuildRuleParams typeParams = params.copyWithChanges(target, params.getDeclaredDeps(), params.getExtraDeps()); switch (type.get().getValue()) { case SHARED: return createSharedLibraryBuildRule(typeParams, resolver, target, swiftPlatform.get(), cxxPlatform, args.soname, flavoredLinkerMapMode); case STATIC: case MACH_O_BUNDLE: // TODO(tho@uber.com) create build rule for other types. } throw new RuntimeException("unhandled library build type"); } // All swift-compile rules of swift-lib deps are required since we need their swiftmodules // during compilation. final Function<BuildRule, BuildRule> requireSwiftCompile = input -> { try { Preconditions.checkArgument(input instanceof SwiftLibrary); return ((SwiftLibrary) input).requireSwiftCompileRule(cxxPlatform.getFlavor()); } catch (NoSuchBuildTargetException e) { throw new HumanReadableException(e, "Could not find SwiftCompile with target %s", buildTarget); } }; params = params.appendExtraDeps(params.getDeps().stream().filter(SwiftLibrary.class::isInstance) .map(requireSwiftCompile).collect(MoreCollectors.toImmutableSet())); params = params.appendExtraDeps( FluentIterable.from(params.getDeps()).filter(CxxLibrary.class).transform(input -> { BuildTarget companionTarget = input.getBuildTarget() .withAppendedFlavors(SWIFT_COMPANION_FLAVOR); return resolver.getRuleOptional(companionTarget).map(requireSwiftCompile); }).filter(Optional::isPresent).transform(Optional::get).toSortedSet(Ordering.natural())); return new SwiftCompile(cxxPlatform, swiftBuckConfig, params, new SourcePathResolver(new SourcePathRuleFinder(resolver)), swiftPlatform.get().getSwift(), args.frameworks, args.moduleName.orElse(buildTarget.getShortName()), BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s"), args.srcs, args.compilerFlags, args.enableObjcInterop, args.bridgingHeader); } // Otherwise, we return the generic placeholder of this library. params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode); return new SwiftLibrary(params, resolver, new SourcePathResolver(new SourcePathRuleFinder(resolver)), ImmutableSet.of(), swiftPlatformFlavorDomain, args.frameworks, args.libraries, args.supportedPlatformsRegex, args.preferredLinkage.orElse(NativeLinkable.Linkage.ANY)); }
From source file:com.facebook.buck.cxx.toolchain.HeaderSymlinkTreeWithModuleMap.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableSortedSet<Path> paths = getLinks().keySet(); ImmutableList.Builder<Step> builder = ImmutableList.<Step>builder() .addAll(super.getBuildSteps(context, buildableContext)); moduleName.ifPresent(moduleName -> { builder.add(new ModuleMapStep(getProjectFilesystem(), moduleMapPath(getProjectFilesystem(), getBuildTarget(), moduleName), new ModuleMap(moduleName, containsSwiftHeader(paths, moduleName) ? ModuleMap.SwiftMode.INCLUDE_SWIFT_HEADER : ModuleMap.SwiftMode.NO_SWIFT))); Path umbrellaHeaderPath = Paths.get(moduleName, moduleName + ".h"); if (!paths.contains(umbrellaHeaderPath)) { builder.add(new WriteFileStep(getProjectFilesystem(), new UmbrellaHeader(moduleName, getLinks().keySet().stream().map(x -> x.getFileName().toString()) .collect(ImmutableList.toImmutableList())).render(), BuildTargetPaths.getGenPath(getProjectFilesystem(), getBuildTarget(), "%s/" + umbrellaHeaderPath), false));/*from ww w. j a v a 2s . com*/ } }); return builder.build(); }