use of com.google.common.collect.ImmutableList in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunction method getSkyKeys.
public static ImmutableList<SkyKey> getSkyKeys(SkyKey skyKey, EventHandler eventHandler) {
TargetPatternSequence targetPatternSequence = (TargetPatternSequence) skyKey.argument();
Iterable<PrepareDepsOfPatternSkyKeyOrException> keysMaybe = PrepareDepsOfPatternValue.keys(targetPatternSequence.getPatterns(), targetPatternSequence.getOffset());
ImmutableList.Builder<SkyKey> skyKeyBuilder = ImmutableList.builder();
boolean handlerIsParseFailureListener = eventHandler instanceof ParseFailureListener;
for (PrepareDepsOfPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
try {
skyKeyBuilder.add(skyKeyOrException.getSkyKey());
} catch (TargetParsingException e) {
handleTargetParsingException(eventHandler, handlerIsParseFailureListener, skyKeyOrException.getOriginalPattern(), e);
}
}
return skyKeyBuilder.build();
}
use of com.google.common.collect.ImmutableList in project bazel by bazelbuild.
the class SkyframeTargetPatternEvaluator method parseTargetPatternList.
/**
* Loads a list of target patterns (eg, "foo/..."). When policy is set to FILTER_TESTS,
* test_suites are going to be expanded.
*/
ResolvedTargets<Target> parseTargetPatternList(String offset, ExtendedEventHandler eventHandler, List<String> targetPatterns, FilteringPolicy policy, boolean keepGoing) throws InterruptedException, TargetParsingException {
Iterable<TargetPatternSkyKeyOrException> keysMaybe = TargetPatternValue.keys(targetPatterns, policy, offset);
ImmutableList.Builder<SkyKey> builder = ImmutableList.builder();
for (TargetPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
try {
builder.add(skyKeyOrException.getSkyKey());
} catch (TargetParsingException e) {
if (!keepGoing) {
throw e;
}
String pattern = skyKeyOrException.getOriginalPattern();
eventHandler.handle(Event.error("Skipping '" + pattern + "': " + e.getMessage()));
if (eventHandler instanceof ParseFailureListener) {
((ParseFailureListener) eventHandler).parsingError(pattern, e.getMessage());
}
}
}
ImmutableList<SkyKey> skyKeys = builder.build();
return parseTargetPatternKeys(targetPatterns, skyKeys, SkyframeExecutor.DEFAULT_THREAD_COUNT, keepGoing, eventHandler, createTargetPatternEvaluatorUtil(policy, eventHandler, keepGoing));
}
use of com.google.common.collect.ImmutableList in project bazel by bazelbuild.
the class BazelJavaCompiler method newInstance.
private static JavaCompiler newInstance(final JavaCompiler delegate) {
// We forward most operations to the JavaCompiler implementation in langtools.jar.
return new JavaCompiler() {
@Override
public CompilationTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
// We prepend bazel's default javacopts to user javacopts,
// so that the user can override them. javac supports this
// "last option wins" style of option override.
ImmutableList.Builder<String> fullOptions = ImmutableList.builder();
fullOptions.addAll(getDefaultJavacopts());
if (options != null) {
fullOptions.addAll(options);
}
return delegate.getTask(out, fileManager, diagnosticListener, fullOptions.build(), classes, compilationUnits);
}
@Override
public StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
StandardJavaFileManager fileManager = delegate.getStandardFileManager(diagnosticListener, locale, charset);
try {
fileManager.setLocation(// bootclasspath
StandardLocation.PLATFORM_CLASS_PATH, JavacBootclasspath.asFiles());
} catch (IOException e) {
// Should never happen, according to javadocs for setLocation
throw new RuntimeException(e);
}
return fileManager;
}
@Override
public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
// prepend bazel's default javacopts to user arguments
List<String> args = ImmutableList.<String>builder().addAll(getDefaultJavacopts()).add(arguments).build();
return delegate.run(in, out, err, args.toArray(new String[0]));
}
@Override
public Set<SourceVersion> getSourceVersions() {
return delegate.getSourceVersions();
}
@Override
public int isSupportedOption(String option) {
return delegate.isSupportedOption(option);
}
};
}
use of com.google.common.collect.ImmutableList in project bazel by bazelbuild.
the class JavacTurbine method compile.
Result compile() throws IOException {
ImmutableList.Builder<String> argbuilder = ImmutableList.builder();
argbuilder.addAll(JavacOptions.removeBazelSpecificFlags(turbineOptions.javacOpts()));
// Disable compilation of implicit source files.
// This is insurance: the sourcepath is empty, so we don't expect implicit sources.
argbuilder.add("-implicit:none");
// Disable debug info
argbuilder.add("-g:none");
// Enable MethodParameters
argbuilder.add("-parameters");
// Compile-time jars always use Java 8
argbuilder.add("-source");
argbuilder.add("8");
argbuilder.add("-target");
argbuilder.add("8");
ImmutableList<Path> processorpath;
if (!turbineOptions.processors().isEmpty()) {
argbuilder.add("-processor");
argbuilder.add(Joiner.on(',').join(turbineOptions.processors()));
processorpath = asPaths(turbineOptions.processorPath());
// see b/31371210
argbuilder.add("-Aexperimental_turbine_hjar");
} else {
processorpath = ImmutableList.of();
}
ImmutableList<Path> sources = ImmutableList.<Path>builder().addAll(asPaths(turbineOptions.sources())).addAll(getSourceJarEntries(turbineOptions)).build();
JavacTurbineCompileRequest.Builder requestBuilder = JavacTurbineCompileRequest.builder().setSources(sources).setJavacOptions(argbuilder.build()).setBootClassPath(asPaths(turbineOptions.bootClassPath())).setProcessorClassPath(processorpath);
// JavaBuilder exempts some annotation processors from Strict Java Deps enforcement.
// To avoid having to apply the same exemptions here, we just ignore strict deps errors
// and leave enforcement to JavaBuilder.
DependencyModule dependencyModule = buildDependencyModule(turbineOptions, StrictJavaDeps.WARN);
if (sources.isEmpty()) {
// accept compilations with an empty source list for compatibility with JavaBuilder
emitClassJar(Paths.get(turbineOptions.outputFile()), ImmutableMap.<String, OutputFileObject>of());
dependencyModule.emitDependencyInformation(/*classpath=*/
"", /*successful=*/
true);
return Result.OK_WITH_REDUCED_CLASSPATH;
}
Result result = Result.ERROR;
JavacTurbineCompileResult compileResult;
List<String> actualClasspath;
List<String> originalClasspath = turbineOptions.classPath();
List<String> compressedClasspath = dependencyModule.computeStrictClasspath(turbineOptions.classPath());
requestBuilder.setStrictDepsPlugin(new StrictJavaDepsPlugin(dependencyModule));
{
// compile with reduced classpath
actualClasspath = compressedClasspath;
requestBuilder.setClassPath(asPaths(actualClasspath));
compileResult = JavacTurbineCompiler.compile(requestBuilder.build());
if (compileResult.success()) {
result = Result.OK_WITH_REDUCED_CLASSPATH;
context = compileResult.context();
}
}
if (!compileResult.success() && hasRecognizedError(compileResult.output())) {
// fall back to transitive classpath
actualClasspath = originalClasspath;
requestBuilder.setClassPath(asPaths(actualClasspath));
compileResult = JavacTurbineCompiler.compile(requestBuilder.build());
if (compileResult.success()) {
result = Result.OK_WITH_FULL_CLASSPATH;
context = compileResult.context();
}
}
if (result.ok()) {
emitClassJar(Paths.get(turbineOptions.outputFile()), compileResult.files());
dependencyModule.emitDependencyInformation(CLASSPATH_JOINER.join(actualClasspath), compileResult.success());
} else {
out.print(compileResult.output());
}
return result;
}
use of com.google.common.collect.ImmutableList in project bazel by bazelbuild.
the class CppLinkActionTest method assertLinkSizeAccuracy.
private void assertLinkSizeAccuracy(int inputs) throws Exception {
ImmutableList.Builder<Artifact> objects = ImmutableList.builder();
for (int i = 0; i < inputs; i++) {
objects.add(getOutputArtifact("object" + i + ".o"));
}
CppLinkAction linkAction = createLinkBuilder(Link.LinkTargetType.EXECUTABLE, "dummyRuleContext/binary2", objects.build(), ImmutableList.<LibraryToLink>of(), new FeatureConfiguration()).setFake(true).build();
// Ensure that minima are enforced.
ResourceSet resources = linkAction.estimateResourceConsumptionLocal();
assertTrue(resources.getMemoryMb() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb());
assertTrue(resources.getCpuUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage());
assertTrue(resources.getIoUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage());
final int linkSize = Iterables.size(linkAction.getLinkCommandLine().getLinkerInputs());
ResourceSet scaledSet = ResourceSet.createWithRamCpuIo(CppLinkAction.LINK_RESOURCES_PER_INPUT.getMemoryMb() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getCpuUsage() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getIoUsage() * linkSize);
// Ensure that anything above the minimum is properly scaled.
assertTrue(resources.getMemoryMb() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb() || resources.getMemoryMb() == scaledSet.getMemoryMb());
assertTrue(resources.getCpuUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage() || resources.getCpuUsage() == scaledSet.getCpuUsage());
assertTrue(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() || resources.getIoUsage() == scaledSet.getIoUsage());
}
Aggregations