Add optional dir_name argument to gerrit_plugin

This allows the plugin to live in a directory name that doesn't exactly
match the plugin name. Without this change, building such a plugin will
fail since the STABLE_BUILD_*_LABEL var won't be found in the stamp info
file.

Same as https://gerrit-review.googlesource.com/c/bazlets/+/183670 but
for in-tree plugin builds.

Change-Id: I393a4e9b418ee3c91ca41794aeee22cfd718d494
(cherry picked from commit e7bf2e23aa9b8d0786a75b550dce21f427ea4073)
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl
index 33f2e6a..8401a6b 100644
--- a/tools/bzl/plugin.bzl
+++ b/tools/bzl/plugin.bzl
@@ -27,6 +27,7 @@
     gwt_module = [],
     resources = [],
     manifest_entries = [],
+    dir_name = None,
     target_suffix = "",
     **kwargs):
   native.java_library(
@@ -42,6 +43,9 @@
   if gwt_module:
     static_jars = [':%s-static' % name]
 
+  if not dir_name:
+    dir_name = name
+
   native.java_binary(
     name = '%s__non_stamped' % name,
     deploy_manifest_lines = manifest_entries + ["Gerrit-ApiType: plugin"],
@@ -87,7 +91,7 @@
     stamp = 1,
     srcs = ['%s__non_stamped_deploy.jar' % name],
     cmd = " && ".join([
-      "GEN_VERSION=$$(cat bazel-out/stable-status.txt | grep -w STABLE_BUILD_%s_LABEL | cut -d ' ' -f 2)" % name.upper(),
+      "GEN_VERSION=$$(cat bazel-out/stable-status.txt | grep -w STABLE_BUILD_%s_LABEL | cut -d ' ' -f 2)" % dir_name.upper(),
       "cd $$TMP",
       "unzip -q $$ROOT/$<",
       "echo \"Implementation-Version: $$GEN_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF",