Accept current workspace name as a flag

Stardoc will thus avoid looking for dependencies in the current workspace name within external/.
For example, if the current workspace is "io_bazel", then, when a file loads "@io_bazel//foo:bar.bzl", Stardoc will look to foo/bar.bzl instead of external/io_bazel/foo/bar.bzl

RELNOTES: None.
PiperOrigin-RevId: 239229374
diff --git a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
index 1c93b24..328babb 100644
--- a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
+++ b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
@@ -146,9 +146,11 @@
   private final Map<Path, Environment> loaded = new HashMap<>();
   private final SkylarkFileAccessor fileAccessor;
   private final List<String> depRoots;
+  private final String workspaceName;
 
-  public SkydocMain(SkylarkFileAccessor fileAccessor, List<String> depRoots) {
+  public SkydocMain(SkylarkFileAccessor fileAccessor, String workspaceName, List<String> depRoots) {
     this.fileAccessor = fileAccessor;
+    this.workspaceName = workspaceName;
     if (depRoots.isEmpty()) {
       // For backwards compatibility, if no dep_roots are specified, use the current
       // directory as the only root.
@@ -199,7 +201,7 @@
     ImmutableMap.Builder<String, ProviderInfo> providerInfoMap = ImmutableMap.builder();
     ImmutableMap.Builder<String, UserDefinedFunction> userDefinedFunctions = ImmutableMap.builder();
 
-    new SkydocMain(new FilesystemFileAccessor(), depRoots)
+    new SkydocMain(new FilesystemFileAccessor(), skydocOptions.workspaceName, depRoots)
         .eval(
             semanticsOptions.toSkylarkSemantics(),
             targetFileLabel,
@@ -431,9 +433,10 @@
   }
 
   private Path pathOfLabel(Label label) {
-    String workspacePrefix = label.getWorkspaceRoot().isEmpty()
-        ? ""
-        : label.getWorkspaceRoot() + "/";
+    String workspacePrefix = "";
+    if (!label.getWorkspaceRoot().isEmpty() && !label.getWorkspaceName().equals(workspaceName)) {
+      workspacePrefix = label.getWorkspaceRoot() + "/";
+    }
 
     return Paths.get(workspacePrefix + label.toPathFragment());
   }
diff --git a/src/main/java/com/google/devtools/build/skydoc/SkydocOptions.java b/src/main/java/com/google/devtools/build/skydoc/SkydocOptions.java
index 1a45913..d223e8c 100644
--- a/src/main/java/com/google/devtools/build/skydoc/SkydocOptions.java
+++ b/src/main/java/com/google/devtools/build/skydoc/SkydocOptions.java
@@ -32,6 +32,14 @@
   public String targetFileLabel;
 
   @Option(
+      name = "workspace_name",
+      defaultValue = "",
+      documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+      effectTags = OptionEffectTag.UNKNOWN,
+      help = "The name of the workspace in which the input file resides")
+  public String workspaceName;
+
+  @Option(
       name = "output",
       defaultValue = "",
       documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,