Add plugin allowlist refresh hints

Change-Id: I691718c25ecc4a71600506efb80b65c53b4847c2
diff --git a/gerrit_plugin.bzl b/gerrit_plugin.bzl
index eba7dce..747d6a5 100644
--- a/gerrit_plugin.bzl
+++ b/gerrit_plugin.bzl
@@ -409,10 +409,19 @@
     if not allowlist:
         allowlist = ":%s_third_party_runtime_jars.allowlist.txt" % plugin
 
+    allowlist_test = plugin + "_dependency_allowlist_test"
+    allowlist_manifest = allowlist_test + "_manifest"
+    package_name = native.package_name()
+    if package_name:
+        allowlist_hint = "//%s:%s" % (package_name, allowlist_manifest)
+    else:
+        allowlist_hint = ":%s" % allowlist_manifest
+
     runtime_jars_allowlist_test(
-        name = plugin + "_dependency_allowlist_test",
+        name = allowlist_test,
         target = plugin_target,
         allowlist = allowlist,
+        hint = allowlist_hint,
     )
 
     if not overlap_against:
diff --git a/tools/diff_allowlist.sh b/tools/diff_allowlist.sh
index ee1a58b..80017a6 100755
--- a/tools/diff_allowlist.sh
+++ b/tools/diff_allowlist.sh
@@ -5,6 +5,20 @@
 GENERATED="${2:?missing generated manifest file}"
 HINT="${3:-}"
 
+copy_source_from_hint() {
+  local hint="$1"
+
+  if [[ "${hint}" =~ ^//([^:]+):(.+)$ ]]; then
+    echo "bazel-bin/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}.txt"
+  elif [[ "${hint}" =~ ^([^:]+):(.+)$ ]]; then
+    echo "bazel-bin/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}.txt"
+  elif [[ "${hint}" =~ ^:(.+)$ ]]; then
+    echo "bazel-bin/${BASH_REMATCH[1]}.txt"
+  else
+    echo "bazel-bin/$(basename "${GENERATED}")"
+  fi
+}
+
 if [[ ! -f "${ALLOWLIST}" ]]; then
   echo "" >&2
   echo "FAIL: Missing allowlist:" >&2
@@ -13,7 +27,7 @@
   if [[ -n "${HINT}" ]]; then
     echo "To refresh it:" >&2
     echo "  bazelisk build ${HINT}" >&2
-    echo "  cp bazel-bin/$(basename "${GENERATED}") ${ALLOWLIST}" >&2
+    echo "  cp $(copy_source_from_hint "${HINT}") ${ALLOWLIST}" >&2
   else
     echo "To refresh it: build the corresponding manifest target and copy its output to the allowlist." >&2
   fi
@@ -34,7 +48,7 @@
   if [[ -n "${HINT}" ]]; then
     echo "If expected, refresh the allowlist with:" >&2
     echo "  bazelisk build ${HINT}" >&2
-    echo "  cp bazel-bin/$(basename "${GENERATED}") ${ALLOWLIST}" >&2
+    echo "  cp $(copy_source_from_hint "${HINT}") ${ALLOWLIST}" >&2
   else
     echo "If expected, refresh the allowlist by rebuilding the manifest and copying it over." >&2
   fi