use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class StringResources method writeArrays.
/**
* Writes the metadata and strings in the following format to the output stream:
* [Int: # of arrays]
* [Int: Smallest resource id among arrays]
* [[Short: resource id delta] [Byte: #genders] [[Byte: gender enum ordinal] [Int: #elements]
* [[Short: length of element] x # of elements]] x # of genders] x # of arrays
* [Byte array of string value] x Summation of genders over array elements over # of arrays
* @param outputStream
* @throws IOException
*/
private void writeArrays(DataOutputStream outputStream) throws IOException {
outputStream.writeInt(arrays.keySet().size());
if (arrays.keySet().isEmpty()) {
return;
}
int previousResourceId = arrays.firstKey();
outputStream.writeInt(previousResourceId);
try (ByteArrayOutputStream dataStream = new ByteArrayOutputStream()) {
for (Map.Entry<Integer, EnumMap<Gender, ImmutableList<String>>> entry : arrays.entrySet()) {
writeShort(outputStream, entry.getKey() - previousResourceId);
EnumMap<Gender, ImmutableList<String>> genderMap = entry.getValue();
outputStream.writeByte(genderMap.size());
for (Map.Entry<Gender, ImmutableList<String>> gender : genderMap.entrySet()) {
outputStream.writeByte(gender.getKey().ordinal());
ImmutableList<String> arrayElements = gender.getValue();
outputStream.writeByte(arrayElements.size());
for (String arrayValue : arrayElements) {
byte[] byteValue = getUnescapedStringBytes(arrayValue);
writeShort(outputStream, byteValue.length);
dataStream.write(byteValue);
}
}
previousResourceId = entry.getKey();
}
outputStream.write(dataStream.toByteArray());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList 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 org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class MergeAndroidResourceSources method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), destinationDirectory));
steps.add(new MergeAndroidResourceSourcesStep(originalDirectories.stream().map(context.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableList()), getProjectFilesystem().resolve(destinationDirectory), getProjectFilesystem().resolve(tempDirectory)));
buildableContext.recordArtifact(destinationDirectory);
return steps.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class AuditFlavorsCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig()).stream().map(input -> BuildTargetParser.INSTANCE.parse(input, BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver())).collect(MoreCollectors.toImmutableSet());
if (targets.isEmpty()) {
params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
return 1;
}
ImmutableList.Builder<TargetNode<?, ?>> builder = ImmutableList.builder();
try (CommandThreadManager pool = new CommandThreadManager("Audit", getConcurrencyLimit(params.getBuckConfig()))) {
for (BuildTarget target : targets) {
TargetNode<?, ?> targetNode = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), target);
builder.add(targetNode);
}
} catch (BuildFileParseException | BuildTargetException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
ImmutableList<TargetNode<?, ?>> targetNodes = builder.build();
if (shouldGenerateJsonOutput()) {
printJsonFlavors(targetNodes, params);
} else {
printFlavors(targetNodes, params);
}
return 0;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class CxxLibraryDescription method createSharedLibrary.
/**
* Create all build rules needed to generate the shared library.
*
* @return the {@link CxxLink} rule representing the actual shared library.
*/
private static CxxLink createSharedLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, CxxLibraryDescription.Arg args, ImmutableList<StringWithMacros> linkerFlags, ImmutableSet<FrameworkPath> frameworks, ImmutableSet<FrameworkPath> libraries, Optional<String> soname, Optional<Linker.CxxRuntimeType> cxxRuntimeType, Linker.LinkType linkType, Linker.LinkableDepType linkableDepType, Optional<SourcePath> bundleLoader, ImmutableSet<BuildTarget> blacklist) throws NoSuchBuildTargetException {
Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
// Create rules for compiling the PIC object files.
ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = requireObjects(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, CxxSourceRuleFactory.PicType.PIC, args);
// Setup the rules to link the shared library.
BuildTarget sharedTarget = CxxDescriptionEnhancer.createSharedLibraryBuildTarget(LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode).getBuildTarget(), cxxPlatform.getFlavor(), linkType);
String sharedLibrarySoname = CxxDescriptionEnhancer.getSharedLibrarySoname(soname, params.getBuildTarget(), cxxPlatform);
Path sharedLibraryPath = CxxDescriptionEnhancer.getSharedLibraryPath(params.getProjectFilesystem(), sharedTarget, sharedLibrarySoname);
ImmutableList.Builder<StringWithMacros> extraLdFlagsBuilder = ImmutableList.builder();
extraLdFlagsBuilder.addAll(linkerFlags);
ImmutableList<StringWithMacros> extraLdFlags = extraLdFlagsBuilder.build();
return CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode), ruleResolver, pathResolver, ruleFinder, sharedTarget, linkType, Optional.of(sharedLibrarySoname), sharedLibraryPath, linkableDepType, Iterables.filter(params.getDeps(), NativeLinkable.class), cxxRuntimeType, bundleLoader, blacklist, NativeLinkableInput.builder().addAllArgs(CxxDescriptionEnhancer.toStringWithMacrosArgs(params.getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, extraLdFlags)).addAllArgs(SourcePathArg.from(objects.values())).setFrameworks(frameworks).setLibraries(libraries).build());
}
Aggregations