mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Caching] Create clang importer from cc1 args directly
When caching build is enabled, teach dependency scanner to report command-lines with `-direct-clang-cc1-module-build` so the later compilation can instantiate clang importer with cc1 args directly. This avoids running clang driver code, which might involve file system lookups, which are the file deps that are not captured and might result in different compilation mode. rdar://119275464
This commit is contained in:
@@ -1659,43 +1659,6 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args,
|
||||
Opts.ExtraArgs.push_back(A->getValue());
|
||||
}
|
||||
|
||||
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= 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.)
|
||||
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 (auto *A = Args.getLastArg(OPT_file_compilation_dir)) {
|
||||
// Forward the -file-compilation-dir flag to correctly set the
|
||||
// debug compilation directory.
|
||||
std::string Val(A->getValue());
|
||||
Opts.ExtraArgs.push_back("-ffile-compilation-dir=" + Val);
|
||||
}
|
||||
|
||||
if (CASOpts.CASFSRootIDs.empty() &&
|
||||
CASOpts.ClangIncludeTrees.empty()) {
|
||||
if (!workingDirectory.empty()) {
|
||||
// Provide a working directory to Clang as well if there are any -Xcc
|
||||
// options, in case some of them are search-related. But do it at the
|
||||
// beginning, so that an explicit -Xcc -working-directory will win.
|
||||
Opts.ExtraArgs.insert(Opts.ExtraArgs.begin(),
|
||||
{"-working-directory", workingDirectory.str()});
|
||||
}
|
||||
}
|
||||
|
||||
Opts.DumpClangDiagnostics |= Args.hasArg(OPT_dump_clang_diagnostics);
|
||||
|
||||
// When the repl is invoked directly (ie. `lldb --repl="..."`) the action
|
||||
@@ -1755,6 +1718,45 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args,
|
||||
Opts.HasClangIncludeTreeRoot |= Args.hasArg(OPT_clang_include_tree_root);
|
||||
}
|
||||
|
||||
// If in direct clang cc1 module build mode, return early.
|
||||
if (Opts.DirectClangCC1ModuleBuild)
|
||||
return false;
|
||||
|
||||
// Only amend the following path option when not in direct cc1 mode.
|
||||
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= 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.)
|
||||
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 (auto *A = Args.getLastArg(OPT_file_compilation_dir)) {
|
||||
// Forward the -file-compilation-dir flag to correctly set the
|
||||
// debug compilation directory.
|
||||
std::string Val(A->getValue());
|
||||
Opts.ExtraArgs.push_back("-ffile-compilation-dir=" + Val);
|
||||
}
|
||||
|
||||
if (!workingDirectory.empty()) {
|
||||
// Provide a working directory to Clang as well if there are any -Xcc
|
||||
// options, in case some of them are search-related. But do it at the
|
||||
// beginning, so that an explicit -Xcc -working-directory will win.
|
||||
Opts.ExtraArgs.insert(Opts.ExtraArgs.begin(),
|
||||
{"-working-directory", workingDirectory.str()});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user