Make webassets packaging repo-path independent

Gitiles' webassets genrule copied resources by stripping one
path component from the source paths. That works when Gitiles is
the main repository, where resource paths start with resources/...,
but not when another Bzlmod build consumes Gitiles as a local
external repository.

In that case Bazel passes source paths below its external repository
tree, so stripping one component leaves the wrong layout and the rule
cannot cd into com/google/gitiles.

Copy each source under the path segment after
resources/com/google/gitiles/ instead. This preserves the existing
archive layout for standalone Gitiles and allows Gerrit to
source-build Gitiles from a modules/gitiles submodule while supplying
its own JGit and java-prettify repositories.

Change-Id: Iec8dbd92411d0fd5a5669035dadc6da231242fb8
diff --git a/resources/com/google/gitiles/BUILD b/resources/com/google/gitiles/BUILD
index c5df3e1..a75a935 100644
--- a/resources/com/google/gitiles/BUILD
+++ b/resources/com/google/gitiles/BUILD
@@ -18,7 +18,12 @@
     outs = ["webassets.zip"],
     cmd = " && ".join([
         "o=$$PWD/$@",
-        "tar cf - $(SRCS) | tar -C $$TMP/ --strip-components=1 -xf -",
+        "mkdir -p $$TMP/com/google/gitiles",
+        "for f in $(SRCS); do " +
+        "rel=$${f#*resources/com/google/gitiles/}; " +
+        "mkdir -p $$TMP/com/google/gitiles/$$(dirname $$rel); " +
+        "cp $$f $$TMP/com/google/gitiles/$$rel; " +
+        "done",
         "cd $$TMP/com/google/gitiles/",
         "mv static +static",
         "zip -qr $$o .",