Skip to content

Commit 3d85f82

Browse files
[CAS] Support legacy prefix map option
Bring back legacy prefix map option to allow an older swift-driver to work with newer swift-frontend. For old swift-driver, it will always send the old style prefix map option, so the new compiler needs to support that. rdar://164208526
1 parent f219e86 commit 3d85f82

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ def scanner_prefix_map_paths : MultiArg<["-"], "scanner-prefix-map-paths", 2>,
23382338
HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"<prefix> <replacement>">;
23392339

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

23442344
def scanner_prefix_map_sdk : Separate<["-"], "scanner-prefix-map-sdk">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,15 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
25182518
Opts.ScannerPrefixMapper.push_back({A->getValue(0), A->getValue(1)});
25192519
}
25202520

2521+
// Handle legacy prefix map option.
2522+
for (StringRef Opt : Args.getAllArgValues(OPT_scanner_prefix_map)) {
2523+
if (auto Mapping = llvm::MappedPrefix::getFromJoined(Opt)) {
2524+
Opts.ScannerPrefixMapper.push_back({Mapping->Old, Mapping->New});
2525+
} else {
2526+
Diags.diagnose(SourceLoc(), diag::error_prefix_mapping, Opt);
2527+
}
2528+
}
2529+
25212530
Opts.ResolvedPluginVerification |=
25222531
Args.hasArg(OPT_resolved_plugin_verification);
25232532

test/CAS/module_path_remap.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@
3131
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F commandLine | %FileCheck %s -check-prefix CLANG-CMD
3232
// CLANG-CMD: /^src/test/ScanDependencies/Inputs/CHeaders/module.modulemap
3333

34+
/// Check the legacy option.
35+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps2.json \
36+
// RUN: -I %S/../ScanDependencies/Inputs/CHeaders -I %S/../ScanDependencies/Inputs/Swift -emit-dependencies \
37+
// RUN: -import-objc-header %S/../ScanDependencies/Inputs/CHeaders/Bridging.h -swift-version 4 -cache-compile-job \
38+
// RUN: -cas-path %t/cas -scanner-prefix-map %swift_src_root=/^src -scanner-prefix-map %t=/^tmp -scanner-output-dir %t -auto-bridging-header-chaining
3439

40+
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps2.json deps2 casFSRootID > %t/deps2.fs.casid
41+
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-include-tree-list @%t/deps2.fs.casid | %FileCheck %s -check-prefix DEPS-FS

0 commit comments

Comments
 (0)