[bazel] Change symlink prefix for Bazel.

The bazel-* directories created by Bazel cause gopls to produce
invalid warning messages, run very slowly, and occasionally
crash.

If we prefix the directories with an underscore then they get
ignored by Go tools. We are forced to do this until
https://github.com/golang/go/issues/42965 is fixed.

See https://github.com/golang/go/issues/41511 as just one of many
issues this has caused.

Change-Id: Ifc0d6b7722f6a74728e86cda3697508c3d0f6fef
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/417417
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
diff --git a/.bazelrc b/.bazelrc
index 1dcebfd..83deeea 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -12,6 +12,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# If we prefix the directories with an underscore then they get ignored by Go tools.
+# We are forced to do this until https://github.com/golang/go/issues/42965 is fixed.
+build --symlink_prefix=_bazel_
+test  --symlink_prefix=_bazel_
+
+# Also suppress the generation of the bazel-out symlink, which always appears,no
+# matter what you set --symlink_prefix to.
+build --experimental_no_product_name_out_symlink
+
 build --workspace_status_command=bazel/get_workspace_status.sh
 
 # Tags such as no-remote and no-cache have no effect without this. See
diff --git a/.gitignore b/.gitignore
index 6b1d47b..3b69a08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -111,6 +111,7 @@
 # gitignore template for Bazel build system
 # website: https://bazel.build/
 
-# Ignore all bazel-* symlinks. There is no full list since this can change
-# based on the name of the directory bazel is cloned into.
-/bazel-*
+# Ignore all _bazel_* symlinks. There is no full list since this can change
+# based on the name of the directory bazel is cloned into. Note that the prefix
+# is set in .bazelrc.
+_bazel_*
diff --git a/infra-sk/index.bzl b/infra-sk/index.bzl
index 37f954b..01a015d 100644
--- a/infra-sk/index.bzl
+++ b/infra-sk/index.bzl
@@ -217,10 +217,10 @@
     $TEST_UNDECLARED_OUTPUTS_DIR/puppeteer-test-screenshots subdirectory. This convention will
     allow us to recover screenshots from multiple tests in a consistent way.
 
-    Screenshots, and any other undeclared outputs of a test, can be found under //bazel-testlogs
+    Screenshots, and any other undeclared outputs of a test, can be found under //_bazel-testlogs
     bundled as a single .zip file per test target. For example, if we run a Puppeteer test with e.g.
     "bazel test //path/to/my:puppeteer_test", any screenshots taken by this test will be found
-    inside //bazel-testlogs/path/to/my/puppeteer_test/test.outputs/outputs.zip.
+    inside //_bazel-testlogs/path/to/my/puppeteer_test/test.outputs/outputs.zip.
 
     To read more about undeclared test outputs, please see the following link:
     https://docs.bazel.build/versions/master/test-encyclopedia.html#test-interaction-with-the-filesystem.
diff --git a/puppeteer-tests/bazel/extract_puppeteer_screenshots/extract_puppeteer_screenshots.go b/puppeteer-tests/bazel/extract_puppeteer_screenshots/extract_puppeteer_screenshots.go
index d994fcb..fff5bbd 100644
--- a/puppeteer-tests/bazel/extract_puppeteer_screenshots/extract_puppeteer_screenshots.go
+++ b/puppeteer-tests/bazel/extract_puppeteer_screenshots/extract_puppeteer_screenshots.go
@@ -6,10 +6,10 @@
 //
 // Under Bazel, Puppeteer tests save screenshots inside $TEST_UNDECLARED_OUTPUTS_DIR, which is set
 // by the "bazel test" command. Screenshots, and any other undeclared outputs of a test, can be
-// found under //bazel-testlogs bundled as a single .zip file per test target.
+// found under //_bazel_testlogs bundled as a single .zip file per test target.
 //
 // For example, if we run a Puppeteer test with "bazel test //my_app:puppeteer_test", then any
-// screenshots will be found inside //bazel-testlogs/my_app/puppeteer_test/test.outputs/outputs.zip.
+// screenshots will be found inside //_bazel_testlogs/my_app/puppeteer_test/test.outputs/outputs.zip.
 //
 // See https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions to learn
 // more about undeclared test outputs.
@@ -66,13 +66,13 @@
 		}
 	}
 
-	// Resolve the //bazel-testlogs symlink. Necessary because filepath.Walk() ignores symlinks.
-	bazelTestlogsDir, err := filepath.EvalSymlinks("bazel-testlogs")
+	// Resolve the //_bazel_testlogs symlink. Necessary because filepath.Walk() ignores symlinks.
+	bazelTestlogsDir, err := filepath.EvalSymlinks("_bazel_testlogs")
 	if err != nil {
 		sklog.Fatal(err)
 	}
 
-	// Find all outputs.zip files under //bazel-testlogs, which contain the undeclared outputs
+	// Find all outputs.zip files under //_bazel_testlogs, which contain the undeclared outputs
 	// produced by all tests.
 	var allOutputsZipPaths []string
 	if err := filepath.Walk(bazelTestlogsDir, func(path string, info os.FileInfo, err error) error {
@@ -118,7 +118,7 @@
 //
 // An alternative approach is to find all Puppeteer tests via a Bazel query (e.g.
 // "bazel query 'attr(generator_function, sk_element_puppeteer_test, //...)'"), but this can be
-// slow. Inspecting all outputs.zip files inside the //bazel-testlogs directory is much faster.
+// slow. Inspecting all outputs.zip files inside the //_bazel_testlogs directory is much faster.
 func extractPuppeteerScreenshotsFromOutputsZip(zipFilePath string) error {
 	// Open the ZIP archive.
 	zipFile, err := zip.OpenReader(zipFilePath)
diff --git a/puppeteer-tests/util.ts b/puppeteer-tests/util.ts
index 2c83cd6..ca14dac 100644
--- a/puppeteer-tests/util.ts
+++ b/puppeteer-tests/util.ts
@@ -24,7 +24,7 @@
  *
  * Note: this works for standard DOM events as well, not just custom events.
  */
-export type EventPromiseFactory = <T>(eventName: EventName) => Promise<T>;
+export type EventPromiseFactory = <T>(eventName: EventName)=> Promise<T>;
 
 /**
  * This function allows tests to catch document-level events in a Puppeteer
@@ -120,7 +120,7 @@
 export interface TestBed {
   page: puppeteer.Page;
   baseUrl: string;
-};
+}
 
 /**
  * Starts a web server that serves custom element demo pages. Equivalent to
@@ -174,7 +174,7 @@
  */
 export const outputDir = () => {
   // When running via "bazel test", screenshots for e.g. //path/to/my:puppeteer_test will be found
-  // at //bazel-testlogs/path/to/my/puppeteer_test/test.outputs/outputs.zip. This is true when
+  // at //_bazel_testlogs/path/to/my/puppeteer_test/test.outputs/outputs.zip. This is true when
   // running on RBE as well (e.g. "bazel test --config=remote").
   //
   // See the following link for more:
@@ -209,10 +209,7 @@
  * application name as a prefix prevents name collisions between different apps
  * and increases consistency among test names.
  */
-export const takeScreenshot =
-    (handle: puppeteer.Page | puppeteer.ElementHandle, appName: string, testName: string) =>
-  handle.screenshot({path: path.join(exports.outputDir(), `${appName}_${testName}.png`)});
-
+export const takeScreenshot = (handle: puppeteer.Page | puppeteer.ElementHandle, appName: string, testName: string) => handle.screenshot({ path: path.join(exports.outputDir(), `${appName}_${testName}.png`) });
 
 let browser: puppeteer.Browser;
 let testBed: Partial<TestBed>;
@@ -241,7 +238,7 @@
     const envDir = process.env.ENV_DIR;
     if (!envDir) throw new Error('required environment variable ENV_DIR is unset');
     const port = parseInt(fs.readFileSync(path.join(envDir, ENV_PORT_FILE_BASE_NAME), 'utf8'));
-    newTestBed.baseUrl = `http://localhost:${port}`
+    newTestBed.baseUrl = `http://localhost:${port}`;
   } else {
     // Not in Bazel - Start the Webpack-based demo page server.
     let baseUrl;
@@ -268,7 +265,7 @@
     await testBed.page.setCookie({
       url: testBed.baseUrl,
       name: 'puppeteer',
-      value: 'true'
+      value: 'true',
     });
   });
 
@@ -283,4 +280,4 @@
       await browser.close();
     });
   }
-}
\ No newline at end of file
+}