Skip to content

Commit c5bbdbd

Browse files
committed
Add -scanner-prefix-map-paths to the frontend
1 parent dd28c53 commit c5bbdbd

File tree

8 files changed

+22
-17
lines changed

8 files changed

+22
-17
lines changed

include/swift/AST/PluginLoader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ class PluginLoader {
5353
llvm::DenseMap<swift::Identifier, PluginEntry> &getPluginMap();
5454

5555
/// Resolved plugin path remappings.
56-
std::vector<std::string> PathRemap;
56+
std::vector<std::pair<std::string, std::string>> PathRemap;
5757

5858
public:
5959
PluginLoader(ASTContext &Ctx, DependencyTracker *DepTracker,
60-
std::optional<std::vector<std::string>> Remap = std::nullopt,
60+
std::optional<std::vector<std::pair<std::string, std::string>>>
61+
Remap = std::nullopt,
6162
bool disableSandbox = false)
6263
: Ctx(Ctx), DepTracker(DepTracker), disableSandbox(disableSandbox) {
6364
if (Remap)

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class FrontendOptions {
145145
std::string VerifyGenericSignaturesInModule;
146146

147147
/// CacheReplay PrefixMap.
148-
std::vector<std::string> CacheReplayPrefixMap;
148+
std::vector<std::pair<std::string, std::string>> CacheReplayPrefixMap;
149149

150150
/// Number of retry opening an input file if the previous opening returns
151151
/// bad file descriptor error.

include/swift/Option/Options.td

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,12 @@ def sdk_module_cache_path : Separate<["-"], "sdk-module-cache-path">,
22242224
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
22252225
HelpText<"Specifies the module cache path for explicitly-built SDK modules">;
22262226

2227-
def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">,
2227+
def scanner_prefix_map_paths : MultiArg<["-"], "scanner-prefix-map-paths", 2>,
22282228
Flags<[FrontendOption, NewDriverOnlyOption]>,
2229+
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix> <replacement>">;
2230+
2231+
def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">,
2232+
Flags<[NewDriverOnlyOption]>,
22292233
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix=replacement>">;
22302234

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

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

22432247
// END ONLY SUPPORTED IN NEW DRIVER
22442248

lib/AST/PluginLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ PluginLoader::getPluginMap() {
100100
std::optional<llvm::PrefixMapper> mapper;
101101
if (!PathRemap.empty()) {
102102
SmallVector<llvm::MappedPrefix, 4> prefixes;
103-
llvm::MappedPrefix::transformJoinedIfValid(PathRemap, prefixes);
103+
llvm::MappedPrefix::transformPairs(PathRemap, prefixes);
104104
mapper.emplace();
105105
mapper->addRange(prefixes);
106106
mapper->sort();

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Option/ArgList.h"
3232
#include "llvm/Option/Option.h"
3333
#include "llvm/Support/Compression.h"
34+
#include "llvm/Support/PrefixMapper.h"
3435
#include "llvm/Support/Process.h"
3536
#include "llvm/Support/FileSystem.h"
3637
#include "llvm/Support/LineIterator.h"
@@ -315,7 +316,9 @@ bool ArgsToFrontendOptionsConverter::convert(
315316
return true;
316317

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

320323
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)) {
321324
if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) ||

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ class CachingDiagnosticsProcessor::Implementation
721721
Instance.getInvocation().getFrontendOptions().InputsAndOutputs),
722722
Diags(Instance.getDiags()), CAS(*Instance.getSharedCASInstance()) {
723723
SmallVector<llvm::MappedPrefix, 4> Prefixes;
724-
llvm::MappedPrefix::transformJoinedIfValid(
724+
llvm::MappedPrefix::transformPairs(
725725
Instance.getInvocation().getFrontendOptions().CacheReplayPrefixMap,
726726
Prefixes);
727727
Mapper.addRange(Prefixes);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,12 +2473,9 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
24732473
auto SplitMap = StringRef(A).split('=');
24742474
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
24752475
}
2476-
for (StringRef Opt : Args.getAllArgValues(OPT_scanner_prefix_map)) {
2477-
if (auto Mapping = llvm::MappedPrefix::getFromJoined(Opt)) {
2478-
Opts.ScannerPrefixMapper.push_back({Mapping->Old, Mapping->New});
2479-
} else {
2480-
Diags.diagnose(SourceLoc(), diag::error_prefix_mapping, Opt);
2481-
}
2476+
2477+
for (const Arg *A : Args.filtered(OPT_scanner_prefix_map_paths)) {
2478+
Opts.ScannerPrefixMapper.push_back({A->getValue(0), A->getValue(1)});
24822479
}
24832480

24842481
Opts.ResolvedPluginVerification |=

lib/Frontend/MakeStyleDependencies.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ reversePathSortedFilenames(const Container &elts) {
9595
static void emitMakeDependenciesFile(std::vector<std::string> &dependencies,
9696
const FrontendOptions &opts,
9797
const InputFile &input,
98-
const std::vector<std::string> &prefixMap,
98+
const std::vector<std::pair<std::string, std::string>> &prefixMap,
9999
llvm::raw_ostream &os) {
100100
// Prefix map all the path if needed.
101101
if (!prefixMap.empty()) {
102102
SmallVector<llvm::MappedPrefix, 4> prefixes;
103-
llvm::MappedPrefix::transformJoinedIfValid(prefixMap, prefixes);
103+
llvm::MappedPrefix::transformPairs(prefixMap, prefixes);
104104
llvm::PrefixMapper mapper;
105105
mapper.addRange(prefixes);
106106
mapper.sort();

0 commit comments

Comments
 (0)