From 23b42cf6c904de96f6f739e987ef1085afaace07 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Thu, 6 Nov 2025 17:27:40 -0800 Subject: [PATCH] [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 --- include/swift/Option/Options.td | 2 +- lib/Frontend/CompilerInvocation.cpp | 6 ++++++ test/CAS/module_path_remap.swift | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 05cd0fa5d9db7..1c407f098026f 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -2343,7 +2343,7 @@ def scanner_prefix_map_paths : MultiArg<["-"], "scanner-prefix-map-paths", 2>, HelpText<"Remap paths reported by dependency scanner">, MetaVarName<" ">; def scanner_prefix_map : Separate<["-"], "scanner-prefix-map">, - Flags<[NewDriverOnlyOption]>, + Flags<[FrontendOption, NewDriverOnlyOption]>, HelpText<"Remap paths reported by dependency scanner">, MetaVarName<"">; def scanner_prefix_map_sdk : Separate<["-"], "scanner-prefix-map-sdk">, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c15d59e5eb1f0..372f9988b1673 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2519,6 +2519,12 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args, Opts.ScannerPrefixMapper.push_back({A->getValue(0), A->getValue(1)}); } + // Handle legacy prefix map option. + for (StringRef Opt : Args.getAllArgValues(OPT_scanner_prefix_map)) { + if (auto Mapping = llvm::MappedPrefix::getFromJoined(Opt)) + Opts.ScannerPrefixMapper.push_back({Mapping->Old, Mapping->New}); + } + Opts.ResolvedPluginVerification |= Args.hasArg(OPT_resolved_plugin_verification); diff --git a/test/CAS/module_path_remap.swift b/test/CAS/module_path_remap.swift index 40648b749d3b4..d0648f7481eec 100644 --- a/test/CAS/module_path_remap.swift +++ b/test/CAS/module_path_remap.swift @@ -31,4 +31,11 @@ // RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F commandLine | %FileCheck %s -check-prefix CLANG-CMD // CLANG-CMD: /^src/test/ScanDependencies/Inputs/CHeaders/module.modulemap +/// Check the legacy option. +// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps2.json \ +// RUN: -I %S/../ScanDependencies/Inputs/CHeaders -I %S/../ScanDependencies/Inputs/Swift -emit-dependencies \ +// RUN: -import-objc-header %S/../ScanDependencies/Inputs/CHeaders/Bridging.h -swift-version 4 -cache-compile-job \ +// 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 +// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps2.json deps2 casFSRootID > %t/deps2.fs.casid +// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-include-tree-list @%t/deps2.fs.casid | %FileCheck %s -check-prefix DEPS-FS