Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Apr 14, 2021
1 parent 8216e7d commit 1c6fdb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void clearAdditionalInputs() {
public boolean discoversInputs() {
return shouldScanIncludes
|| getDotdFile() != null
|| featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES);
|| shouldParseShowIncludes();
}

@Override
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public ActionContinuationOrResult beginExecution(ActionExecutionContext actionEx
ActionExecutionContext spawnContext;
ShowIncludesFilter showIncludesFilterForStdout;
ShowIncludesFilter showIncludesFilterForStderr;
if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
if (shouldParseShowIncludes()) {
showIncludesFilterForStdout = new ShowIncludesFilter(getSourceFile().getFilename());
showIncludesFilterForStderr = new ShowIncludesFilter(getSourceFile().getFilename());
FileOutErr originalOutErr = actionExecutionContext.getFileOutErr();
Expand Down Expand Up @@ -1445,6 +1445,10 @@ protected byte[] getDotDContents(SpawnResult spawnResult) throws EnvironmentalEx
return null;
}

protected boolean shouldParseShowIncludes() {
return featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES);
}

protected Spawn createSpawn(Map<String, String> clientEnv) throws ActionExecutionException {
// Intentionally not adding {@link CppCompileAction#inputsForInvalidation}, those are not needed
// for execution.
Expand All @@ -1458,7 +1462,8 @@ protected Spawn createSpawn(Map<String, String> clientEnv) throws ActionExecutio
}
NestedSet<ActionInput> inputs = inputsBuilder.build();

ImmutableMap<String, String> executionInfo = getExecutionInfo();
ImmutableMap.Builder<String, String> executionInfo = ImmutableMap.<String, String>builder()
.putAll(getExecutionInfo());
if (getDotdFile() != null && useInMemoryDotdFiles()) {
/*
* CppCompileAction does dotd file scanning locally inside the Bazel process and thus
Expand All @@ -1468,34 +1473,25 @@ protected Spawn createSpawn(Map<String, String> clientEnv) throws ActionExecutio
* in-memory. We can do that via
* {@link ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS}.
*/
executionInfo =
ImmutableMap.<String, String>builderWithExpectedSize(executionInfo.size() + 1)
.putAll(executionInfo)
.put(
ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS,
getDotdFile().getExecPathString())
.build();
executionInfo.put(ExecutionRequirements.REMOTE_EXECUTION_INLINE_OUTPUTS,
getDotdFile().getExecPathString());
}

if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
if (shouldParseShowIncludes()) {
// Hack on Windows. The included headers dumped by cl.exe in stdout contain absolute paths.
// When compiling the file from different workspace, the shared cache will cause header
// dependency checking to fail. This was initially fixed by a hack (see
// https://github.com/bazelbuild/bazel/issues/9172 for more details), but is broken again due
// to cl/356735700. We require execution service to ignore caches from other workspace.
executionInfo =
ImmutableMap.<String, String>builderWithExpectedSize(executionInfo.size() + 1)
.putAll(executionInfo)
.put(ExecutionRequirements.DIFFERENTIATE_WORKSPACE_CACHE, "")
.build();
executionInfo.put(ExecutionRequirements.DIFFERENTIATE_WORKSPACE_CACHE, "");
}

try {
return new SimpleSpawn(
this,
ImmutableList.copyOf(getArguments()),
getEnvironment(clientEnv),
executionInfo,
executionInfo.build(),
inputs,
getOutputs(),
estimateResourceConsumptionLocal());
Expand Down Expand Up @@ -1848,7 +1844,7 @@ public ActionContinuationOrResult execute()
.getOptions(BuildLanguageOptions.class)
.experimentalSiblingRepositoryLayout;

if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
if (shouldParseShowIncludes()) {
NestedSet<Artifact> discoveredInputs =
discoverInputsFromShowIncludesFilters(
execRoot,
Expand Down Expand Up @@ -1888,7 +1884,7 @@ public ActionContinuationOrResult execute()
private void copyTempOutErrToActionOutErr() throws ActionExecutionException {
// If parse_showincludes feature is enabled, instead of parsing dotD file we parse the
// output of cl.exe caused by /showIncludes option.
if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
if (shouldParseShowIncludes()) {
try {
FileOutErr tempOutErr = spawnExecutionContext.getFileOutErr();
FileOutErr outErr = actionExecutionContext.getFileOutErr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void testInMemoryDotdFileAndExecutionRequirement() throws Exception {
when(action.getDotdFile()).thenReturn(dotdFile);
when(action.useInMemoryDotdFiles()).thenReturn(true);
when(action.estimateResourceConsumptionLocal()).thenReturn(AbstractAction.DEFAULT_RESOURCE_SET);
when(action.shouldParseShowIncludes()).thenReturn(false);
when(action.createSpawn(any())).thenCallRealMethod();

// act
Expand Down

0 comments on commit 1c6fdb8

Please sign in to comment.