Skip to content

Commit

Permalink
Split CppIncludeScanningContext out of CppCompileActionContext
Browse files Browse the repository at this point in the history
Rename IncludeScanningContext to CppIncludeExtractionContext, which more closely matches its semantics.

PiperOrigin-RevId: 184974810
  • Loading branch information
ulfjack authored and Copybara-Service committed Feb 8, 2018
1 parent 8a96fe9 commit b116240
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import com.google.devtools.build.lib.exec.SpawnCache;
import com.google.devtools.build.lib.rules.android.WriteAdbArgsActionContext;
import com.google.devtools.build.lib.rules.cpp.CppCompileActionContext;
import com.google.devtools.build.lib.rules.cpp.IncludeScanningContext;
import com.google.devtools.build.lib.rules.cpp.CppIncludeExtractionContext;
import com.google.devtools.build.lib.rules.cpp.CppIncludeScanningContext;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -73,7 +74,8 @@ public ImmutableMap<String, String> getSpawnActionContexts() {
public Multimap<Class<? extends ActionContext>, String> getActionContexts() {
return ImmutableMultimap.<Class<? extends ActionContext>, String>builder()
.put(CppCompileActionContext.class, "")
.put(IncludeScanningContext.class, "")
.put(CppIncludeExtractionContext.class, "")
.put(CppIncludeScanningContext.class, "")
.put(FileWriteActionContext.class, "")
.put(WriteAdbArgsActionContext.class, "")
.put(SpawnCache.class, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public Iterable<Artifact> discoverInputs(ActionExecutionContext actionExecutionC
try {
initialResult =
actionExecutionContext
.getContext(CppCompileActionContext.class)
.getContext(CppIncludeScanningContext.class)
.findAdditionalInputs(
this, actionExecutionContext, cppSemantics.getIncludeProcessing());
} catch (ExecException e) {
Expand Down Expand Up @@ -1120,8 +1120,8 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
ensureCoverageNotesFilesExist();

// This is the .d file scanning part.
IncludeScanningContext scanningContext =
actionExecutionContext.getContext(IncludeScanningContext.class);
CppIncludeExtractionContext scanningContext =
actionExecutionContext.getContext(CppIncludeExtractionContext.class);
Path execRoot = actionExecutionContext.getExecRoot();

NestedSet<Artifact> discoveredInputs;
Expand Down Expand Up @@ -1271,7 +1271,7 @@ public Iterable<Artifact> getInputFilesForExtraAction(
throws ActionExecutionException, InterruptedException {
Iterable<Artifact> scannedIncludes;
try {
scannedIncludes = actionExecutionContext.getContext(CppCompileActionContext.class)
scannedIncludes = actionExecutionContext.getContext(CppIncludeScanningContext.class)
.findAdditionalInputs(this, actionExecutionContext, cppSemantics.getIncludeProcessing());
} catch (ExecException e) {
throw e.toActionExecutionException(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
import com.google.devtools.build.lib.actions.ActionContext;
import com.google.devtools.build.lib.actions.ActionContextMarker;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ExecException;
import java.io.IOException;
import javax.annotation.Nullable;

/**
* Context for compiling plain C++.
Expand All @@ -37,18 +34,6 @@ public interface Reply {
byte[] getContents() throws IOException;
}

/**
* Does include scanning to find the list of files needed to execute the action.
*
* <p>Returns null if additional inputs will only be found during action execution, not before.
*/
@Nullable
Iterable<Artifact> findAdditionalInputs(
CppCompileAction action,
ActionExecutionContext actionExecutionContext,
IncludeProcessing includeProcessing)
throws ExecException, InterruptedException, ActionExecutionException;

/**
* Executes the given action and return the reply of the executor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Context for actions that do include scanning.
*/
public interface IncludeScanningContext extends ActionContext {
public interface CppIncludeExtractionContext extends ActionContext {
/**
* Extracts the set of include files from a source file.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.rules.cpp;

import com.google.devtools.build.lib.actions.ActionContext;
import com.google.devtools.build.lib.actions.ActionContextMarker;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ExecException;
import javax.annotation.Nullable;

/**
* Context for include scanning.
*/
@ActionContextMarker(name = "IncludeScanning")
public interface CppIncludeScanningContext extends ActionContext {
/**
* Does include scanning to find the list of files needed to execute the action.
*
* <p>Returns null if additional inputs will only be found during action execution, not before.
*/
@Nullable
Iterable<Artifact> findAdditionalInputs(
CppCompileAction action,
ActionExecutionContext actionExecutionContext,
IncludeProcessing includeProcessing)
throws ExecException, InterruptedException, ActionExecutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ protected String getRawProgressMessage() {
@Override
public ActionResult execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
IncludeScanningContext context =
actionExecutionContext.getContext(IncludeScanningContext.class);
CppIncludeExtractionContext context =
actionExecutionContext.getContext(CppIncludeExtractionContext.class);
try {
context.extractIncludes(actionExecutionContext, this, getPrimaryInput(),
getPrimaryOutput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
actionExecutionContext.getVerboseFailures(),
this);
}
IncludeScanningContext scanningContext =
actionExecutionContext.getContext(IncludeScanningContext.class);
CppIncludeExtractionContext scanningContext =
actionExecutionContext.getContext(CppIncludeExtractionContext.class);
Path execRoot = actionExecutionContext.getExecRoot();

NestedSet<Artifact> discoveredInputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@
name = {"spawn"}
)
public class SpawnGccStrategy implements CppCompileActionContext {
@Override
public Iterable<Artifact> findAdditionalInputs(
CppCompileAction action,
ActionExecutionContext actionExecutionContext,
IncludeProcessing includeProcessing)
throws ExecException, InterruptedException {
return null;
}

@Override
public CppCompileActionResult execWithReply(
CppCompileAction action, ActionExecutionContext actionExecutionContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.ActionContext;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactResolver;
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.ExecutionStrategy;
import com.google.devtools.build.lib.actions.ResourceManager;
import com.google.devtools.build.lib.analysis.test.TestActionContext;
Expand All @@ -34,26 +36,30 @@
import com.google.devtools.build.lib.exec.local.LocalSpawnRunner;
import com.google.devtools.build.lib.exec.local.PosixLocalEnvProvider;
import com.google.devtools.build.lib.exec.local.WindowsLocalEnvProvider;
import com.google.devtools.build.lib.rules.cpp.IncludeScanningContext;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction;
import com.google.devtools.build.lib.rules.cpp.CppIncludeExtractionContext;
import com.google.devtools.build.lib.rules.cpp.CppIncludeScanningContext;
import com.google.devtools.build.lib.rules.cpp.IncludeProcessing;
import com.google.devtools.build.lib.rules.cpp.SpawnGccStrategy;
import com.google.devtools.build.lib.rules.test.ExclusiveTestStrategy;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import javax.annotation.Nullable;

/**
* Provide a standalone, local execution context.
*/
public class StandaloneActionContextProvider extends ActionContextProvider {

/**
* a IncludeScanningContext that does nothing. Since local execution does not need to
* discover inclusion in advance, we do not need include scanning.
* An IncludeExtractionContext that does nothing. Since local execution does not need to discover
* inclusion in advance, we do not need include scanning.
*/
@ExecutionStrategy(contextType = IncludeScanningContext.class)
class DummyIncludeScanningContext implements IncludeScanningContext {
@ExecutionStrategy(contextType = CppIncludeExtractionContext.class)
class DummyCppIncludeExtractionContext implements CppIncludeExtractionContext {
@Override
public void extractIncludes(
ActionExecutionContext actionExecutionContext,
Expand All @@ -70,6 +76,23 @@ public ArtifactResolver getArtifactResolver() {
}
}

/**
* An IncludeScanningContext that does nothing. Since local execution does not need to discover
* inclusion in advance, we do not need include scanning.
*/
@ExecutionStrategy(contextType = CppIncludeScanningContext.class)
static class DummyCppIncludeScanningContext implements CppIncludeScanningContext {
@Override
@Nullable
public Iterable<Artifact> findAdditionalInputs(
CppCompileAction action,
ActionExecutionContext actionExecutionContext,
IncludeProcessing includeProcessing)
throws ExecException, InterruptedException, ActionExecutionException {
return null;
}
}

private final CommandEnvironment env;

public StandaloneActionContextProvider(CommandEnvironment env) {
Expand All @@ -92,7 +115,8 @@ public Iterable<? extends ActionContext> getActionContexts() {
// last one from strategies list will be used
return ImmutableList.of(
new StandaloneSpawnStrategy(env.getExecRoot(), createLocalRunner(env)),
new DummyIncludeScanningContext(),
new DummyCppIncludeExtractionContext(),
new DummyCppIncludeScanningContext(),
new SpawnGccStrategy(),
testStrategy,
new ExclusiveTestStrategy(testStrategy),
Expand Down

0 comments on commit b116240

Please sign in to comment.