Search in sources :

Example 1 with RPCServer

use of com.google.devtools.build.lib.server.RPCServer in project bazel by bazelbuild.

the class BlazeRuntime method createBlazeRPCServer.

/**
   * Creates and returns a new Blaze RPCServer. Call {@link RPCServer#serve()} to start the server.
   */
private static RPCServer createBlazeRPCServer(Iterable<BlazeModule> modules, List<String> args) throws IOException, OptionsParsingException, AbruptExitException {
    final RPCServer[] rpcServer = new RPCServer[1];
    Runnable prepareForAbruptShutdown = new Runnable() {

        @Override
        public void run() {
            rpcServer[0].prepareForAbruptShutdown();
        }
    };
    BlazeRuntime runtime = newRuntime(modules, args, prepareForAbruptShutdown);
    BlazeCommandDispatcher dispatcher = new BlazeCommandDispatcher(runtime);
    CommandExecutor commandExecutor = new CommandExecutor(runtime, dispatcher);
    BlazeServerStartupOptions startupOptions = runtime.getStartupOptionsProvider().getOptions(BlazeServerStartupOptions.class);
    try {
        // This is necessary so that Bazel kind of works during bootstrapping, at which time the
        // gRPC server is not compiled in so that we don't need gRPC for bootstrapping.
        Class<?> factoryClass = Class.forName("com.google.devtools.build.lib.server.GrpcServerImpl$Factory");
        RPCServer.Factory factory = (RPCServer.Factory) factoryClass.getConstructor().newInstance();
        rpcServer[0] = factory.create(commandExecutor, runtime.getClock(), startupOptions.commandPort, runtime.getWorkspace().getWorkspace(), runtime.getServerDirectory(), startupOptions.maxIdleSeconds);
        return rpcServer[0];
    } catch (ReflectiveOperationException | IllegalArgumentException e) {
        throw new AbruptExitException("gRPC server not compiled in", ExitCode.BLAZE_INTERNAL_ERROR);
    }
}
Also used : CoverageReportActionFactory(com.google.devtools.build.lib.rules.test.CoverageReportActionFactory) QueryEnvironmentFactory(com.google.devtools.build.lib.query2.QueryEnvironmentFactory) WindowsSubprocessFactory(com.google.devtools.build.lib.windows.WindowsSubprocessFactory) JavaSubprocessFactory(com.google.devtools.build.lib.shell.JavaSubprocessFactory) ConfigurationFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFactory) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) RPCServer(com.google.devtools.build.lib.server.RPCServer) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException)

Example 2 with RPCServer

use of com.google.devtools.build.lib.server.RPCServer in project bazel by bazelbuild.

the class BlazeRuntime method serverMain.

/**
   * A main method that does not send email. The return value indicates the desired exit status of
   * the program.
   */
private static int serverMain(Iterable<BlazeModule> modules, OutErr outErr, String[] args) {
    InterruptSignalHandler sigintHandler = null;
    try {
        final RPCServer blazeServer = createBlazeRPCServer(modules, Arrays.asList(args));
        // Register the signal handler.
        sigintHandler = new InterruptSignalHandler() {

            @Override
            public void run() {
                LOG.severe("User interrupt");
                blazeServer.interrupt();
            }
        };
        blazeServer.serve();
        return ExitCode.SUCCESS.getNumericExitCode();
    } catch (OptionsParsingException e) {
        outErr.printErr(e.getMessage());
        return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode();
    } catch (IOException e) {
        outErr.printErr("I/O Error: " + e.getMessage());
        return ExitCode.BUILD_FAILURE.getNumericExitCode();
    } catch (AbruptExitException e) {
        outErr.printErr(e.getMessage());
        return e.getExitCode().getNumericExitCode();
    } finally {
        if (sigintHandler != null) {
            sigintHandler.uninstall();
        }
    }
}
Also used : InterruptSignalHandler(com.google.devtools.build.lib.server.signal.InterruptSignalHandler) RPCServer(com.google.devtools.build.lib.server.RPCServer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) IOException(java.io.IOException) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException)

Aggregations

RPCServer (com.google.devtools.build.lib.server.RPCServer)2 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)2 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 QueryEnvironmentFactory (com.google.devtools.build.lib.query2.QueryEnvironmentFactory)1 CoverageReportActionFactory (com.google.devtools.build.lib.rules.test.CoverageReportActionFactory)1 InterruptSignalHandler (com.google.devtools.build.lib.server.signal.InterruptSignalHandler)1 JavaSubprocessFactory (com.google.devtools.build.lib.shell.JavaSubprocessFactory)1 WindowsSubprocessFactory (com.google.devtools.build.lib.windows.WindowsSubprocessFactory)1 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)1 IOException (java.io.IOException)1