Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heuristically path map copts and defines #23630

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ default ExceptionlessMapFn<Object> getMapFn(@Nullable String previousFlag) {
return MapFn.DEFAULT;
}

/**
* Heuristically maps all path-like strings in the given argument.
*/
default String mapHeuristically(String arg) {
return arg;
}

/**
* Returns a {@link FileRootApi} representing the new root of the given artifact after mapping.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public ExceptionlessMapFn<Object> getMapFn(@Nullable String previousFlag) {
return MapFn.DEFAULT;
}

@Override
public String mapHeuristically(String arg) {
return argStripper.strip(arg);
}

@Override
public FileRootApi mapRoot(Artifact artifact) {
if (Objects.equals(artifact.getRoot(), outputArtifactRoot)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ public ImmutableList<VariableValue> getSequenceValue(
ImmutableList.Builder<VariableValue> sequences =
ImmutableList.builderWithExpectedSize(values.size());
for (String value : values) {
sequences.add(new StringValue(value));
sequences.add(new StringValue(pathMapper.mapHeuristically(value)));
}
return sequences.build();
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/shell/bazel/path_mapping_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ cc_library(
name = "utils",
srcs = ["dir/utils.cc"],
hdrs = ["dir/utils.h"],
defines = ["MY_FILE=\\\"+$(execpath dir/utils.cc)+\\\""],
include_prefix = "other_dir",
strip_include_prefix = "dir",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -615,7 +616,13 @@ EOF
cat > "$pkg/common/utils/utils.cc.tpl" <<'EOF'
#include "utils.h"

#include <cstdlib>
#include <iostream>

std::string AsGreeting(const std::string& name) {
if (std::string(MY_FILE).find("-out/cfg/") == std::string::npos) {
std::cerr << "Expected path to contain '-out/cfg/'" << std::endl;
}
return "{GREETING}, " + name + "!";
}
EOF
Expand Down
Loading