Allow --local_test_jobs to take a keyword ('HOST_RAM', 'HOST_CPUS' 'auto'), or [keyword][-|*]<float>.

Allows users to tune flag relative to host resources or to our auto value.
This enables us to tune an auto value for this flag that reflects host
capacity, and allows users to select a value relative to their host capacity.
Currently, passing "auto" just returns the default value, 0, which does not cap
local test jobs.

RELNOTES: None.
PiperOrigin-RevId: 226506239
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index 34aeffb..e0d9c33 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -19,6 +19,7 @@
 import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
 import com.google.devtools.build.lib.util.OptionsUtils;
 import com.google.devtools.build.lib.util.RegexFilter;
+import com.google.devtools.build.lib.util.ResourceConverter;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.common.options.BoolOrEnumConverter;
 import com.google.devtools.common.options.Option;
@@ -250,15 +251,18 @@
   public boolean localMemoryEstimate;
 
   @Option(
-    name = "local_test_jobs",
-    defaultValue = "0",
-    documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
-    effectTags = {OptionEffectTag.UNKNOWN},
-    help =
-        "The max number of local test jobs to run concurrently. "
-            + "0 means local resources will limit the number of local test jobs to run "
-            + "concurrently instead. Setting this greater than the value for --jobs is ineffectual."
-  )
+      name = "local_test_jobs",
+      defaultValue = "auto",
+      documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+      effectTags = {OptionEffectTag.UNKNOWN},
+      help =
+          "The max number of local test jobs to run concurrently. "
+              + "Takes "
+              + ResourceConverter.FLAG_SYNTAX
+              + ". 0 means local resources will limit the number of local test jobs to run "
+              + "concurrently instead. Setting this greater than the value for --jobs "
+              + "is ineffectual.",
+      converter = LocalTestJobsConverter.class)
   public int localTestJobs;
 
   public boolean usingLocalTestJobs() {
@@ -387,6 +391,13 @@
     }
   }
 
+  /** Converter for --local_test_jobs, which takes {@value FLAG_SYNTAX} */
+  public static class LocalTestJobsConverter extends ResourceConverter {
+    public LocalTestJobsConverter() throws OptionsParsingException {
+      super(/* autoSupplier= */ () -> 0, /* minValue= */ 0, /* maxValue= */ Integer.MAX_VALUE);
+    }
+  }
+
   /** Converter for --subcommands */
   public static class ShowSubcommandsConverter extends BoolOrEnumConverter<ShowSubcommands> {
     public ShowSubcommandsConverter() {