// Copyright 2016 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.runtime; import static com.google.devtools.build.lib.profiler.AutoProfiler.profiledAndLogged; import static java.nio.charset.StandardCharsets.ISO_8859_1; import com.google.common.collect.Range; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.SubscriberExceptionHandler; import com.google.devtools.build.lib.actions.cache.ActionCache; import com.google.devtools.build.lib.actions.cache.CompactPersistentActionCache; import com.google.devtools.build.lib.actions.cache.NullActionCache; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction; import com.google.devtools.build.lib.analysis.config.BinTools; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.util.LoggingUtil; import com.google.devtools.build.lib.util.OS; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; /** * This class represents a workspace, and contains operations and data related to it. In contrast, * the BlazeRuntime class represents the Blaze server, and contains operations and data that are * (supposed to be) independent of the workspace or the current command. * *
At this time, there is still a 1:1 relationship between the BlazeRuntime and the
* BlazeWorkspace, but the introduction of this class is a step towards allowing 1:N relationships.
*/
public final class BlazeWorkspace {
public static final String DO_NOT_BUILD_FILE_NAME = "DO_NOT_BUILD_HERE";
private static final Logger LOG = Logger.getLogger(BlazeRuntime.class.getName());
private final BlazeRuntime runtime;
private final SubscriberExceptionHandler eventBusExceptionHandler;
private final WorkspaceStatusAction.Factory workspaceStatusActionFactory;
private final BinTools binTools;
private final BlazeDirectories directories;
private final SkyframeExecutor skyframeExecutor;
/** The action cache is loaded lazily on the first build command. */
private ActionCache actionCache;
/** The execution time range of the previous build command in this server, if any. */
@Nullable
private Range This is often the first entry on the {@code --package_path}, but not always.
* Callers should certainly not make this assumption. The Path returned may be null.
*/
public Path getWorkspace() {
return directories.getWorkspace();
}
/**
* Returns the output base directory associated with this Blaze server
* process. This is the base directory for shared Blaze state as well as tool
* and strategy specific subdirectories.
*/
public Path getOutputBase() {
return directories.getOutputBase();
}
/**
* Returns the cached value of
* {@code getOutputBase().getFilesystem().getFileSystemType(getOutputBase())}, which is assumed
* to be constant for a fixed workspace for the life of the Blaze server.
*/
public String getOutputBaseFilesystemTypeName() {
return outputBaseFilesystemTypeName;
}
/**
* Returns the output path associated with this Blaze server process..
*/
public Path getOutputPath() {
return directories.getOutputPath();
}
public Path getInstallBase() {
return directories.getInstallBase();
}
/**
* Returns the execution root directory associated with this Blaze server
* process. This is where all input and output files visible to the actual
* build reside.
*/
public Path getExecRoot() {
return directories.getExecRoot();
}
/**
* Returns path to the cache directory. Path must be inside output base to
* ensure that users can run concurrent instances of blaze in different
* clients without attempting to concurrently write to the same action cache
* on disk, which might not be safe.
*/
Path getCacheDirectory() {
return getOutputBase().getChild("action_cache");
}
void recordLastExecutionTime(long commandStartTime) {
long currentTimeMillis = runtime.getClock().currentTimeMillis();
lastExecutionRange = currentTimeMillis >= commandStartTime
? Range.closed(commandStartTime, currentTimeMillis)
: null;
}
/**
* Range that represents the last execution time of a build in millis since epoch.
*/
@Nullable
public Range