Simplify presubmit command

This adds a sh_binary helper that finds the folder where
bazel was invoked from and passes that in. Thus, the user
just needs to run

bazel run //cmd/presubmit

Change-Id: I66a9ed1986fcc297915effba2f1af5488602cbc8
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/575914
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d37b839..a56386c 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -6,13 +6,11 @@
 
 """Presubmit checks for the Skia infrastructure code."""
 
-import os
-
 USE_PYTHON3 = True
 
 def _RunPresubmitsWithBazelisk(input_api, output_api, extra_arg):
   """Run presubmit.go via bazelisk. Fail if it returns a non-zero exit code."""
-  command = ['bazelisk', 'run', '//cmd/presubmit', '--', '--repo_dir='+os.getcwd(), extra_arg]
+  command = ['bazelisk', 'run', '//cmd/presubmit', '--', extra_arg]
   command_str = ' '.join(command)
   results = []
 
diff --git a/cmd/presubmit/presubmit.go b/cmd/presubmit/presubmit.go
index 45ad90f..5e25924 100644
--- a/cmd/presubmit/presubmit.go
+++ b/cmd/presubmit/presubmit.go
@@ -5,7 +5,8 @@
 // If any presubmits fail, there will be errors logged to stdout and the exit code will be non-zero.
 //
 // This should be invoked from the root of the repo via Bazel like
-//   bazel run //cmd/presubmit -- --repo_dir=$PWD
+//   bazel run //cmd/presubmit
+// See presubmit.sh for a helper that pipes in the correct value for repo_dir.
 package main
 
 import (
@@ -25,7 +26,8 @@
 
 func main() {
 	var (
-		repoDir  = flag.String("repo_dir", "", "The root directory of the repo.")
+		// https://bazel.build/docs/user-manual#running-executables
+		repoDir  = flag.String("repo_dir", os.Getenv("BUILD_WORKSPACE_DIRECTORY"), "The root directory of the repo. Default set by BUILD_WORKSPACE_DIRECTORY env variable.")
 		upstream = flag.String("upstream", "origin/main", "The upstream repo to diff against.")
 		verbose  = flag.Bool("verbose", false, "If extra logging is desired")
 		upload   = flag.Bool("upload", false, "If true, this will skip any checks that are not suitable for an upload check (may be the empty set).")
diff --git a/infra/bots/task_drivers/presubmit/presubmit.go b/infra/bots/task_drivers/presubmit/presubmit.go
index 4162868..eda8f83 100644
--- a/infra/bots/task_drivers/presubmit/presubmit.go
+++ b/infra/bots/task_drivers/presubmit/presubmit.go
@@ -63,7 +63,7 @@
 		td.Fatal(ctx, err)
 	}
 
-	if err := bazelCmd(ctx, repoPath, "run", "//cmd/presubmit", "--", "--repo_dir="+repoPath); err != nil {
+	if err := bazelCmd(ctx, repoPath, "run", "//cmd/presubmit", "--", "--commit"); err != nil {
 		td.Fatal(ctx, err)
 	}
 }