Search in sources :

Example 1 with BinTools

use of com.google.devtools.build.lib.analysis.config.BinTools 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)

Example 2 with BinTools

use of com.google.devtools.build.lib.analysis.config.BinTools in project bazel by bazelbuild.

the class AnalysisTestCase method useRuleClassProvider.

/**
   * Changes the rule class provider to be used for the loading and the analysis phase.
   */
protected void useRuleClassProvider(ConfiguredRuleClassProvider ruleClassProvider) throws Exception {
    this.ruleClassProvider = ruleClassProvider;
    PackageFactory pkgFactory = analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, scratch.getFileSystem());
    BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
    skyframeExecutor = SequencedSkyframeExecutor.create(pkgFactory, directories, binTools, workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), ImmutableList.<DiffAwareness.Factory>of(), Predicates.<PathFragment>alwaysFalse(), Preprocessor.Factory.Supplier.NullSupplier.INSTANCE, analysisMock.getSkyFunctions(), getPrecomputedValues(), ImmutableList.<SkyValueDirtinessChecker>of(), analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD));
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 3;
    skyframeExecutor.preparePackageLoading(pkgLocator, packageCacheOptions, ruleClassProvider.getDefaultsPackageContent(analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()), UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    packageManager = skyframeExecutor.getPackageManager();
    loadingPhaseRunner = skyframeExecutor.getLoadingPhaseRunner(pkgFactory.getRuleClassNames(), defaultFlags().contains(Flag.SKYFRAME_LOADING_PHASE));
    buildView = new BuildView(directories, ruleClassProvider, skyframeExecutor, null);
    useConfiguration();
}
Also used : BinTools(com.google.devtools.build.lib.analysis.config.BinTools) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) BuildView(com.google.devtools.build.lib.analysis.BuildView) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ConfigurationFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFactory) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) SkyValueDirtinessChecker(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Aggregations

BinTools (com.google.devtools.build.lib.analysis.config.BinTools)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 BuildView (com.google.devtools.build.lib.analysis.BuildView)1 ServerDirectories (com.google.devtools.build.lib.analysis.ServerDirectories)1 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)1 SubprocessBuilder (com.google.devtools.build.lib.shell.SubprocessBuilder)1 SkyValueDirtinessChecker (com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker)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 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)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 WindowsFileSystem (com.google.devtools.build.lib.windows.WindowsFileSystem)1 OptionsProvider (com.google.devtools.common.options.OptionsProvider)1