Support hermetic indexing information

Swiftc port of https://github.com/apple/llvm-project/pull/4207.

This introduces a new flag, `-file-prefix-map` which can be used
instead of the existing `-debug-prefix-map` and `-coverage-prefix-map`
flags, and also remaps paths in index information currently.
This commit is contained in:
David Goldman
2022-04-12 18:19:35 -04:00
parent 3a9c801284
commit c232ed2913
14 changed files with 255 additions and 37 deletions

View File

@@ -1210,14 +1210,23 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
Opts.ExtraArgs.push_back(A->getValue());
}
for (auto A : Args.getAllArgValues(OPT_debug_prefix_map)) {
for (const Arg *A : Args.filtered(OPT_file_prefix_map,
OPT_debug_prefix_map)) {
std::string Val(A->getValue());
// Forward -debug-prefix-map arguments from Swift to Clang as
// -fdebug-prefix-map. This is required to ensure DIFiles created there,
// like "<swift-imported-modules>", have their paths remapped properly.
// -fdebug-prefix-map= and -file-prefix-map as -ffile-prefix-map=.
//
// This is required to ensure DIFiles created there, like
/// "<swift-imported-modules>", as well as index data, have their paths
// remapped properly.
//
// (Note, however, that Clang's usage of std::map means that the remapping
// may not be applied in the same order, which can matter if one mapping is
// a prefix of another.)
Opts.ExtraArgs.push_back("-fdebug-prefix-map=" + A);
if (A->getOption().matches(OPT_file_prefix_map))
Opts.ExtraArgs.push_back("-ffile-prefix-map=" + Val);
else
Opts.ExtraArgs.push_back("-fdebug-prefix-map=" + Val);
}
if (!workingDirectory.empty()) {
@@ -2002,6 +2011,13 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
: "-gdwarf_types");
}
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
auto SplitMap = StringRef(A).split('=');
Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second);
Opts.DebugPrefixMap.addMapping(SplitMap.first, SplitMap.second);
Opts.CoveragePrefixMap.addMapping(SplitMap.first, SplitMap.second);
}
for (auto A : Args.getAllArgValues(options::OPT_debug_prefix_map)) {
auto SplitMap = StringRef(A).split('=');
Opts.DebugPrefixMap.addMapping(SplitMap.first, SplitMap.second);