Skip to content

Commit

Permalink
[7.3.0] Add basic C++ path mapping support (#22876)
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 #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 #6526

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

Closes #22445.

PiperOrigin-RevId: 646109274
Change-Id: I6f4eb92b6be3052547f144c681b6588e9fc40693

Closes #22875

Co-authored-by: Yun Peng <pcloudy@google.com>
  • Loading branch information
fmeum and meteorcloudy authored Jul 10, 2024
1 parent 279f21a commit 1debf67
Show file tree
Hide file tree
Showing 28 changed files with 810 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -57,7 +58,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 @@ -81,6 +83,7 @@ private SimpleSpawn(
this.localResourcesSupplier = localResourcesSupplier;
this.localResourcesCached = null;
}
this.pathMapper = pathMapper;
}

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

@SuppressWarnings("TooManyParameters")
Expand All @@ -134,8 +138,67 @@ 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,
RunfilesSupplier runfilesSupplier,
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,
runfilesSupplier,
filesetMappings,
inputs,
tools,
outputs,
mandatoryOutputs,
/* localResources= */ null,
localResourcesSupplier,
pathMapper);
}

public SimpleSpawn(
ActionExecutionMetadata owner,
ImmutableList<String> arguments,
ImmutableMap<String, String> environment,
ImmutableMap<String, String> executionInfo,
RunfilesSupplier runfilesSupplier,
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,
runfilesSupplier,
filesetMappings,
inputs,
tools,
outputs,
mandatoryOutputs,
localResources,
/* localResourcesSupplier= */ null,
pathMapper);
}

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

public SimpleSpawn(
Expand Down Expand Up @@ -265,6 +329,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 @@ -305,7 +306,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 1debf67

Please sign in to comment.