Skip to content

Commit

Permalink
Add basic C++ path mapping support
Browse files Browse the repository at this point in the history
Basic support for path mapping for `CppCompile` actions is added by wiring up `PathMapper` with:
* structured path variables for files and include paths (`Artifact` and `NestedSet<PathFragment>`)
* inputs/outputs via `Spawn#getPathMapper()`
* header discovery

Also turns `external_include_paths` into a structured variable, which was missed in bazelbuild#22463.

The following features are known to be unsupported for now:
* `layering_check` (requires rewriting paths to and in module maps)
* source tree artifacts (requires wiring up `PathMapper` in `CppCompileActionTemplate`)
* location expanded paths to generated files such as sanitizer suppression lists (requires heuristically rewriting paths in `user_compile_flags`)

These limitations will be lifted in follow-up PRs.

Work towards bazelbuild#6526

RELNOTES: Experimental support for path mapping `CppCompile` actions can be enabled via `--modify_execution_info=CppCompile=+supports-path-mapping`.

Closes bazelbuild#22445.

PiperOrigin-RevId: 646109274
Change-Id: I6f4eb92b6be3052547f144c681b6588e9fc40693
  • Loading branch information
fmeum committed Jul 5, 2024
1 parent 6e9693e commit 6cc1b49
Show file tree
Hide file tree
Showing 25 changed files with 801 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class SimpleSpawn implements Spawn {
private final ImmutableList<ActionInput> outputs;
// If null, all outputs are mandatory.
@Nullable private final Set<? extends ActionInput> mandatoryOutputs;
private final PathMapper pathMapper;
private final LocalResourcesSupplier localResourcesSupplier;
private ResourceSet localResourcesCached;

Expand All @@ -55,7 +56,8 @@ private SimpleSpawn(
Collection<? extends ActionInput> outputs,
@Nullable final Set<? extends ActionInput> mandatoryOutputs,
@Nullable ResourceSet localResources,
@Nullable LocalResourcesSupplier localResourcesSupplier) {
@Nullable LocalResourcesSupplier localResourcesSupplier,
PathMapper pathMapper) {
this.owner = Preconditions.checkNotNull(owner);
this.arguments = Preconditions.checkNotNull(arguments);
this.environment = Preconditions.checkNotNull(environment);
Expand All @@ -77,6 +79,7 @@ private SimpleSpawn(
this.localResourcesSupplier = localResourcesSupplier;
this.localResourcesCached = null;
}
this.pathMapper = pathMapper;
}

public SimpleSpawn(
Expand All @@ -101,7 +104,8 @@ public SimpleSpawn(
outputs,
mandatoryOutputs,
localResources,
/*localResourcesSupplier=*/ null);
/* localResourcesSupplier= */ null,
PathMapper.NOOP);
}

@SuppressWarnings("TooManyParameters")
Expand All @@ -126,8 +130,63 @@ public SimpleSpawn(
tools,
outputs,
mandatoryOutputs,
/*localResources=*/ null,
localResourcesSupplier);
/* localResources= */ null,
localResourcesSupplier,
PathMapper.NOOP);
}

public SimpleSpawn(
ActionExecutionMetadata owner,
ImmutableList<String> arguments,
ImmutableMap<String, String> environment,
ImmutableMap<String, String> executionInfo,
ImmutableMap<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings,
NestedSet<? extends ActionInput> inputs,
NestedSet<? extends ActionInput> tools,
Collection<? extends ActionInput> outputs,
@Nullable Set<? extends ActionInput> mandatoryOutputs,
LocalResourcesSupplier localResourcesSupplier,
PathMapper pathMapper) {
this(
owner,
arguments,
environment,
executionInfo,
filesetMappings,
inputs,
tools,
outputs,
mandatoryOutputs,
null,
localResourcesSupplier,
pathMapper);
}

public SimpleSpawn(
ActionExecutionMetadata owner,
ImmutableList<String> arguments,
ImmutableMap<String, String> environment,
ImmutableMap<String, String> executionInfo,
ImmutableMap<Artifact, ImmutableList<FilesetOutputSymlink>> filesetMappings,
NestedSet<? extends ActionInput> inputs,
NestedSet<? extends ActionInput> tools,
Collection<? extends ActionInput> outputs,
@Nullable Set<? extends ActionInput> mandatoryOutputs,
ResourceSet localResources,
PathMapper pathMapper) {
this(
owner,
arguments,
environment,
executionInfo,
filesetMappings,
inputs,
tools,
outputs,
mandatoryOutputs,
localResources,
null,
pathMapper);
}

public SimpleSpawn(
Expand Down Expand Up @@ -226,6 +285,11 @@ public ResourceSet getLocalResources() throws ExecException {
return localResourcesCached;
}

@Override
public PathMapper getPathMapper() {
return pathMapper;
}

@Override
public String getMnemonic() {
return owner.getMnemonic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.PathMapper;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
Expand Down Expand Up @@ -288,7 +289,7 @@ public Dict<String, String> getEnvironmentVariable(
return Dict.immutableCopyOf(
featureConfiguration
.getFeatureConfiguration()
.getEnvironmentVariables(actionName, variables));
.getEnvironmentVariables(actionName, variables, PathMapper.NOOP));
}

@Override
Expand Down
Loading

0 comments on commit 6cc1b49

Please sign in to comment.