use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class OcamlBuildRulesGenerator method generateBytecodeLinking.
/**
* Links the .cmo files generated by the bytecode compilation
*/
private BuildRule generateBytecodeLinking(ImmutableList<SourcePath> allInputs) {
BuildRuleParams linkParams = params.withBuildTarget(addBytecodeFlavor(params.getBuildTarget())).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getBytecodeLinkDeps()).addAll(Stream.concat(ocamlContext.getBytecodeLinkableInput().getArgs().stream(), ocamlContext.getCLinkableInput().getArgs().stream()).flatMap(arg -> arg.getDeps(ruleFinder).stream()).filter(rule -> !(rule instanceof OcamlBuild)).iterator()).addAll(cxxCompiler.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
ImmutableList.Builder<Arg> flags = ImmutableList.builder();
flags.addAll(ocamlContext.getFlags());
flags.addAll(StringArg.from(ocamlContext.getCommonCLinkerFlags()));
OcamlLink link = new OcamlLink(linkParams, allInputs, cxxCompiler.getEnvironment(pathResolver), cxxCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlBytecodeCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getBytecodeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getBytecodeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
true, /* buildNativePlugin */
false);
resolver.addToIndex(link);
return link;
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class AppleDescriptions method createBuildRuleForTransitiveAssetCatalogDependencies.
public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver, ApplePlatform applePlatform, Tool actool) {
TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));
ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();
Optional<String> appIcon = Optional.empty();
Optional<String> launchImage = Optional.empty();
AppleAssetCatalogDescription.Optimization optimization = null;
for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
if (optimization == null) {
optimization = arg.optimization;
}
assetCatalogDirsBuilder.addAll(arg.dirs);
if (arg.appIcon.isPresent()) {
if (appIcon.isPresent()) {
throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a app_icon", params.getBuildTarget());
}
appIcon = arg.appIcon;
}
if (arg.launchImage.isPresent()) {
if (launchImage.isPresent()) {
throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a launch_image", params.getBuildTarget());
}
launchImage = arg.launchImage;
}
if (arg.optimization != optimization) {
throw new HumanReadableException("At most one asset catalog optimisation style can be " + "specified in the dependencies %s", params.getBuildTarget());
}
}
ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();
if (assetCatalogDirs.isEmpty()) {
return Optional.empty();
}
Preconditions.checkNotNull(optimization, "optimization was null even though assetCatalogArgs was not empty");
for (SourcePath assetCatalogDir : assetCatalogDirs) {
Path baseName = sourcePathResolver.getRelativePath(assetCatalogDir).getFileName();
if (!baseName.toString().endsWith(".xcassets")) {
throw new HumanReadableException("Target %s had asset catalog dir %s - asset catalog dirs must end with .xcassets", params.getBuildTarget(), assetCatalogDir);
}
}
BuildRuleParams assetCatalogParams = params.withAppendedFlavor(AppleAssetCatalog.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
return Optional.of(new AppleAssetCatalog(assetCatalogParams, applePlatform.getName(), actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class NdkLibraryDescription method findSources.
@VisibleForTesting
protected ImmutableSortedSet<SourcePath> findSources(final ProjectFilesystem filesystem, final Path buildRulePath) {
final ImmutableSortedSet.Builder<SourcePath> srcs = ImmutableSortedSet.naturalOrder();
try {
final Path rootDirectory = filesystem.resolve(buildRulePath);
Files.walkFileTree(rootDirectory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), /* maxDepth */
Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (EXTENSIONS_REGEX.matcher(file.toString()).matches()) {
srcs.add(new PathSourcePath(filesystem, buildRulePath.resolve(rootDirectory.relativize(file))));
}
return super.visitFile(file, attrs);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
return srcs.build();
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class UnzipAar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), unpackDirectory));
steps.add(new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(aarFile), unpackDirectory));
steps.add(new TouchStep(getProjectFilesystem(), getProguardConfig()));
steps.add(new MkdirStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(getAssetsDirectory())));
steps.add(new MkdirStep(getProjectFilesystem(), getNativeLibsDirectory()));
steps.add(new TouchStep(getProjectFilesystem(), getTextSymbolsFile()));
// We take the classes.jar file that is required to exist in an .aar and merge it with any
// .jar files under libs/ into an "uber" jar. We do this for simplicity because we do not know
// how many entries there are in libs/ at graph enhancement time, but we need to make sure
// that all of the .class files in the .aar get packaged. As it is implemented today, an
// android_library that depends on an android_prebuilt_aar can compile against anything in the
// .aar's classes.jar or libs/.
steps.add(new MkdirStep(getProjectFilesystem(), uberClassesJar.getParent()));
steps.add(new AbstractExecutionStep("create_uber_classes_jar") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
Path libsDirectory = unpackDirectory.resolve("libs");
boolean dirDoesNotExistOrIsEmpty;
if (!getProjectFilesystem().exists(libsDirectory)) {
dirDoesNotExistOrIsEmpty = true;
} else {
try {
dirDoesNotExistOrIsEmpty = getProjectFilesystem().getDirectoryContents(libsDirectory).isEmpty();
} catch (IOException e) {
context.logError(e, "Failed to get directory contents of %s", libsDirectory);
return StepExecutionResult.ERROR;
}
}
Path classesJar = unpackDirectory.resolve("classes.jar");
JavacEventSinkToBuckEventBusBridge eventSink = new JavacEventSinkToBuckEventBusBridge(context.getBuckEventBus());
if (!getProjectFilesystem().exists(classesJar)) {
try {
JarDirectoryStepHelper.createEmptyJarFile(getProjectFilesystem(), classesJar, eventSink, context.getStdErr());
} catch (IOException e) {
context.logError(e, "Failed to create empty jar %s", classesJar);
return StepExecutionResult.ERROR;
}
}
if (dirDoesNotExistOrIsEmpty) {
try {
getProjectFilesystem().copy(classesJar, uberClassesJar, ProjectFilesystem.CopySourceMode.FILE);
} catch (IOException e) {
context.logError(e, "Failed to copy from %s to %s", classesJar, uberClassesJar);
return StepExecutionResult.ERROR;
}
} else {
// Glob all of the contents from classes.jar and the entries in libs/ into a single JAR.
ImmutableSortedSet.Builder<Path> entriesToJarBuilder = ImmutableSortedSet.naturalOrder();
entriesToJarBuilder.add(classesJar);
try {
entriesToJarBuilder.addAll(getProjectFilesystem().getDirectoryContents(libsDirectory));
} catch (IOException e) {
context.logError(e, "Failed to get directory contents of %s", libsDirectory);
return StepExecutionResult.ERROR;
}
ImmutableSortedSet<Path> entriesToJar = entriesToJarBuilder.build();
try {
JarDirectoryStepHelper.createJarFile(getProjectFilesystem(), uberClassesJar, entriesToJar, /* mainClass */
Optional.empty(), /* manifestFile */
Optional.empty(), /* mergeManifests */
true, /* blacklist */
ImmutableSet.of(), eventSink, context.getStdErr());
} catch (IOException e) {
context.logError(e, "Failed to jar %s into %s", entriesToJar, uberClassesJar);
return StepExecutionResult.ERROR;
}
}
return StepExecutionResult.SUCCESS;
}
});
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTextSymbolsDir));
steps.add(new ExtractFromAndroidManifestStep(getAndroidManifest(), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, pathToRDotJavaPackageFile));
steps.add(CopyStep.forFile(getProjectFilesystem(), getTextSymbolsFile(), pathToTextSymbolsFile));
buildableContext.recordArtifact(unpackDirectory);
buildableContext.recordArtifact(uberClassesJar);
buildableContext.recordArtifact(pathToTextSymbolsFile);
buildableContext.recordArtifact(pathToRDotJavaPackageFile);
return steps.build();
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class DDescriptionUtils method requireBuildRule.
/**
* Ensures that a DCompileBuildRule exists for the given target, creating a DCompileBuildRule
* if neccesary.
* @param baseParams build parameters for the rule
* @param buildRuleResolver BuildRuleResolver the rule should be in
* @param src the source file to be compiled
* @param compilerFlags flags to pass to the compiler
* @param compileTarget the target the rule should be for
* @param dBuckConfig the Buck configuration for D
* @return the build rule
*/
public static DCompileBuildRule requireBuildRule(BuildTarget compileTarget, BuildRuleParams baseParams, BuildRuleResolver buildRuleResolver, SourcePathRuleFinder ruleFinder, DBuckConfig dBuckConfig, ImmutableList<String> compilerFlags, String name, SourcePath src, DIncludes includes) throws NoSuchBuildTargetException {
Optional<BuildRule> existingRule = buildRuleResolver.getRuleOptional(compileTarget);
if (existingRule.isPresent()) {
return (DCompileBuildRule) existingRule.get();
} else {
Tool compiler = dBuckConfig.getDCompiler();
Map<BuildTarget, DIncludes> transitiveIncludes = new TreeMap<>();
transitiveIncludes.put(baseParams.getBuildTarget(), includes);
for (Map.Entry<BuildTarget, DLibrary> library : getTransitiveDLibraryRules(baseParams.getDeps()).entrySet()) {
transitiveIncludes.put(library.getKey(), library.getValue().getIncludes());
}
ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
depsBuilder.addAll(compiler.getDeps(ruleFinder));
depsBuilder.addAll(ruleFinder.filterBuildRuleInputs(src));
for (DIncludes dIncludes : transitiveIncludes.values()) {
depsBuilder.addAll(dIncludes.getDeps(ruleFinder));
}
ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
return buildRuleResolver.addToIndex(new DCompileBuildRule(baseParams.withBuildTarget(compileTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps), Suppliers.ofInstance(ImmutableSortedSet.of())), compiler, ImmutableList.<String>builder().addAll(dBuckConfig.getBaseCompilerFlags()).addAll(compilerFlags).build(), name, ImmutableSortedSet.of(src), ImmutableList.copyOf(transitiveIncludes.values())));
}
}
Aggregations