Skip to content

Commit

Permalink
Add experimental flag `experimental_use_cpp_compile_action_args_param…
Browse files Browse the repository at this point in the history
…s_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
  • Loading branch information
Googler authored and Copybara-Service committed Feb 4, 2021
1 parent 346d5fe commit dc914c6
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 262 deletions.
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.cpp;

import static java.nio.charset.StandardCharsets.ISO_8859_1;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -47,6 +49,7 @@
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.ExecutionRequirements;
import com.google.devtools.build.lib.actions.LostInputsActionExecutionException;
import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.actions.SimpleSpawn;
Expand Down Expand Up @@ -862,9 +865,16 @@ public Sequence<CommandLineArgsApi> getStarlarkArgs() throws EvalException {
.collect(ImmutableSet.toImmutableSet());

CommandLine commandLine = compileCommandLine.getFilteredFeatureConfigurationCommandLine(this);

ParamFileInfo paramFileInfo = null;
if (cppConfiguration.useArgsParamsFile()) {
paramFileInfo =
ParamFileInfo.builder(ParameterFileType.GCC_QUOTED)
.setCharset(ISO_8859_1)
.setUseAlways(true)
.build();
}
CommandLineAndParamFileInfo commandLineAndParamFileInfo =
new CommandLineAndParamFileInfo(commandLine, /* paramFileInfo= */ null);
new CommandLineAndParamFileInfo(commandLine, paramFileInfo);

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

Expand Down Expand Up @@ -1788,8 +1798,7 @@ public ActionContinuationOrResult execute()
dotDContents = getDotDContents(spawnResults.get(0));
} catch (ExecException e) {
copyTempOutErrToActionOutErr();
throw e.toActionExecutionException(
CppCompileAction.this);
throw e.toActionExecutionException(CppCompileAction.this);
} catch (InterruptedException e) {
copyTempOutErrToActionOutErr();
throw e;
Expand Down
Expand Up @@ -120,16 +120,17 @@ public static HeadersCheckingMode getValue(String value) {
* --dynamic_mode parses to DynamicModeFlag, but AUTO will be translated based on platform,
* resulting in a DynamicMode value.
*/
public enum DynamicMode { OFF, DEFAULT, FULLY }
public enum DynamicMode {
OFF,
DEFAULT,
FULLY
}

/**
* This enumeration is used for the --strip option.
*/
/** This enumeration is used for the --strip option. */
public enum StripMode {

ALWAYS("always"), // Always strip.
ALWAYS("always"), // Always strip.
SOMETIMES("sometimes"), // Strip iff compilationMode == FASTBUILD.
NEVER("never"); // Never strip.
NEVER("never"); // Never strip.

private final String mode;

Expand Down Expand Up @@ -304,7 +305,6 @@ public CompilationMode getCompilationMode() {
return compilationMode;
}


public boolean hasSharedLinkOption() {
return linkopts.contains("-shared");
}
Expand Down Expand Up @@ -341,31 +341,31 @@ public boolean isCSFdo() {
return cppOptions.isCSFdo();
}

/**
* Returns whether or not to strip the binaries.
*/
public boolean useArgsParamsFile() {
return cppOptions.useArgsParamsFile;
}

/** Returns whether or not to strip the binaries. */
public boolean shouldStripBinaries() {
return stripBinaries;
}

/**
* Returns the additional options to pass to strip when generating a
* {@code <name>.stripped} binary by this build.
* Returns the additional options to pass to strip when generating a {@code <name>.stripped}
* binary by this build.
*/
public ImmutableList<String> getStripOpts() {
return ImmutableList.copyOf(cppOptions.stripoptList);
}

/**
* Returns whether temporary outputs from gcc will be saved.
*/
/** Returns whether temporary outputs from gcc will be saved. */
public boolean getSaveTemps() {
return cppOptions.saveTemps;
}

/**
* Returns the {@link PerLabelOptions} to apply to the gcc command line, if
* the label of the compiled file matches the regular expression.
* Returns the {@link PerLabelOptions} to apply to the gcc command line, if the label of the
* compiled file matches the regular expression.
*/
public ImmutableList<PerLabelOptions> getPerFileCopts() {
return ImmutableList.copyOf(cppOptions.perFileCopts);
Expand All @@ -388,9 +388,7 @@ public Label customMalloc() {
return cppOptions.customMalloc;
}

/**
* Returns whether we are processing headers in dependencies of built C++ targets.
*/
/** Returns whether we are processing headers in dependencies of built C++ targets. */
public boolean processHeadersInDependencies() {
return cppOptions.processHeadersInDependencies;
}
Expand Down Expand Up @@ -536,9 +534,7 @@ public String getOutputDirectoryName() {
return result;
}

/**
* Returns true if we should share identical native libraries between different targets.
*/
/** Returns true if we should share identical native libraries between different targets. */
public boolean shareNativeDeps() {
return cppOptions.shareNativeDeps;
}
Expand Down Expand Up @@ -821,4 +817,3 @@ public boolean fissionActiveForCurrentCompilationModeStarlark(StarlarkThread thr
return fissionIsActiveForCurrentCompilationMode();
}
}

0 comments on commit dc914c6

Please sign in to comment.