Skip to content

Commit 613caa9

Browse files
committed
Revert "[clang] Delay normalization of -fmodules-cache-path (#150123)"
This reverts commit 4a4bdde. The Serialization library doesn't link Frontend, where CompilerInstance lives, causing link failures on some build bots.
1 parent b8cefcb commit 613caa9

File tree

7 files changed

+25
-51
lines changed

7 files changed

+25
-51
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,8 +3281,7 @@ defm declspec : BoolOption<"f", "declspec",
32813281
def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, Group<i_Group>,
32823282
Flags<[]>, Visibility<[ClangOption, CC1Option]>,
32833283
MetaVarName<"<directory>">,
3284-
HelpText<"Specify the module cache path">,
3285-
MarshallingInfoString<HeaderSearchOpts<"ModuleCachePath">>;
3284+
HelpText<"Specify the module cache path">;
32863285
def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Group<i_Group>,
32873286
Flags<[]>, Visibility<[ClangOption, CC1Option]>,
32883287
MetaVarName<"<directory>">,

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,6 @@ class CompilerInstance : public ModuleLoader {
705705
GetDependencyDirectives = std::move(Getter);
706706
}
707707

708-
static void normalizeModuleCachePath(FileManager &FileMgr, StringRef Path,
709-
SmallVectorImpl<char> &NormalizedPath);
710708
std::string getSpecificModuleCachePath(StringRef ModuleHash);
711709
std::string getSpecificModuleCachePath() {
712710
return getSpecificModuleCachePath(getInvocation().getModuleHash());

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -553,25 +553,10 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
553553
PP->setDependencyDirectivesGetter(*GetDependencyDirectives);
554554
}
555555

556-
void CompilerInstance::normalizeModuleCachePath(
557-
FileManager &FileMgr, StringRef Path,
558-
SmallVectorImpl<char> &NormalizedPath) {
559-
NormalizedPath.assign(Path.begin(), Path.end());
560-
FileMgr.makeAbsolutePath(NormalizedPath);
561-
llvm::sys::path::remove_dots(NormalizedPath);
562-
}
563-
564556
std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) {
565-
assert(FileMgr && "Specific module cache path requires a FileManager");
566-
567-
if (getHeaderSearchOpts().ModuleCachePath.empty())
568-
return "";
569-
570557
// Set up the module path, including the hash for the module-creation options.
571-
SmallString<256> SpecificModuleCache;
572-
normalizeModuleCachePath(*FileMgr, getHeaderSearchOpts().ModuleCachePath,
573-
SpecificModuleCache);
574-
if (!getHeaderSearchOpts().DisableModuleHash)
558+
SmallString<256> SpecificModuleCache(getHeaderSearchOpts().ModuleCachePath);
559+
if (!SpecificModuleCache.empty() && !getHeaderSearchOpts().DisableModuleHash)
575560
llvm::sys::path::append(SpecificModuleCache, ModuleHash);
576561
return std::string(SpecificModuleCache);
577562
}

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,9 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
33153315
if (Opts.UseLibcxx)
33163316
GenerateArg(Consumer, OPT_stdlib_EQ, "libc++");
33173317

3318+
if (!Opts.ModuleCachePath.empty())
3319+
GenerateArg(Consumer, OPT_fmodules_cache_path, Opts.ModuleCachePath);
3320+
33183321
for (const auto &File : Opts.PrebuiltModuleFiles)
33193322
GenerateArg(Consumer, OPT_fmodule_file, File.first + "=" + File.second);
33203323

@@ -3417,7 +3420,8 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
34173420
}
34183421

34193422
static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
3420-
DiagnosticsEngine &Diags) {
3423+
DiagnosticsEngine &Diags,
3424+
const std::string &WorkingDir) {
34213425
unsigned NumErrorsBefore = Diags.getNumErrors();
34223426

34233427
HeaderSearchOptions *HeaderSearchOpts = &Opts;
@@ -3430,6 +3434,17 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
34303434
if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
34313435
Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0);
34323436

3437+
// Canonicalize -fmodules-cache-path before storing it.
3438+
SmallString<128> P(Args.getLastArgValue(OPT_fmodules_cache_path));
3439+
if (!(P.empty() || llvm::sys::path::is_absolute(P))) {
3440+
if (WorkingDir.empty())
3441+
llvm::sys::fs::make_absolute(P);
3442+
else
3443+
llvm::sys::fs::make_absolute(WorkingDir, P);
3444+
}
3445+
llvm::sys::path::remove_dots(P);
3446+
Opts.ModuleCachePath = std::string(P);
3447+
34333448
// Only the -fmodule-file=<name>=<file> form.
34343449
for (const auto *A : Args.filtered(OPT_fmodule_file)) {
34353450
StringRef Val = A->getValue();
@@ -5006,7 +5021,8 @@ bool CompilerInvocation::CreateFromArgsImpl(
50065021
InputKind DashX = Res.getFrontendOpts().DashX;
50075022
ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
50085023
llvm::Triple T(Res.getTargetOpts().Triple);
5009-
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags);
5024+
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags,
5025+
Res.getFileSystemOpts().WorkingDir);
50105026
if (Res.getFrontendOpts().GenReducedBMI ||
50115027
Res.getFrontendOpts().ProgramAction ==
50125028
frontend::GenerateReducedModuleInterface ||

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "clang/Basic/TargetInfo.h"
5858
#include "clang/Basic/TargetOptions.h"
5959
#include "clang/Basic/Version.h"
60-
#include "clang/Frontend/CompilerInstance.h"
6160
#include "clang/Lex/HeaderSearch.h"
6261
#include "clang/Lex/HeaderSearchOptions.h"
6362
#include "clang/Lex/MacroInfo.h"
@@ -1711,13 +1710,9 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
17111710
const HeaderSearchOptions &HSOpts =
17121711
PP.getHeaderSearchInfo().getHeaderSearchOpts();
17131712

1714-
SmallString<256> HSOpts_ModuleCachePath;
1715-
CompilerInstance::normalizeModuleCachePath(
1716-
PP.getFileManager(), HSOpts.ModuleCachePath, HSOpts_ModuleCachePath);
1717-
17181713
AddString(HSOpts.Sysroot, Record);
17191714
AddString(HSOpts.ResourceDir, Record);
1720-
AddString(HSOpts_ModuleCachePath, Record);
1715+
AddString(HSOpts.ModuleCachePath, Record);
17211716
AddString(HSOpts.ModuleUserBuildPath, Record);
17221717
Record.push_back(HSOpts.DisableModuleHash);
17231718
Record.push_back(HSOpts.ImplicitModuleMaps);

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,9 @@ class DependencyScanningAction {
449449

450450
// Use the dependency scanning optimized file system if requested to do so.
451451
if (DepFS) {
452-
SmallString<256> ModulesCachePath;
453-
CompilerInstance::normalizeModuleCachePath(
454-
*FileMgr, ScanInstance.getHeaderSearchOpts().ModuleCachePath,
455-
ModulesCachePath);
452+
StringRef ModulesCachePath =
453+
ScanInstance.getHeaderSearchOpts().ModuleCachePath;
454+
456455
DepFS->resetBypassedPathPrefix();
457456
if (!ModulesCachePath.empty())
458457
DepFS->setBypassedPathPrefix(ModulesCachePath);

clang/test/Modules/modules-cache-path-canonicalization-output.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)