Skip to content

Add -scanner-prefix-map-paths to the frontend #82745

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions include/swift/AST/PluginLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class PluginLoader {
llvm::DenseMap<swift::Identifier, PluginEntry> &getPluginMap();

/// Resolved plugin path remappings.
std::vector<std::string> PathRemap;
std::vector<std::pair<std::string, std::string>> PathRemap;

public:
PluginLoader(ASTContext &Ctx, DependencyTracker *DepTracker,
std::optional<std::vector<std::string>> Remap = std::nullopt,
std::optional<std::vector<std::pair<std::string, std::string>>> Remap = std::nullopt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format the line.

bool disableSandbox = false)
: Ctx(Ctx), DepTracker(DepTracker), disableSandbox(disableSandbox) {
if (Remap)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class FrontendOptions {
std::string VerifyGenericSignaturesInModule;

/// CacheReplay PrefixMap.
std::vector<std::string> CacheReplayPrefixMap;
std::vector<std::pair<std::string, std::string>> CacheReplayPrefixMap;

/// Number of retry opening an input file if the previous opening returns
/// bad file descriptor error.
Expand Down
10 changes: 7 additions & 3 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2224,8 +2224,12 @@ def sdk_module_cache_path : Separate<["-"], "sdk-module-cache-path">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
HelpText<"Specifies the module cache path for explicitly-built SDK modules">;

def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">,
def scanner_prefix_map_paths : MultiArg<["-"], "scanner-prefix-map-paths", 2>,
Flags<[FrontendOption, NewDriverOnlyOption]>,
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix> <replacement>">;

def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">,
Flags<[NewDriverOnlyOption]>,
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix=replacement>">;

def scanner_prefix_map_sdk : Separate<["-"], "scanner-prefix-map-sdk">,
Expand All @@ -2236,9 +2240,9 @@ def scanner_prefix_map_toolchain : Separate<["-"], "scanner-prefix-map-toolchain
Flags<[NewDriverOnlyOption]>,
HelpText<"Remap paths within toolchain directory reported by dependency scanner">, MetaVarName<"<path>">;

def cache_replay_prefix_map: Separate<["-"], "cache-replay-prefix-map">,
def cache_replay_prefix_map: MultiArg<["-"], "cache-replay-prefix-map", 2>,
Flags<[FrontendOption, NoDriverOption, CacheInvariant]>,
HelpText<"Remap paths when replaying outputs from cache">, MetaVarName<"<prefix=replacement>">;
HelpText<"Remap paths when replaying outputs from cache">, MetaVarName<"<prefix> <replacement>">;

// END ONLY SUPPORTED IN NEW DRIVER

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ PluginLoader::getPluginMap() {
std::optional<llvm::PrefixMapper> mapper;
if (!PathRemap.empty()) {
SmallVector<llvm::MappedPrefix, 4> prefixes;
llvm::MappedPrefix::transformJoinedIfValid(PathRemap, prefixes);
llvm::MappedPrefix::transformPairs(PathRemap, prefixes);
mapper.emplace();
mapper->addRange(prefixes);
mapper->sort();
Expand Down
5 changes: 4 additions & 1 deletion lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/PrefixMapper.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/LineIterator.h"
Expand Down Expand Up @@ -315,7 +316,9 @@ bool ArgsToFrontendOptionsConverter::convert(
return true;

Opts.DeterministicCheck |= Args.hasArg(OPT_enable_deterministic_check);
Opts.CacheReplayPrefixMap = Args.getAllArgValues(OPT_cache_replay_prefix_map);
for (const Arg *A : Args.filtered(OPT_cache_replay_prefix_map)) {
Opts.CacheReplayPrefixMap.push_back({A->getValue(0), A->getValue(1)});
}

if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)) {
if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) ||
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/CachedDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ class CachingDiagnosticsProcessor::Implementation
Instance.getInvocation().getFrontendOptions().InputsAndOutputs),
Diags(Instance.getDiags()), CAS(*Instance.getSharedCASInstance()) {
SmallVector<llvm::MappedPrefix, 4> Prefixes;
llvm::MappedPrefix::transformJoinedIfValid(
llvm::MappedPrefix::transformPairs(
Instance.getInvocation().getFrontendOptions().CacheReplayPrefixMap,
Prefixes);
Mapper.addRange(Prefixes);
Expand Down
9 changes: 3 additions & 6 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2473,12 +2473,9 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
auto SplitMap = StringRef(A).split('=');
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
}
for (StringRef Opt : Args.getAllArgValues(OPT_scanner_prefix_map)) {
if (auto Mapping = llvm::MappedPrefix::getFromJoined(Opt)) {
Opts.ScannerPrefixMapper.push_back({Mapping->Old, Mapping->New});
} else {
Diags.diagnose(SourceLoc(), diag::error_prefix_mapping, Opt);
}

for (const Arg *A : Args.filtered(OPT_scanner_prefix_map_paths)) {
Opts.ScannerPrefixMapper.push_back({A->getValue(0), A->getValue(1)});
}

Opts.ResolvedPluginVerification |=
Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/MakeStyleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ reversePathSortedFilenames(const Container &elts) {
static void emitMakeDependenciesFile(std::vector<std::string> &dependencies,
const FrontendOptions &opts,
const InputFile &input,
const std::vector<std::string> &prefixMap,
const std::vector<std::pair<std::string, std::string>> &prefixMap,
llvm::raw_ostream &os) {
// Prefix map all the path if needed.
if (!prefixMap.empty()) {
SmallVector<llvm::MappedPrefix, 4> prefixes;
llvm::MappedPrefix::transformJoinedIfValid(prefixMap, prefixes);
llvm::MappedPrefix::transformPairs(prefixMap, prefixes);
llvm::PrefixMapper mapper;
mapper.addRange(prefixes);
mapper.sort();
Expand Down