Skip to content

Commit dc914c6

Browse files
Googlercopybara-github
authored andcommitted
Add experimental flag experimental_use_cpp_compile_action_args_params_file.
This flag enables writing the CPPCompileAction exposed `.args` to parameters file. The parameters file will be immutable and its properties cannot be updated from the aspect but this CL is a step to verify the solution for b/168634763 PiperOrigin-RevId: 355708794
1 parent 346d5fe commit dc914c6

4 files changed

Lines changed: 312 additions & 262 deletions

File tree

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.rules.cpp;
1515

16+
import static java.nio.charset.StandardCharsets.ISO_8859_1;
17+
1618
import com.google.common.annotations.VisibleForTesting;
1719
import com.google.common.base.Ascii;
1820
import com.google.common.base.Preconditions;
@@ -47,6 +49,7 @@
4749
import com.google.devtools.build.lib.actions.ExecException;
4850
import com.google.devtools.build.lib.actions.ExecutionRequirements;
4951
import com.google.devtools.build.lib.actions.LostInputsActionExecutionException;
52+
import com.google.devtools.build.lib.actions.ParamFileInfo;
5053
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
5154
import com.google.devtools.build.lib.actions.ResourceSet;
5255
import com.google.devtools.build.lib.actions.SimpleSpawn;
@@ -862,9 +865,16 @@ public Sequence<CommandLineArgsApi> getStarlarkArgs() throws EvalException {
862865
.collect(ImmutableSet.toImmutableSet());
863866

864867
CommandLine commandLine = compileCommandLine.getFilteredFeatureConfigurationCommandLine(this);
865-
868+
ParamFileInfo paramFileInfo = null;
869+
if (cppConfiguration.useArgsParamsFile()) {
870+
paramFileInfo =
871+
ParamFileInfo.builder(ParameterFileType.GCC_QUOTED)
872+
.setCharset(ISO_8859_1)
873+
.setUseAlways(true)
874+
.build();
875+
}
866876
CommandLineAndParamFileInfo commandLineAndParamFileInfo =
867-
new CommandLineAndParamFileInfo(commandLine, /* paramFileInfo= */ null);
877+
new CommandLineAndParamFileInfo(commandLine, paramFileInfo);
868878

869879
Args args = Args.forRegisteredAction(commandLineAndParamFileInfo, directoryInputs);
870880

@@ -1788,8 +1798,7 @@ public ActionContinuationOrResult execute()
17881798
dotDContents = getDotDContents(spawnResults.get(0));
17891799
} catch (ExecException e) {
17901800
copyTempOutErrToActionOutErr();
1791-
throw e.toActionExecutionException(
1792-
CppCompileAction.this);
1801+
throw e.toActionExecutionException(CppCompileAction.this);
17931802
} catch (InterruptedException e) {
17941803
copyTempOutErrToActionOutErr();
17951804
throw e;

‎src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java‎

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,17 @@ public static HeadersCheckingMode getValue(String value) {
120120
* --dynamic_mode parses to DynamicModeFlag, but AUTO will be translated based on platform,
121121
* resulting in a DynamicMode value.
122122
*/
123-
public enum DynamicMode { OFF, DEFAULT, FULLY }
123+
public enum DynamicMode {
124+
OFF,
125+
DEFAULT,
126+
FULLY
127+
}
124128

125-
/**
126-
* This enumeration is used for the --strip option.
127-
*/
129+
/** This enumeration is used for the --strip option. */
128130
public enum StripMode {
129-
130-
ALWAYS("always"), // Always strip.
131+
ALWAYS("always"), // Always strip.
131132
SOMETIMES("sometimes"), // Strip iff compilationMode == FASTBUILD.
132-
NEVER("never"); // Never strip.
133+
NEVER("never"); // Never strip.
133134

134135
private final String mode;
135136

@@ -304,7 +305,6 @@ public CompilationMode getCompilationMode() {
304305
return compilationMode;
305306
}
306307

307-
308308
public boolean hasSharedLinkOption() {
309309
return linkopts.contains("-shared");
310310
}
@@ -341,31 +341,31 @@ public boolean isCSFdo() {
341341
return cppOptions.isCSFdo();
342342
}
343343

344-
/**
345-
* Returns whether or not to strip the binaries.
346-
*/
344+
public boolean useArgsParamsFile() {
345+
return cppOptions.useArgsParamsFile;
346+
}
347+
348+
/** Returns whether or not to strip the binaries. */
347349
public boolean shouldStripBinaries() {
348350
return stripBinaries;
349351
}
350352

351353
/**
352-
* Returns the additional options to pass to strip when generating a
353-
* {@code <name>.stripped} binary by this build.
354+
* Returns the additional options to pass to strip when generating a {@code <name>.stripped}
355+
* binary by this build.
354356
*/
355357
public ImmutableList<String> getStripOpts() {
356358
return ImmutableList.copyOf(cppOptions.stripoptList);
357359
}
358360

359-
/**
360-
* Returns whether temporary outputs from gcc will be saved.
361-
*/
361+
/** Returns whether temporary outputs from gcc will be saved. */
362362
public boolean getSaveTemps() {
363363
return cppOptions.saveTemps;
364364
}
365365

366366
/**
367-
* Returns the {@link PerLabelOptions} to apply to the gcc command line, if
368-
* the label of the compiled file matches the regular expression.
367+
* Returns the {@link PerLabelOptions} to apply to the gcc command line, if the label of the
368+
* compiled file matches the regular expression.
369369
*/
370370
public ImmutableList<PerLabelOptions> getPerFileCopts() {
371371
return ImmutableList.copyOf(cppOptions.perFileCopts);
@@ -388,9 +388,7 @@ public Label customMalloc() {
388388
return cppOptions.customMalloc;
389389
}
390390

391-
/**
392-
* Returns whether we are processing headers in dependencies of built C++ targets.
393-
*/
391+
/** Returns whether we are processing headers in dependencies of built C++ targets. */
394392
public boolean processHeadersInDependencies() {
395393
return cppOptions.processHeadersInDependencies;
396394
}
@@ -536,9 +534,7 @@ public String getOutputDirectoryName() {
536534
return result;
537535
}
538536

539-
/**
540-
* Returns true if we should share identical native libraries between different targets.
541-
*/
537+
/** Returns true if we should share identical native libraries between different targets. */
542538
public boolean shareNativeDeps() {
543539
return cppOptions.shareNativeDeps;
544540
}
@@ -821,4 +817,3 @@ public boolean fissionActiveForCurrentCompilationModeStarlark(StarlarkThread thr
821817
return fissionIsActiveForCurrentCompilationMode();
822818
}
823819
}
824-

0 commit comments

Comments
 (0)