Search in sources :

Example 51 with ImmutableList

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ImmutableList(com.google.common.collect.ImmutableList) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener) PrepareDepsOfPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternValue.PrepareDepsOfPatternSkyKeyOrException) TargetPatternSequence(com.google.devtools.build.lib.skyframe.PrepareDepsOfPatternsValue.TargetPatternSequence)

Example 52 with ImmutableList

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));
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ImmutableList(com.google.common.collect.ImmutableList) ParseFailureListener(com.google.devtools.build.lib.pkgcache.ParseFailureListener) TargetPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException)

Example 53 with ImmutableList

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);
        }
    };
}
Also used : Locale(java.util.Locale) JavaFileManager(javax.tools.JavaFileManager) StandardJavaFileManager(javax.tools.StandardJavaFileManager) ImmutableList(com.google.common.collect.ImmutableList) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) JavaCompiler(javax.tools.JavaCompiler) Charset(java.nio.charset.Charset) DiagnosticListener(javax.tools.DiagnosticListener) SourceVersion(javax.lang.model.SourceVersion) IOException(java.io.IOException) JavaFileObject(javax.tools.JavaFileObject) StandardJavaFileManager(javax.tools.StandardJavaFileManager) Writer(java.io.Writer)

Example 54 with ImmutableList

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;
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) DependencyModule(com.google.devtools.build.buildjar.javac.plugins.dependency.DependencyModule) StrictJavaDepsPlugin(com.google.devtools.build.buildjar.javac.plugins.dependency.StrictJavaDepsPlugin) FileVisitResult(java.nio.file.FileVisitResult)

Example 55 with ImmutableList

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)552 Path (java.nio.file.Path)130 List (java.util.List)112 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)78 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)64 ArrayList (java.util.ArrayList)63 Map (java.util.Map)62 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 ImmutableSet (com.google.common.collect.ImmutableSet)44 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 Optional (java.util.Optional)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 HashMap (java.util.HashMap)35