// Copyright 2014 Google Inc. 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 com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.ActionContextConsumer; import com.google.devtools.build.lib.actions.ActionContextProvider; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.exec.OutputService; import com.google.devtools.build.lib.packages.MakeEnvironment; import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.PackageFactory.PackageArgument; import com.google.devtools.build.lib.packages.Preprocessor; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; import com.google.devtools.build.lib.query2.output.OutputFormatter; import com.google.devtools.build.lib.rules.test.CoverageReportActionFactory; import com.google.devtools.build.lib.skyframe.DiffAwareness; import com.google.devtools.build.lib.skyframe.PrecomputedValue.Injected; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.skyframe.SkyframeExecutorFactory; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.Label; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.Clock; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.UUID; import javax.annotation.Nullable; /** * A module Blaze can load at the beginning of its execution. Modules are supplied with extension * points to augment the functionality at specific, well-defined places. * *
The constructors of individual Blaze modules should be empty. All work should be done in the * methods (e.g. {@link #blazeStartup}). */ public abstract class BlazeModule { /** * Returns the extra startup options this module contributes. * *
This method will be called at the beginning of Blaze startup (before #blazeStartup).
*/
public Iterable This method will be called at the beginning of Blaze startup.
*/
@SuppressWarnings("unused")
public void globalInit(OptionsProvider startupOptions) throws AbruptExitException {
}
/**
* Returns the file system implementation used by Blaze. It is an error if more than one module
* returns a file system. If all return null, the default unix file system is used.
*
* This method will be called at the beginning of Blaze startup (in-between #globalInit and
* #blazeStartup).
*/
@SuppressWarnings("unused")
public FileSystem getFileSystem(OptionsProvider startupOptions, PathFragment outputPath) {
return null;
}
/**
* Called when Blaze starts up.
*/
@SuppressWarnings("unused")
public void blazeStartup(OptionsProvider startupOptions,
BlazeVersionInfo versionInfo, UUID instanceId, BlazeDirectories directories,
Clock clock) throws AbruptExitException {
}
/**
* Returns the set of directories under which blaze may assume all files are immutable.
*/
public Set This method will be called during Blaze startup (after #blazeStartup).
*/
public Preprocessor.Factory.Supplier getPreprocessorFactorySupplier() {
return null;
}
/**
* Adds the rule classes supported by this module.
*
* This method will be called during Blaze startup (after #blazeStartup).
*/
@SuppressWarnings("unused")
public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
}
/**
* Returns the list of commands this module contributes to Blaze.
*
* This method will be called during Blaze startup (after #blazeStartup).
*/
public Iterable extends BlazeCommand> getCommands() {
return ImmutableList.of();
}
/**
* Returns the list of query output formatters this module provides.
*
* This method will be called during Blaze startup (after #blazeStartup).
*/
public Iterable This method will be called during Blaze startup (after #blazeStartup).
*/
@SuppressWarnings("unused")
public Iterable extends DiffAwareness.Factory> getDiffAwarenessFactories(boolean watchFS) {
return ImmutableList.of();
}
/**
* Returns the workspace status action factory contributed by this module.
*
* There should always be exactly one of these in a Blaze instance.
*/
public WorkspaceStatusAction.Factory getWorkspaceStatusActionFactory() {
return null;
}
/**
* PlatformSet is a group of platforms characterized by a regular expression. For example, the
* entry "oldlinux": "i[34]86-libc[345]-linux" might define a set of platforms representing
* certain older linux releases.
*
* Platform-set names are used in BUILD files in the third argument to vardef, to
* define per-platform tweaks to variables such as CFLAGS.
*
* vardef is a legacy mechanism: it needs explicit support in the rule implementations,
* and cannot express conditional dependencies, only conditional attribute values. This
* mechanism will be supplanted by configuration dependent attributes, and its effect can
* usually also be achieved with abi_deps.
*
* This method will be called during Blaze startup (after #blazeStartup).
*/
public Map This method will be called at the beginning of each command (after #beforeCommand).
*/
@SuppressWarnings("unused")
public OutputService getOutputService() throws AbruptExitException {
return null;
}
/**
* Returns the extra options this module contributes to a specific command.
*
* This method will be called at the beginning of each command (after #beforeCommand).
*/
@SuppressWarnings("unused")
public Iterable This is usually true for info keys that take multiple lines, thus, cannot really be
* included in the output of argumentless "blaze info".
*/
boolean isHidden();
/**
* Returns the value of the info key. The return value is directly printed to stdout.
*/
byte[] get(Supplier This method will be called at the beginning of each "blaze info" command (after
* #beforeCommand).
*/
public Iterable This method will be called at the beginning of each "blaze query" command (after
* #beforeCommand).
*/
public Iterable This method will be called at the beginning of the execution phase, e.g. of the
* "blaze build" command.
*/
public ActionContextProvider getActionContextProvider() {
return null;
}
/**
* Returns the action context consumer that pulls in action contexts required by this module,
* if any.
*
* This method will be called at the beginning of the execution phase, e.g. of the
* "blaze build" command.
*/
public ActionContextConsumer getActionContextConsumer() {
return null;
}
/**
* Called after each command.
*/
public void afterCommand() {
}
/**
* Called when Blaze shuts down.
*/
public void blazeShutdown() {
}
/**
* Action inputs are allowed to be missing for all inputs where this predicate returns true.
*/
public Predicate This method is called once per Blaze instance at the very beginning of its life.
* If it creates the injected values by using a {@code com.google.common.base.Supplier},
* that supplier is asked for the value it contains just before the loading phase begins. This
* functionality can be used to implement precomputed values that are not constant during the
* lifetime of a Blaze instance (naturally, they must be constant over the course of a build)
*
* The following things must be done in order to define a new precomputed values:
*
*
*/
public Iterable