Skip to content

Commit fdec096

Browse files
committed
ClangImporter: Refactor Clang invocation path remapping after change to...
...`clang::tooling::dependencies::DepscanPrefixMapping::configurePrefixMapper` See swiftlang/llvm-project#10723
1 parent 50ee3f4 commit fdec096

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/ConcreteDeclRef.h"
2727
#include "swift/AST/DiagnosticEngine.h"
2828
#include "swift/AST/DiagnosticsClangImporter.h"
29+
#include "swift/AST/DiagnosticsFrontend.h"
2930
#include "swift/AST/DiagnosticsSema.h"
3031
#include "swift/AST/Evaluator.h"
3132
#include "swift/AST/IRGenOptions.h"
@@ -4206,9 +4207,22 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
42064207

42074208
if (!Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper.empty()) {
42084209
// Remap all the paths if requested.
4210+
// FIXME: Should we also do
4211+
// https://github.com/swiftlang/llvm-project/pull/10723?
42094212
llvm::PrefixMapper Mapper;
4210-
clang::tooling::dependencies::DepscanPrefixMapping::configurePrefixMapper(
4211-
Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Mapper);
4213+
SmallVector<llvm::MappedPrefix> Prefixes;
4214+
if (auto E = llvm::MappedPrefix::transformJoined(
4215+
Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Prefixes)) {
4216+
// Save this string. In general the diagnostic might outlive this
4217+
// function.
4218+
auto identifier =
4219+
Impl.SwiftContext.getIdentifier(llvm::toString(std::move(E)));
4220+
Impl.SwiftContext.Diags.diagnose(SourceLoc(), diag::error_prefix_mapping,
4221+
identifier.str());
4222+
}
4223+
Mapper.addRange(Prefixes);
4224+
Mapper.sort();
4225+
42124226
clang::tooling::dependencies::DepscanPrefixMapping::remapInvocationPaths(
42134227
instance, Mapper);
42144228
instance.getFrontendOpts().PathPrefixMappings.clear();

0 commit comments

Comments
 (0)