use of com.google.devtools.build.lib.analysis.ServerDirectories in project bazel by bazelbuild.
the class CommandInterruptionTest method setUp.
@Before
public void setUp() throws Exception {
executor = Executors.newSingleThreadExecutor();
Scratch scratch = new Scratch();
isTestShuttingDown = new AtomicBoolean(false);
String productName = TestConstants.PRODUCT_NAME;
ServerDirectories serverDirectories = new ServerDirectories(scratch.dir("install"), scratch.dir("output"));
BlazeRuntime runtime = new BlazeRuntime.Builder().setProductName(productName).setServerDirectories(serverDirectories).setStartupOptionsProvider(OptionsParser.newOptionsParser(BlazeServerStartupOptions.class)).addBlazeModule(new BlazeModule() {
@Override
public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
// Can't create a Skylark environment without a tools repository!
builder.setToolsRepository(TestConstants.TOOLS_REPOSITORY);
// Can't create a runtime without a configuration collection factory!
builder.setConfigurationCollectionFactory(Mockito.mock(ConfigurationCollectionFactory.class));
// Can't create a defaults package without the base options in there!
builder.addConfigurationOptions(BuildConfiguration.Options.class);
}
}).build();
snooze = new WaitForCompletionCommand(isTestShuttingDown);
dispatcher = new BlazeCommandDispatcher(runtime, snooze);
BlazeDirectories blazeDirectories = new BlazeDirectories(serverDirectories, scratch.dir("workspace"), productName);
runtime.initWorkspace(blazeDirectories, /*bintools=*/
null);
}
use of com.google.devtools.build.lib.analysis.ServerDirectories 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;
}
use of com.google.devtools.build.lib.analysis.ServerDirectories in project bazel by bazelbuild.
the class BlazeCommandDispatcherRcoptionsTest method initializeRuntime.
@Before
public final void initializeRuntime() throws Exception {
String productName = TestConstants.PRODUCT_NAME;
ServerDirectories serverDirectories = new ServerDirectories(scratch.dir("install_base"), scratch.dir("output_base"));
this.runtime = new BlazeRuntime.Builder().setProductName(productName).setServerDirectories(serverDirectories).setStartupOptionsProvider(OptionsParser.newOptionsParser(BlazeServerStartupOptions.class)).addBlazeModule(new BlazeModule() {
@Override
public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
// We must add these options so that the defaults package can be created.
builder.addConfigurationOptions(BuildConfiguration.Options.class);
// The defaults package asserts that it is not empty, so we provide options.
builder.addConfigurationOptions(MockFragmentOptions.class);
// The tools repository is needed for createGlobals
builder.setToolsRepository(TestConstants.TOOLS_REPOSITORY);
builder.setConfigurationCollectionFactory(Mockito.mock(ConfigurationCollectionFactory.class));
}
}).build();
BlazeDirectories directories = new BlazeDirectories(serverDirectories, scratch.dir("pkg"), productName);
this.runtime.initWorkspace(directories, /*binTools=*/
null);
}
Aggregations