rmaz updated this revision to Diff 428483. rmaz added a comment. Refactor branch into existing case
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124874/new/ https://reviews.llvm.org/D124874 Files: clang/include/clang/Driver/Options.td clang/include/clang/Lex/HeaderSearchOptions.h clang/lib/Serialization/ASTWriter.cpp clang/test/Modules/module-file-home-is-cwd.m Index: clang/test/Modules/module-file-home-is-cwd.m =================================================================== --- /dev/null +++ clang/test/Modules/module-file-home-is-cwd.m @@ -0,0 +1,8 @@ +// RUN: cd %S +// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-file-home-is-cwd -fmodule-name=libA -emit-module Inputs/normal-module-map/module.map -o %t/mod.pcm +// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s + +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h' +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h' +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map' +// CHECK-NOT: MODULE_DIRECTORY Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -1224,15 +1224,24 @@ } if (WritingModule && WritingModule->Directory) { - SmallString<128> BaseDir(WritingModule->Directory->getName()); + SmallString<128> BaseDir; + if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) { + // Use the current working directory as the base path for all inputs. + auto *CWD = + Context.getSourceManager().getFileManager().getDirectory(".").get(); + BaseDir.assign(CWD->getName()); + } else { + BaseDir.assign(WritingModule->Directory->getName()); + } cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); // If the home of the module is the current working directory, then we // want to pick up the cwd of the build process loading the module, not // our cwd, when we load this module. - if (!PP.getHeaderSearchInfo() - .getHeaderSearchOpts() - .ModuleMapFileHomeIsCwd || + if (!(PP.getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModuleMapFileHomeIsCwd || + PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) || WritingModule->Directory->getName() != StringRef(".")) { // Module directory. auto Abbrev = std::make_shared<BitCodeAbbrev>(); Index: clang/include/clang/Lex/HeaderSearchOptions.h =================================================================== --- clang/include/clang/Lex/HeaderSearchOptions.h +++ clang/include/clang/Lex/HeaderSearchOptions.h @@ -143,6 +143,12 @@ /// file. unsigned ModuleMapFileHomeIsCwd : 1; + /// Set the base path of a built module file to be the current working + /// directory. This is useful for sharing module files across machines + /// that build with different paths without having to rewrite all + /// modulemap files to have working directory relative paths. + unsigned ModuleFileHomeIsCwd : 1; + /// Also search for prebuilt implicit modules in the prebuilt module cache /// path. unsigned EnablePrebuiltImplicitModules : 1; @@ -222,9 +228,9 @@ HeaderSearchOptions(StringRef _Sysroot = "/") : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false), ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false), - EnablePrebuiltImplicitModules(false), UseBuiltinIncludes(true), - UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), - UseLibcxx(false), Verbose(false), + ModuleFileHomeIsCwd(false), EnablePrebuiltImplicitModules(false), + UseBuiltinIncludes(true), UseStandardSystemIncludes(true), + UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false), ModulesValidateOncePerBuildSession(false), ModulesValidateSystemHeaders(false), ValidateASTInputFilesContent(false), UseDebugInfo(false), Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -5609,6 +5609,10 @@ HelpText<"Use the current working directory as the home directory of " "module maps specified by -fmodule-map-file=<FILE>">, MarshallingInfoFlag<HeaderSearchOpts<"ModuleMapFileHomeIsCwd">>; +def fmodule_file_home_is_cwd : Flag<["-"], "fmodule-file-home-is-cwd">, + HelpText<"Use the current working directory as the base directory of " + "compiled module files.">, + MarshallingInfoFlag<HeaderSearchOpts<"ModuleFileHomeIsCwd">>; def fmodule_feature : Separate<["-"], "fmodule-feature">, MetaVarName<"<feature>">, HelpText<"Enable <feature> in module map requires declarations">,
Index: clang/test/Modules/module-file-home-is-cwd.m =================================================================== --- /dev/null +++ clang/test/Modules/module-file-home-is-cwd.m @@ -0,0 +1,8 @@ +// RUN: cd %S +// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-file-home-is-cwd -fmodule-name=libA -emit-module Inputs/normal-module-map/module.map -o %t/mod.pcm +// RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s + +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h' +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h' +// CHECK: <INPUT_FILE {{.*}}/> blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map' +// CHECK-NOT: MODULE_DIRECTORY Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -1224,15 +1224,24 @@ } if (WritingModule && WritingModule->Directory) { - SmallString<128> BaseDir(WritingModule->Directory->getName()); + SmallString<128> BaseDir; + if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) { + // Use the current working directory as the base path for all inputs. + auto *CWD = + Context.getSourceManager().getFileManager().getDirectory(".").get(); + BaseDir.assign(CWD->getName()); + } else { + BaseDir.assign(WritingModule->Directory->getName()); + } cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); // If the home of the module is the current working directory, then we // want to pick up the cwd of the build process loading the module, not // our cwd, when we load this module. - if (!PP.getHeaderSearchInfo() - .getHeaderSearchOpts() - .ModuleMapFileHomeIsCwd || + if (!(PP.getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModuleMapFileHomeIsCwd || + PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) || WritingModule->Directory->getName() != StringRef(".")) { // Module directory. auto Abbrev = std::make_shared<BitCodeAbbrev>(); Index: clang/include/clang/Lex/HeaderSearchOptions.h =================================================================== --- clang/include/clang/Lex/HeaderSearchOptions.h +++ clang/include/clang/Lex/HeaderSearchOptions.h @@ -143,6 +143,12 @@ /// file. unsigned ModuleMapFileHomeIsCwd : 1; + /// Set the base path of a built module file to be the current working + /// directory. This is useful for sharing module files across machines + /// that build with different paths without having to rewrite all + /// modulemap files to have working directory relative paths. + unsigned ModuleFileHomeIsCwd : 1; + /// Also search for prebuilt implicit modules in the prebuilt module cache /// path. unsigned EnablePrebuiltImplicitModules : 1; @@ -222,9 +228,9 @@ HeaderSearchOptions(StringRef _Sysroot = "/") : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false), ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false), - EnablePrebuiltImplicitModules(false), UseBuiltinIncludes(true), - UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), - UseLibcxx(false), Verbose(false), + ModuleFileHomeIsCwd(false), EnablePrebuiltImplicitModules(false), + UseBuiltinIncludes(true), UseStandardSystemIncludes(true), + UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false), ModulesValidateOncePerBuildSession(false), ModulesValidateSystemHeaders(false), ValidateASTInputFilesContent(false), UseDebugInfo(false), Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -5609,6 +5609,10 @@ HelpText<"Use the current working directory as the home directory of " "module maps specified by -fmodule-map-file=<FILE>">, MarshallingInfoFlag<HeaderSearchOpts<"ModuleMapFileHomeIsCwd">>; +def fmodule_file_home_is_cwd : Flag<["-"], "fmodule-file-home-is-cwd">, + HelpText<"Use the current working directory as the base directory of " + "compiled module files.">, + MarshallingInfoFlag<HeaderSearchOpts<"ModuleFileHomeIsCwd">>; def fmodule_feature : Separate<["-"], "fmodule-feature">, MetaVarName<"<feature>">, HelpText<"Enable <feature> in module map requires declarations">,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits