aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ming Zhao <mzhao@luminatewireless.com>2015-06-12 12:38:03 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-06-15 10:47:54 +0000
commit225030849d61c7cc6f7a09e93654f316cf33b1df (patch)
treead23683c07ee76e1f253698b17fcdc15e9c0e5b8
parent4833822ced449008ffc57d217334edac3122ef7e (diff)
Add username, hostname to stable build status.
Add timestamp to volatile build status. -- Change-Id: I940b2e8b924fcfba80406e0437913843fccde38f Reviewed-on: https://bazel-review.git.corp.google.com/#/c/1511/1 MOS_MIGRATED_REVID=95832082
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BuildInfo.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java33
2 files changed, 42 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildInfo.java
index 4177e56d93..65cdbf6f16 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildInfo.java
@@ -23,4 +23,19 @@ public class BuildInfo {
* Named constants for the BuildInfo keys.
*/
public static final String BUILD_EMBED_LABEL = "BUILD_EMBED_LABEL";
+
+ /**
+ * The name of the user that performs the build.
+ */
+ public static final String BUILD_USER = "BUILD_USER";
+
+ /**
+ * The host where the build happens
+ */
+ public static final String BUILD_HOST = "BUILD_HOST";
+
+ /**
+ * Build time as milliseconds since epoch
+ */
+ public static final String BUILD_TIMESTAMP = "BUILD_TIMESTAMP";
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
index 8b96e7719a..23b6b1e041 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java
@@ -13,6 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.bazel;
+import com.google.common.base.Joiner;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -37,6 +38,7 @@ import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.GotOptionsEvent;
+import com.google.devtools.build.lib.util.NetUtil;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.OptionsBase;
@@ -57,6 +59,10 @@ public class BazelWorkspaceStatusModule extends BlazeModule {
private final Artifact stableStatus;
private final Artifact volatileStatus;
private final AtomicReference<Options> options;
+
+ private final String username;
+ private final String hostname;
+ private final long timestamp;
private BazelWorkspaceStatusAction(
AtomicReference<WorkspaceStatusAction.Options> options,
@@ -67,6 +73,9 @@ public class BazelWorkspaceStatusModule extends BlazeModule {
this.options = options;
this.stableStatus = stableStatus;
this.volatileStatus = volatileStatus;
+ this.username = System.getProperty("user.name");
+ this.hostname = NetUtil.findShortHostName();
+ this.timestamp = System.currentTimeMillis();
}
@Override
@@ -78,10 +87,17 @@ public class BazelWorkspaceStatusModule extends BlazeModule {
public void execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException {
try {
- String embedLabelLine = String.format("BUILD_EMBED_LABEL %s\n", options.get().embedLabel);
+ Joiner joiner = Joiner.on('\n');
+ String info =
+ joiner.join(
+ BuildInfo.BUILD_EMBED_LABEL + " " + options.get().embedLabel,
+ BuildInfo.BUILD_HOST + " " + hostname,
+ BuildInfo.BUILD_USER + " " + username);
+ FileSystemUtils.writeContent(stableStatus.getPath(), info.getBytes(StandardCharsets.UTF_8));
+ String volatileInfo = BuildInfo.BUILD_TIMESTAMP + " " + timestamp + "\n";
+
FileSystemUtils.writeContent(
- stableStatus.getPath(), embedLabelLine.getBytes(StandardCharsets.UTF_8));
- FileSystemUtils.writeContent(volatileStatus.getPath(), new byte[] {});
+ volatileStatus.getPath(), volatileInfo.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new ActionExecutionException(e, this, true);
}
@@ -164,13 +180,18 @@ public class BazelWorkspaceStatusModule extends BlazeModule {
private class BazelWorkspaceStatusActionContext implements WorkspaceStatusAction.Context {
@Override
public ImmutableMap<String, Key> getStableKeys() {
- return ImmutableMap.of(BuildInfo.BUILD_EMBED_LABEL,
- Key.of(KeyType.STRING, options.get().embedLabel, "redacted"));
+ return ImmutableMap.of(
+ BuildInfo.BUILD_EMBED_LABEL,
+ Key.of(KeyType.STRING, options.get().embedLabel, "redacted"),
+ BuildInfo.BUILD_HOST,
+ Key.of(KeyType.STRING, "hostname", "redacted"),
+ BuildInfo.BUILD_USER,
+ Key.of(KeyType.STRING, "username", "redacted"));
}
@Override
public ImmutableMap<String, Key> getVolatileKeys() {
- return ImmutableMap.of();
+ return ImmutableMap.of(BuildInfo.BUILD_TIMESTAMP, Key.of(KeyType.INTEGER, "0", "0"));
}
}