Skip to content

Commit fbfc7a6

Browse files
Merge pull request #82745 from sina-mahdavi/sina-mahdavi/new-scanner-prefix-map-option
Add `-scanner-prefix-map-paths` to the frontend
2 parents a8c36dc + 0384347 commit fbfc7a6

15 files changed

+43
-38
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
@@ -720,7 +720,7 @@ class CachingDiagnosticsProcessor::Implementation
720720
Instance.getInvocation().getFrontendOptions().InputsAndOutputs),
721721
Diags(Instance.getDiags()), CAS(*Instance.getSharedCASInstance()) {
722722
SmallVector<llvm::MappedPrefix, 4> Prefixes;
723-
llvm::MappedPrefix::transformJoinedIfValid(
723+
llvm::MappedPrefix::transformPairs(
724724
Instance.getInvocation().getFrontendOptions().CacheReplayPrefixMap,
725725
Prefixes);
726726
Mapper.addRange(Prefixes);

lib/Frontend/CompilerInvocation.cpp

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

24832480
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();

test/CAS/block-list.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -O \
55
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
66
// RUN: -blocklist-file %t/blocklist.yml -blocklist-file %t/empty.yml \
7-
// RUN: -scanner-prefix-map %t=/^tmp -I %t/include \
7+
// RUN: -scanner-prefix-map-paths %t /^tmp -I %t/include \
88
// RUN: %t/main.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas
99

1010
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd
@@ -38,7 +38,7 @@
3838
// RUN: -blocklist-file /^tmp/blocklist.yml -blocklist-file /^tmp/empty.yml \
3939
// RUN: -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation \
4040
// RUN: -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation \
41-
// RUN: -cache-replay-prefix-map /^tmp=%t \
41+
// RUN: -cache-replay-prefix-map /^tmp %t \
4242
// RUN: /^tmp/main.swift @%t/MyApp.cmd 2>&1 | %FileCheck %s --check-prefix CHECK-BLOCKED
4343

4444
// REQUIRES: swift_feature_LayoutStringValueWitnesses

test/CAS/cached_diagnostics_remap.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
/// Check path remapping.
55
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -O -import-objc-header %t/objc.h -auto-bridging-header-chaining \
66
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
7-
// RUN: %t/test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas -scanner-prefix-map %t=/^test -scanner-output-dir %t.noremap
7+
// RUN: %t/test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas -scanner-prefix-map-paths %t /^test -scanner-output-dir %t.noremap
88

99
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json bridgingHeader > %t/header.cmd
1010
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch 2>&1 | %FileCheck %s -check-prefix BRIDGE
1111
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
1212
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch > %t/keys.json
1313
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action render-diags %t/keys.json -- \
14-
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch -cache-replay-prefix-map /^test=%t 2>&1 \
14+
// RUN: %target-swift-frontend @%t/header.cmd -disable-implicit-swift-modules -O -o %t/objc.pch -cache-replay-prefix-map /^test %t 2>&1 \
1515
// RUN: | %FileCheck %s -check-prefix BRIDGE -check-prefix BRIDGE-REMAP
1616

1717
// RUN: %{python} %S/Inputs/ExtractOutputKey.py %t/keys.json > %t/key
@@ -33,7 +33,7 @@
3333
// RUN: -emit-module -o %t/test.swiftmodule /^test/test.swift > %t/cache_key.json
3434
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action render-diags %t/cache_key.json -- %target-swift-frontend -cache-compile-job -module-name Test \
3535
// RUN: -O -cas-path %t/cas @%t/MyApp.cmd \
36-
// RUN: -emit-module -o %t/test.swiftmodule /^test/test.swift -cache-replay-prefix-map /^test=%t 2>&1 | %FileCheck %s --check-prefix REMAP
36+
// RUN: -emit-module -o %t/test.swiftmodule /^test/test.swift -cache-replay-prefix-map /^test %t 2>&1 | %FileCheck %s --check-prefix REMAP
3737

3838
// BRIDGE: /^test/objc.h:3:2: warning: warning in bridging header
3939
// BRIDGE-REMAP: BUILD_DIR{{.*}}{{/|\\}}objc.h:3:2: warning: warning in bridging header

0 commit comments

Comments
 (0)