From 0934170a61ce3080f3a024f5456f9d406a1a3157 Mon Sep 17 00:00:00 2001
From: Yuka Takahashi <yukatkh@gmail.com>
Date: Tue, 25 Sep 2018 18:00:57 +0200
Subject: [PATCH] [cxxmodules] Allow ROOT_ prefix module to be implicitly build
 by rootcling

Previously, [system] was used to mark modules which were supporsed be
implicitly built by rootcling for runtime modules. This was a workaround, and it was causing
SourceLocation error in cxxmodules as it is also using the same
modulemap.

To remove the workaround, we are introducing a new convention that modules
start with ROOT_ is treated as "ROOT system modules", which can be build
implicitly.
---
 build/unix/module.modulemap         | 17 ++++++++++-------
 core/dictgen/src/rootcling_impl.cxx |  9 +++++----
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/build/unix/module.modulemap b/build/unix/module.modulemap
index 71d36957646..5f4f685b2fb 100644
--- a/build/unix/module.modulemap
+++ b/build/unix/module.modulemap
@@ -1,6 +1,6 @@
 // This module contains header files from module Core which can be used in both
 // C and C++ context.
-module ROOT_Foundation_C [system] {
+module ROOT_Foundation_C  {
   module "ThreadLocalStorage.h" { header "ThreadLocalStorage.h" export * }
   module "strlcpy.h" { header "strlcpy.h" export * }
   module "snprintf.h" { header "snprintf.h" export * }
@@ -11,7 +11,7 @@ module ROOT_Foundation_C [system] {
 // This module contains header files from module Core which are used as
 // configuration for ROOT. They contain a lot of macro definitions which are
 // supposed to be textually expanded in each TU.
-module ROOT_Config [system] {
+module ROOT_Config  {
   // These headers are supposed to be only textually expanded for each TU.
   module "RVersion.h" { textual header "RVersion.h" export * }
   module "RConfig.h" { textual header "RConfig.h" export * }
@@ -23,10 +23,13 @@ module ROOT_Config [system] {
   export *
 }
 
+module ROOT_Rtypes {
+  module "RtypesCore.h" { header "RtypesCore.h" export * }
+}
+
 // This module contains header files from module Core which do not need -frtti.
 // They are mainly needed for ROOT stage1 build.
-module ROOT_Foundation_Stage1_NoRTTI [system] {
-  module "RtypesCore.h" { header "RtypesCore.h" export * }
+module ROOT_Foundation_Stage1_NoRTTI  {
   module "ESTLType.h" { header "ESTLType.h" export * }
   module "ROOT/RStringView.hxx" {
     // RWrap_libcpp_string_view.h is meant to be included only by ROOT/RStringView.hxx
@@ -55,9 +58,9 @@ module ROOT_Foundation_Stage1_NoRTTI [system] {
 // when there is no folder GL or contents in it.
 // module ROOT_Glew {
   // Depending on the platform we get some of these three installed.
-  module "glew.h" [system] { header "GL/glew.h" export * }
-  module "wglew.h" [system] { header "GL/wglew.h" export * }
-  module "glxew.h" [system] { header "GL/glxew.h" export * }
+  module "glew.h" { header "GL/glew.h" export * }
+  module "wglew.h" { header "GL/wglew.h" export * }
+  module "glxew.h" { header "GL/glxew.h" export * }
 //  link "lib/libGLEW.so"
 //}
 
diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx
index c1094a181cb..ec6be201761 100644
--- a/core/dictgen/src/rootcling_impl.cxx
+++ b/core/dictgen/src/rootcling_impl.cxx
@@ -3912,14 +3912,15 @@ public:
          }
       }
 
-      // Skip the diag only if we build a system module. We still print the diag
+      // Skip the diag only if we build a ROOT system module or a system module. We still print the diag
       // when building a non-system module as we will print an error below and the
       // user should see the detailed default clang diagnostic.
-      bool isSystemModuleDiag = module && module->IsSystem;
-      if (!isSystemModuleDiag)
+      bool isROOTSystemModuleDiag = module && llvm::StringRef(moduleName).startswith("ROOT_");
+      bool isSystemModuleDiag = module && module && module->IsSystem;
+      if (!isROOTSystemModuleDiag && !isSystemModuleDiag)
          fChild->HandleDiagnostic(DiagLevel, Info);
 
-      if (ID == remark_module_build && !isSystemModuleDiag) {
+      if (ID == remark_module_build && !isROOTSystemModuleDiag && !isSystemModuleDiag) {
          ROOT::TMetaUtils::Error(0,
                                  "Had to build non-system module %s implicitly. You first need to\n"
                                  "generate the dictionary for %s or mark the C++ module as a system\n"
-- 
GitLab