From b25bb538170e7a471430d2b1e4e8fe7229e16dc1 Mon Sep 17 00:00:00 2001 From: Alex Torok Date: Mon, 14 Mar 2022 14:46:49 +0000 Subject: [PATCH] Use CommandLineItem.CapturingMapFn to reduce memory usage in BazelPythonSematics --- .../devtools/build/lib/bazel/rules/python/BUILD | 1 + .../bazel/rules/python/BazelPythonSemantics.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BUILD index dbcd04e8b0687b..26da7689d97889 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BUILD @@ -22,6 +22,7 @@ java_library( deps = [ "//src/main/java/com/google/devtools/build/lib/actions", "//src/main/java/com/google/devtools/build/lib/actions:artifacts", + "//src/main/java/com/google/devtools/build/lib/actions:commandline_item", "//src/main/java/com/google/devtools/build/lib/analysis:actions/custom_command_line", "//src/main/java/com/google/devtools/build/lib/analysis:actions/launcher_file_write_action", "//src/main/java/com/google/devtools/build/lib/analysis:actions/substitution", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index a76ba940ad72d9..ee674e99dd9ac9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -20,6 +20,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.CommandLineItem; import com.google.devtools.build.lib.actions.ParamFileInfo; import com.google.devtools.build.lib.actions.ParameterFile; import com.google.devtools.build.lib.analysis.AnalysisUtils; @@ -367,12 +368,18 @@ private static void createPythonZipAction( // Read each runfile from execute path, add them into zip file at the right runfiles path. // Filter the executable file, cause we are building it. + argv.addAll(CustomCommandLine.VectorArg.of(runfilesSupport.getRunfilesArtifacts()).mapped( + (CommandLineItem.CapturingMapFn) (artifact, args) -> { + if (!artifact.equals(executable) && !artifact.equals(zipFile)) { + args.accept( + getZipRunfilesPath(artifact.getRunfilesPath(), workspaceName, legacyExternalRunfiles) + + "=" + + artifact.getExecPathString()); + } + })); + for (Artifact artifact : runfilesSupport.getRunfilesArtifacts().toList()) { if (!artifact.equals(executable) && !artifact.equals(zipFile)) { - argv.addDynamicString( - getZipRunfilesPath(artifact.getRunfilesPath(), workspaceName, legacyExternalRunfiles) - + "=" - + artifact.getExecPathString()); inputsBuilder.add(artifact); } }