Search in sources :

Example 21 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class AppleSimulatorController method launchInstalledBundleInSimulator.

/**
   * Launches a previously-installed bundle in a started simulator.
   *
   * @return the process ID of the newly-launched process if successful,
   * an absent value otherwise.
   */
public Optional<Long> launchInstalledBundleInSimulator(String simulatorUdid, String bundleID, LaunchBehavior launchBehavior, List<String> args) throws IOException, InterruptedException {
    ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
    commandBuilder.add(simctlPath.toString(), "launch");
    if (launchBehavior == LaunchBehavior.WAIT_FOR_DEBUGGER) {
        commandBuilder.add("-w");
    }
    commandBuilder.add(simulatorUdid, bundleID);
    commandBuilder.addAll(args);
    ImmutableList<String> command = commandBuilder.build();
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(command).build();
    Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
    String message = String.format("Launching bundle ID %s in simulator %s via command %s", bundleID, simulatorUdid, command);
    LOG.debug(message);
    ProcessExecutor.Result result = processExecutor.launchAndExecute(processExecutorParams, options, /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    if (result.getExitCode() != 0) {
        LOG.error(result.getMessageForResult(message));
        return Optional.empty();
    }
    Preconditions.checkState(result.getStdout().isPresent());
    String trimmedStdout = result.getStdout().get().trim();
    Matcher stdoutMatcher = SIMCTL_LAUNCH_OUTPUT_PATTERN.matcher(trimmedStdout);
    if (!stdoutMatcher.find()) {
        LOG.error("Could not parse output from %s: %s", command, trimmedStdout);
        return Optional.empty();
    }
    return Optional.of(Long.parseLong(stdoutMatcher.group(1), 10));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 22 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class CxxInferAnalyze method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(specsDir);
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return ImmutableList.<Step>builder().add(new MkdirStep(getProjectFilesystem(), specsDir)).add(new SymCopyStep(getProjectFilesystem(), captureAndAnalyzeRules.captureRules.stream().map(CxxInferCapture::getSourcePathToOutput).map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableList()), resultsDir)).add(new AbstractExecutionStep("write_specs_path_list") {

        @Override
        public StepExecutionResult execute(ExecutionContext executionContext) throws IOException {
            try {
                ImmutableList<String> specsDirsWithAbsolutePath = getSpecsOfAllDeps().stream().map(input -> context.getSourcePathResolver().getAbsolutePath(input).toString()).collect(MoreCollectors.toImmutableList());
                getProjectFilesystem().writeLinesToPath(specsDirsWithAbsolutePath, specsPathList);
            } catch (IOException e) {
                executionContext.logError(e, "Error while writing specs path list file for the analyzer");
                return StepExecutionResult.ERROR;
            }
            return StepExecutionResult.SUCCESS;
        }
    }).add(new DefaultShellStep(getProjectFilesystem().getRootPath(), getAnalyzeCommand(), ImmutableMap.of())).build();
}
Also used : DefaultShellStep(com.facebook.buck.shell.DefaultShellStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ImmutableList(com.google.common.collect.ImmutableList) SymCopyStep(com.facebook.buck.step.fs.SymCopyStep) IOException(java.io.IOException)

Example 23 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class AbstractPrebuiltCxxLibraryGroupDescription method getSharedLinkArgs.

/**
   * @return the link args formed from the user-provided shared link line after resolving library
   *         macro references.
   */
private Iterable<Arg> getSharedLinkArgs(BuildTarget target, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) {
    ImmutableList.Builder<Arg> builder = ImmutableList.builder();
    for (String arg : args) {
        Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg);
        if (libRef.isPresent()) {
            SourcePath lib = libs.get(libRef.get().getSecond());
            if (lib == null) {
                throw new HumanReadableException("%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg);
            }
            Arg libArg;
            if (libRef.get().getFirst().equals(LIB_MACRO)) {
                libArg = SourcePathArg.of(lib);
            } else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) {
                if (!(lib instanceof PathSourcePath)) {
                    throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target);
                }
                libArg = new RelativeLinkArg((PathSourcePath) lib);
            } else {
                throw new IllegalStateException();
            }
            builder.add(libArg);
        } else {
            builder.add(StringArg.of(arg));
        }
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableList(com.google.common.collect.ImmutableList) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Pair(com.facebook.buck.model.Pair)

Example 24 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class Archive method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    // Cache the archive we built.
    buildableContext.recordArtifact(output);
    SourcePathResolver resolver = context.getSourcePathResolver();
    // paths.
    for (SourcePath input : inputs) {
        Preconditions.checkState(resolver.getFilesystem(input).getRootPath().equals(getProjectFilesystem().getRootPath()));
    }
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    builder.add(new MkdirStep(getProjectFilesystem(), output.getParent()), new RmStep(getProjectFilesystem(), output), new ArchiveStep(getProjectFilesystem(), archiver.getEnvironment(resolver), archiver.getCommandPrefix(resolver), archiverFlags, archiver.getArchiveOptions(contents == Contents.THIN), output, inputs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), archiver));
    if (archiver.isRanLibStepRequired()) {
        builder.add(new RanlibStep(getProjectFilesystem(), ranlib.getEnvironment(resolver), ranlib.getCommandPrefix(resolver), ranlibFlags, output));
    }
    if (!archiver.getScrubbers().isEmpty()) {
        builder.add(new FileScrubberStep(getProjectFilesystem(), output, archiver.getScrubbers()));
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep)

Example 25 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class CxxBoostTest method parseResults.

@Override
protected ImmutableList<TestResultSummary> parseResults(Path exitCode, Path output, Path results) throws Exception {
    ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
    // Process the test run output to grab the individual test stdout/stderr and
    // test run times.
    Map<String, String> messages = Maps.newHashMap();
    Map<String, List<String>> stdout = Maps.newHashMap();
    Map<String, Long> times = Maps.newHashMap();
    try (BufferedReader reader = Files.newBufferedReader(output, Charsets.US_ASCII)) {
        Stack<String> testSuite = new Stack<>();
        Optional<String> currentTest = Optional.empty();
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher;
            if ((matcher = SUITE_START.matcher(line)).matches()) {
                String suite = matcher.group(1);
                testSuite.push(suite);
            } else if ((matcher = SUITE_END.matcher(line)).matches()) {
                String suite = matcher.group(1);
                Preconditions.checkState(testSuite.peek().equals(suite));
                testSuite.pop();
            } else if ((matcher = CASE_START.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                currentTest = Optional.of(test);
                stdout.put(test, Lists.newArrayList());
            } else if ((matcher = CASE_END.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                Preconditions.checkState(currentTest.isPresent() && currentTest.get().equals(test));
                String time = matcher.group(2);
                times.put(test, time == null ? 0 : Long.valueOf(time));
                currentTest = Optional.empty();
            } else if (currentTest.isPresent()) {
                if (ERROR.matcher(line).matches()) {
                    messages.put(currentTest.get(), line);
                } else {
                    Preconditions.checkNotNull(stdout.get(currentTest.get())).add(line);
                }
            }
        }
    }
    // Parse the XML result file for the actual test result summaries.
    Document doc = XmlDomParser.parse(results);
    Node testResult = doc.getElementsByTagName("TestResult").item(0);
    Node testSuite = testResult.getFirstChild();
    visitTestSuite(summariesBuilder, messages, stdout, times, "", testSuite);
    return summariesBuilder.build();
}
Also used : Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Node(org.w3c.dom.Node) TestResultSummary(com.facebook.buck.test.TestResultSummary) Document(org.w3c.dom.Document) Stack(java.util.Stack) BufferedReader(java.io.BufferedReader) ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1056 List (java.util.List)291 ArrayList (java.util.ArrayList)166 Test (org.junit.Test)156 Path (java.nio.file.Path)149 Map (java.util.Map)149 ImmutableMap (com.google.common.collect.ImmutableMap)124 IOException (java.io.IOException)111 Set (java.util.Set)99 ImmutableSet (com.google.common.collect.ImmutableSet)97 SourcePath (com.facebook.buck.rules.SourcePath)91 Optional (java.util.Optional)87 HashMap (java.util.HashMap)84 Step (com.facebook.buck.step.Step)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)71 Collectors (java.util.stream.Collectors)61 File (java.io.File)58 HashSet (java.util.HashSet)57 Nullable (javax.annotation.Nullable)54 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52