Search in sources :

Example 1 with OptionsProvider

use of com.google.devtools.common.options.OptionsProvider in project bazel by bazelbuild.

the class BlazeRuntime method newRuntime.

/**
   * Creates a new blaze runtime, given the install and output base directories.
   *
   * <p>Note: This method can and should only be called once per startup, as it also creates the
   * filesystem object that will be used for the runtime. So it should only ever be called from the
   * main method of the Blaze program.
   *
   * @param args Blaze startup options.
   *
   * @return a new BlazeRuntime instance initialized with the given filesystem and directories, and
   *         an error string that, if not null, describes a fatal initialization failure that makes
   *         this runtime unsuitable for real commands
   */
private static BlazeRuntime newRuntime(Iterable<BlazeModule> blazeModules, List<String> args, Runnable abruptShutdownHandler) throws AbruptExitException, OptionsParsingException {
    OptionsProvider options = parseOptions(blazeModules, args);
    for (BlazeModule module : blazeModules) {
        module.globalInit(options);
    }
    BlazeServerStartupOptions startupOptions = options.getOptions(BlazeServerStartupOptions.class);
    String productName = startupOptions.productName.toLowerCase(Locale.US);
    if (startupOptions.oomMoreEagerlyThreshold != 100) {
        new RetainedHeapLimiter(startupOptions.oomMoreEagerlyThreshold).install();
    }
    PathFragment workspaceDirectory = startupOptions.workspaceDirectory;
    PathFragment installBase = startupOptions.installBase;
    PathFragment outputBase = startupOptions.outputBase;
    // Must be before first use of JNI.
    maybeForceJNI(installBase);
    // are mandatory options, despite the comment in their declarations.
    if (installBase == null || !installBase.isAbsolute()) {
        // (includes "" default case)
        throw new IllegalArgumentException("Bad --install_base option specified: '" + installBase + "'");
    }
    if (outputBase != null && !outputBase.isAbsolute()) {
        // (includes "" default case)
        throw new IllegalArgumentException("Bad --output_base option specified: '" + outputBase + "'");
    }
    FileSystem fs = null;
    for (BlazeModule module : blazeModules) {
        FileSystem moduleFs = module.getFileSystem(options);
        if (moduleFs != null) {
            Preconditions.checkState(fs == null, "more than one module returns a file system");
            fs = moduleFs;
        }
    }
    if (fs == null) {
        fs = fileSystemImplementation();
    }
    Path.setFileSystemForSerialization(fs);
    SubprocessBuilder.setSubprocessFactory(subprocessFactoryImplementation());
    Path installBasePath = fs.getPath(installBase);
    Path outputBasePath = fs.getPath(outputBase);
    Path workspaceDirectoryPath = null;
    if (!workspaceDirectory.equals(PathFragment.EMPTY_FRAGMENT)) {
        workspaceDirectoryPath = fs.getPath(workspaceDirectory);
    }
    ServerDirectories serverDirectories = new ServerDirectories(installBasePath, outputBasePath, startupOptions.installMD5);
    Clock clock = BlazeClock.instance();
    BlazeRuntime.Builder runtimeBuilder = new BlazeRuntime.Builder().setProductName(productName).setServerDirectories(serverDirectories).setStartupOptionsProvider(options).setClock(clock).setAbruptShutdownHandler(abruptShutdownHandler).setEventBusExceptionHandler(startupOptions.fatalEventBusExceptions || !BlazeVersionInfo.instance().isReleasedBlaze() ? new BlazeRuntime.BugReportingExceptionHandler() : new BlazeRuntime.RemoteExceptionHandler());
    if (System.getenv("TEST_TMPDIR") != null && System.getenv("NO_CRASH_ON_LOGGING_IN_TEST") == null) {
        LoggingUtil.installRemoteLogger(getTestCrashLogger());
    }
    runtimeBuilder.addBlazeModule(new BuiltinCommandModule());
    for (BlazeModule blazeModule : blazeModules) {
        runtimeBuilder.addBlazeModule(blazeModule);
    }
    BlazeRuntime runtime = runtimeBuilder.build();
    BlazeDirectories directories = new BlazeDirectories(serverDirectories, workspaceDirectoryPath, startupOptions.deepExecRoot, productName);
    BinTools binTools;
    try {
        binTools = BinTools.forProduction(directories);
    } catch (IOException e) {
        throw new AbruptExitException("Cannot enumerate embedded binaries: " + e.getMessage(), ExitCode.LOCAL_ENVIRONMENTAL_ERROR);
    }
    runtime.initWorkspace(directories, binTools);
    if (startupOptions.useCustomExitCodeOnAbruptExit) {
        CustomExitCodePublisher.setAbruptExitStatusFileDir(serverDirectories.getOutputBase());
    }
    AutoProfiler.setClock(runtime.getClock());
    BugReport.setRuntime(runtime);
    return runtime;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) OptionsProvider(com.google.devtools.common.options.OptionsProvider) SubprocessBuilder(com.google.devtools.build.lib.shell.SubprocessBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) Clock(com.google.devtools.build.lib.util.Clock) BlazeClock(com.google.devtools.build.lib.util.BlazeClock) ServerDirectories(com.google.devtools.build.lib.analysis.ServerDirectories) BinTools(com.google.devtools.build.lib.analysis.config.BinTools) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) JavaIoFileSystem(com.google.devtools.build.lib.vfs.JavaIoFileSystem) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) WindowsFileSystem(com.google.devtools.build.lib.windows.WindowsFileSystem) UnixFileSystem(com.google.devtools.build.lib.unix.UnixFileSystem) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException)

Aggregations

BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ServerDirectories (com.google.devtools.build.lib.analysis.ServerDirectories)1 BinTools (com.google.devtools.build.lib.analysis.config.BinTools)1 SubprocessBuilder (com.google.devtools.build.lib.shell.SubprocessBuilder)1 UnixFileSystem (com.google.devtools.build.lib.unix.UnixFileSystem)1 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)1 BlazeClock (com.google.devtools.build.lib.util.BlazeClock)1 Clock (com.google.devtools.build.lib.util.Clock)1 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)1 JavaIoFileSystem (com.google.devtools.build.lib.vfs.JavaIoFileSystem)1 Path (com.google.devtools.build.lib.vfs.Path)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 WindowsFileSystem (com.google.devtools.build.lib.windows.WindowsFileSystem)1 OptionsProvider (com.google.devtools.common.options.OptionsProvider)1 IOException (java.io.IOException)1