Bazel: Stamp git version for core plugins

Extend workspace status script to scan plugins directory and generate
git version for each of them in stable-status.txt file. This can be
used in plugin build rule to include this as plugin version info.

Given that there is no way to dynamically merge manifest file content
in Bazel[1] in java_binary rule, we have two options: either manipulate
the plugin artifact file by appending the generated plugin version in
post java_binary step in the META-INF/MANIFEST.MF file, or add VERSION
resource file in the plugin and route reading plugin version to this
file.

TEST PLAN:

  $ bazel build :gen_version
  $ cat bazel-out/stable-status.txt
  STABLE_BUILD_COMMIT-MESSAGE-LENGTH-VALIDATOR_LABEL v2.13.1-2-g76b9115
  STABLE_BUILD_COOKBOOK-PLUGIN_LABEL v2.13.2-12-g0162fc1
  STABLE_BUILD_DOWNLOAD-COMMANDS_LABEL v2.13.1-4-g6326db6
  STABLE_BUILD_GERRIT_LABEL v2.13.2-1329-g7c5917b-dirty
  [...]

[1] https://github.com/bazelbuild/bazel/issues/2009

Change-Id: Ie900617e918246ebb54080517161021f3030fdab
diff --git a/tools/workspace-status.sh b/tools/workspace-status.sh
index 506330c..6f17754 100755
--- a/tools/workspace-status.sh
+++ b/tools/workspace-status.sh
@@ -10,6 +10,12 @@
 # If the script exits with non-zero code, it's considered as a failure
 # and the output will be discarded.
 
-git_rev=$(git describe --always --match "v[0-9].*" --dirty)
+function rev() {
+  cd $1; git describe --always --match "v[0-9].*" --dirty
+}
 
-echo "STABLE_BUILD_GERRIT_LABEL ${git_rev}"
+echo STABLE_BUILD_GERRIT_LABEL $(rev .)
+for p in plugins/* ; do
+  test -d "$p" || continue
+  echo STABLE_BUILD_$(echo $(basename $p)_LABEL|tr [a-z] [A-Z]) $(rev $p)
+done