Beispiel #1
0
 private void reportTargets(AnalysisResult analysisResult) {
   Collection<ConfiguredTarget> targetsToBuild = analysisResult.getTargetsToBuild();
   Collection<ConfiguredTarget> targetsToTest = analysisResult.getTargetsToTest();
   if (targetsToTest != null) {
     int testCount = targetsToTest.size();
     int targetCount = targetsToBuild.size() - testCount;
     if (targetCount == 0) {
       getReporter()
           .handle(
               Event.info(
                   "Found "
                       + testCount
                       + (testCount == 1 ? " test target..." : " test targets...")));
     } else {
       getReporter()
           .handle(
               Event.info(
                   "Found "
                       + targetCount
                       + (targetCount == 1 ? " target and " : " targets and ")
                       + testCount
                       + (testCount == 1 ? " test target..." : " test targets...")));
     }
   } else {
     int targetCount = targetsToBuild.size();
     getReporter()
         .handle(
             Event.info(
                 "Found " + targetCount + (targetCount == 1 ? " target..." : " targets...")));
   }
 }
Beispiel #2
0
 // Kill workers on Ctrl-C to quickly end the interrupted build.
 // TODO(philwo) - make sure that this actually *kills* the workers and not just politely waits
 // for them to finish.
 @Subscribe
 public void buildInterrupted(BuildInterruptedEvent event) {
   if (workers != null) {
     if (verbose) {
       env.getReporter().handle(Event.info("Build interrupted, shutting down worker pool..."));
     }
     workers.close();
     workers = null;
   }
 }
Beispiel #3
0
 @Subscribe
 public void buildComplete(BuildCompleteEvent event) {
   if (workers != null && buildRequest.getOptions(WorkerOptions.class).workerQuitAfterBuild) {
     if (verbose) {
       env.getReporter().handle(Event.info("Build completed, shutting down worker pool..."));
     }
     workers.close();
     workers = null;
   }
 }
Beispiel #4
0
 private static void deserializeEvent(StoredEventHandler eventHandler, Build.Event event) {
   String message = event.getMessage();
   switch (event.getKind()) {
     case ERROR:
       eventHandler.handle(Event.error(message));
       break;
     case WARNING:
       eventHandler.handle(Event.warn(message));
       break;
     case INFO:
       eventHandler.handle(Event.info(message));
       break;
     case PROGRESS:
       eventHandler.handle(Event.progress(message));
       break;
     default:
       break; // Ignore
   }
 }
Beispiel #5
0
  @Override
  public ExitCode exec(CommandEnvironment env, OptionsProvider options)
      throws ShutdownBlazeServerException {
    BlazeRuntime runtime = env.getRuntime();
    Options cleanOptions = options.getOptions(Options.class);
    cleanOptions.expunge_async = cleanOptions.cleanStyle.equals("expunge_async");
    cleanOptions.expunge = cleanOptions.cleanStyle.equals("expunge");

    if (!cleanOptions.expunge
        && !cleanOptions.expunge_async
        && !cleanOptions.cleanStyle.isEmpty()) {
      env.getReporter()
          .handle(Event.error(null, "Invalid clean_style value '" + cleanOptions.cleanStyle + "'"));
      return ExitCode.COMMAND_LINE_ERROR;
    }

    String cleanBanner =
        cleanOptions.expunge_async
            ? "Starting clean."
            : "Starting clean (this may take a while). "
                + "Consider using --expunge_async if the clean takes more than several minutes.";

    env.getReporter().handle(Event.info(null /*location*/, cleanBanner));
    try {
      String symlinkPrefix =
          options.getOptions(BuildRequest.BuildRequestOptions.class).getSymlinkPrefix();
      actuallyClean(env, runtime.getOutputBase(), cleanOptions, symlinkPrefix);
      return ExitCode.SUCCESS;
    } catch (IOException e) {
      env.getReporter().handle(Event.error(e.getMessage()));
      return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
    } catch (CommandException | ExecException e) {
      env.getReporter().handle(Event.error(e.getMessage()));
      return ExitCode.RUN_FAILURE;
    } catch (InterruptedException e) {
      env.getReporter().handle(Event.error("clean interrupted"));
      return ExitCode.INTERRUPTED;
    }
  }
Beispiel #6
0
 public Sender(
     String url, String secret, CommandEnvironment env, ExecutorService executorService)
     throws SenderException {
   this.reporter = env.getReporter();
   this.secret = readSecret(secret, reporter);
   try {
     this.url = new URL(url);
     if (!this.secret.isEmpty()) {
       if (!(this.url.getProtocol().equals("https")
           || this.url.getHost().equals("localhost")
           || this.url.getHost().matches("^127.0.0.[0-9]+$"))) {
         reporter.handle(
             Event.warn(
                 "Using authentication over unsecure channel, " + "consider using HTTPS."));
       }
     }
   } catch (MalformedURLException e) {
     throw new SenderException("Invalid server url " + url, e);
   }
   this.buildId = env.getCommandId().toString();
   this.executorService = executorService;
   sendMessage("test", null); // test connecting to the server.
   reporter.handle(Event.info("Results are being streamed to " + url + "/result/" + buildId));
 }
Beispiel #7
0
  private void actuallyClean(
      CommandEnvironment env, Path outputBase, Options cleanOptions, String symlinkPrefix)
      throws IOException, ShutdownBlazeServerException, CommandException, ExecException,
          InterruptedException {
    BlazeRuntime runtime = env.getRuntime();
    if (env.getOutputService() != null) {
      env.getOutputService().clean();
    }
    if (cleanOptions.expunge) {
      LOG.info("Expunging...");
      // Delete the big subdirectories with the important content first--this
      // will take the most time. Then quickly delete the little locks, logs
      // and links right before we exit. Once the lock file is gone there will
      // be a small possibility of a server race if a client is waiting, but
      // all significant files will be gone by then.
      FileSystemUtils.deleteTreesBelow(outputBase);
      FileSystemUtils.deleteTree(outputBase);
    } else if (cleanOptions.expunge_async) {
      LOG.info("Expunging asynchronously...");
      String tempBaseName = outputBase.getBaseName() + "_tmp_" + ProcessUtils.getpid();

      // Keeping tempOutputBase in the same directory ensures it remains in the
      // same file system, and therefore the mv will be atomic and fast.
      Path tempOutputBase = outputBase.getParentDirectory().getChild(tempBaseName);
      outputBase.renameTo(tempOutputBase);
      env.getReporter()
          .handle(Event.info(null, "Output base moved to " + tempOutputBase + " for deletion"));

      // Daemonize the shell and use the double-fork idiom to ensure that the shell
      // exits even while the "rm -rf" command continues.
      String command =
          String.format(
              "exec >&- 2>&- <&- && (/usr/bin/setsid /bin/rm -rf %s &)&",
              ShellEscaper.escapeString(tempOutputBase.getPathString()));

      LOG.info("Executing shell commmand " + ShellEscaper.escapeString(command));

      // Doesn't throw iff command exited and was successful.
      new CommandBuilder()
          .addArg(command)
          .useShell(true)
          .setWorkingDir(tempOutputBase.getParentDirectory())
          .build()
          .execute();
    } else {
      LOG.info("Output cleaning...");
      runtime.clearCaches();
      // In order to be sure that we delete everything, delete the workspace directory both for
      // --deep_execroot and for --nodeep_execroot.
      for (String directory :
          new String[] {runtime.getWorkspaceName(), "execroot/" + runtime.getWorkspaceName()}) {
        Path child = outputBase.getRelative(directory);
        if (child.exists()) {
          LOG.finest("Cleaning " + child);
          FileSystemUtils.deleteTreesBelow(child);
        }
      }
    }
    // remove convenience links
    OutputDirectoryLinksUtils.removeOutputDirectoryLinks(
        runtime.getWorkspaceName(), runtime.getWorkspace(), env.getReporter(), symlinkPrefix);
    // shutdown on expunge cleans
    if (cleanOptions.expunge || cleanOptions.expunge_async) {
      throw new ShutdownBlazeServerException(0);
    }
  }