1313// limitations under the License.
1414package com .google .devtools .build .lib .exec ;
1515
16+ import com .google .common .collect .ImmutableMap ;
1617import com .google .common .collect .Iterables ;
1718import com .google .devtools .build .lib .actions .ActionExecutionContext ;
1819import com .google .devtools .build .lib .actions .ActionExecutionContext .ShowSubcommands ;
20+ import com .google .devtools .build .lib .actions .LocalHostCapacity ;
21+ import com .google .devtools .build .lib .actions .ResourceSet ;
1922import com .google .devtools .build .lib .analysis .config .PerLabelOptions ;
20- import com .google .devtools .build .lib .util .CpuResourceConverter ;
2123import com .google .devtools .build .lib .util .OptionsUtils ;
22- import com .google .devtools .build .lib .util .RamResourceConverter ;
2324import com .google .devtools .build .lib .util .RegexFilter ;
2425import com .google .devtools .build .lib .util .ResourceConverter ;
2526import com .google .devtools .build .lib .vfs .PathFragment ;
@@ -288,70 +289,6 @@ public boolean shouldMaterializeParamFiles() {
288289 + " summary." )
289290 public TestSummaryFormat testSummary ;
290291
291- @ Option (
292- name = "local_cpu_resources" ,
293- defaultValue = ResourceConverter .HOST_CPUS_KEYWORD ,
294- deprecationWarning =
295- "--local_cpu_resources is deprecated, please use --local_resources=cpu= instead." ,
296- documentationCategory = OptionDocumentationCategory .BUILD_TIME_OPTIMIZATION ,
297- effectTags = {OptionEffectTag .HOST_MACHINE_RESOURCE_OPTIMIZATIONS },
298- help =
299- "Explicitly set the total number of local CPU cores available to Bazel to spend on build"
300- + " actions executed locally. Takes an integer, or \" "
301- + ResourceConverter .HOST_CPUS_KEYWORD
302- + "\" , optionally followed"
303- + " by [-|*]<float> (eg. "
304- + ResourceConverter .HOST_CPUS_KEYWORD
305- + "*.5"
306- + " to use half the available CPU cores). By default, (\" "
307- + ResourceConverter .HOST_CPUS_KEYWORD
308- + "\" ), Bazel will query system"
309- + " configuration to estimate the number of CPU cores available." ,
310- converter = CpuResourceConverter .class )
311- public double localCpuResources ;
312-
313- @ Option (
314- name = "local_ram_resources" ,
315- defaultValue = ResourceConverter .HOST_RAM_KEYWORD + "*.67" ,
316- deprecationWarning =
317- "--local_ram_resources is deprecated, please use --local_resources=memory= instead." ,
318- documentationCategory = OptionDocumentationCategory .BUILD_TIME_OPTIMIZATION ,
319- effectTags = {OptionEffectTag .HOST_MACHINE_RESOURCE_OPTIMIZATIONS },
320- help =
321- "Explicitly set the total amount of local host RAM (in MB) available to Bazel to spend on"
322- + " build actions executed locally. Takes an integer, or \" "
323- + ResourceConverter .HOST_RAM_KEYWORD
324- + "\" , optionally followed by [-|*]<float>"
325- + " (eg. "
326- + ResourceConverter .HOST_RAM_KEYWORD
327- + "*.5 to use half the available"
328- + " RAM). By default, (\" "
329- + ResourceConverter .HOST_RAM_KEYWORD
330- + "*.67\" ),"
331- + " Bazel will query system configuration to estimate the amount of RAM available"
332- + " and will use 67% of it." ,
333- converter = RamResourceConverter .class )
334- public double localRamResources ;
335-
336- @ Option (
337- name = "local_extra_resources" ,
338- defaultValue = "null" ,
339- deprecationWarning =
340- "--local_extra_resources is deprecated, please use --local_resources instead." ,
341- documentationCategory = OptionDocumentationCategory .BUILD_TIME_OPTIMIZATION ,
342- effectTags = {OptionEffectTag .HOST_MACHINE_RESOURCE_OPTIMIZATIONS },
343- allowMultiple = true ,
344- help =
345- "Set the number of extra resources available to Bazel. "
346- + "Takes in a string-float pair. Can be used multiple times to specify multiple "
347- + "types of extra resources. Bazel will limit concurrently running actions "
348- + "based on the available extra resources and the extra resources required. "
349- + "Tests can declare the amount of extra resources they need "
350- + "by using a tag of the \" resources:<resoucename>:<amount>\" format. "
351- + "Available CPU, RAM and resources cannot be set with this flag." ,
352- converter = Converters .StringToDoubleAssignmentConverter .class )
353- public List <Map .Entry <String , Double >> localExtraResources ;
354-
355292 @ Option (
356293 name = "local_resources" ,
357294 defaultValue = "null" ,
@@ -372,11 +309,19 @@ public boolean shouldMaterializeParamFiles() {
372309 + "types of resources. Bazel will limit concurrently running actions "
373310 + "based on the available resources and the resources required. "
374311 + "Tests can declare the amount of resources they need "
375- + "by using a tag of the \" resources:<resource name>:<amount>\" format. "
376- + "Overrides resources specified by --local_{cpu|ram|extra}_resources." ,
312+ + "by using a tag of the \" resources:<resource name>:<amount>\" format. " ,
377313 converter = ResourceConverter .AssignmentConverter .class )
378314 public List <Map .Entry <String , Double >> localResources ;
379315
316+ public ImmutableMap <String , Double > getLocalResources () {
317+ ImmutableMap .Builder <String , Double > resources = ImmutableMap .builder ();
318+ return resources
319+ .put (ResourceSet .CPU , LocalHostCapacity .getLocalHostCapacity ().getCpuUsage ())
320+ .put (ResourceSet .MEMORY , .67 * LocalHostCapacity .getLocalHostCapacity ().getMemoryMb ())
321+ .putAll (localResources )
322+ .buildKeepingLast ();
323+ }
324+
380325 @ Option (
381326 name = "experimental_cpu_load_scheduling" ,
382327 defaultValue = "false" ,
0 commit comments