// 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.analysis; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.AbstractAction; import com.google.devtools.build.lib.actions.ActionOwner; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactFactory; import com.google.devtools.build.lib.actions.ArtifactOwner; import com.google.devtools.build.lib.actions.Executor.ActionContext; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionsBase; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; /** * An action writing the workspace status files. * *
These files represent information about the environment the build was run in. They are used * by language-specific build info factories to make the data in them available for individual * languages (e.g. by turning them into .h files for C++) * *
The format of these files a list of key-value pairs, one for each line. The key and the value * are separated by a space. * *
There are two of these files: volatile and stable. Changes in the volatile file do not
* cause rebuilds if no other file is changed. This is useful for frequently-changing information
* that does not significantly affect the build, e.g. the current time.
*/
public abstract class WorkspaceStatusAction extends AbstractAction {
/**
* Options controlling the workspace status command.
*/
public static class Options extends OptionsBase {
@Option(name = "embed_label",
defaultValue = "",
category = "misc",
help = "Embed source control revision or release label in binary")
public String embedLabel;
}
/**
* The type of a workspace status action key.
*/
public enum KeyType {
INTEGER,
STRING,
VERBATIM,
}
/**
* Language for keys that should be present in the build info for every language.
*/
// TODO(bazel-team): Once this is released, migrate the only place in the depot to use
// the BUILD_USERNAME, BUILD_HOSTNAME and BUILD_DIRECTORY keys instead of BUILD_INFO. Then
// language-specific build info keys can be removed.
public static final String ALL_LANGUAGES = "*";
/**
* Action context required by the actions that write language-specific workspace status artifacts.
*/
public static interface Context extends ActionContext {
ImmutableMap The output is a text file with each line representing a workspace status info key.
* The key is the part of the line before the first space and should consist of the characters
* [A-Z_] (although this is not checked). Everything after the first space is the value.
*/
public static Map If the objects returned for two builds are equals, the workspace status action can be
* be reused between them. Note that this only applies to the action object itself (the action
* will be unconditionally re-executed on every build)
*/
WorkspaceStatusAction createWorkspaceStatusAction(
ArtifactFactory artifactFactory, ArtifactOwner artifactOwner, Supplier