diff options
| author | Arthur LAURENT <[email protected]> | 2025-04-24 16:35:23 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-04-24 16:35:23 +0200 |
| commit | 58854bf7b3018a7d52dbaea096cdd4d2307dc27d (patch) | |
| tree | 66dcda01a8a8648e82877a1b1da2a32530e81841 /xmake/rules/c++/modules | |
| parent | 175b91c0dbd964499e1049db5c70991deb87123c (diff) | |
(C++ modules support) factorize implementation getter
Diffstat (limited to 'xmake/rules/c++/modules')
| -rw-r--r-- | xmake/rules/c++/modules/builder.lua | 17 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/scanner.lua | 17 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/support.lua | 21 |
3 files changed, 15 insertions, 40 deletions
diff --git a/xmake/rules/c++/modules/builder.lua b/xmake/rules/c++/modules/builder.lua index 51de339f7..34b603abd 100644 --- a/xmake/rules/c++/modules/builder.lua +++ b/xmake/rules/c++/modules/builder.lua @@ -235,22 +235,7 @@ function _is_duplicated_headerunit(target, key) end function _builder(target) - local cachekey = tostring(target) - local builder = support.memcache():get2("builder", cachekey) - if builder == nil then - if target:has_tool("cxx", "clang", "clangxx", "clang_cl") then - builder = import("clang.builder", {anonymous = true}) - elseif target:has_tool("cxx", "gcc", "gxx") then - builder = import("gcc.builder", {anonymous = true}) - elseif target:has_tool("cxx", "cl") then - builder = import("msvc.builder", {anonymous = true}) - else - local _, toolname = target:tool("cxx") - raise("compiler(%s): does not support c++ module!", toolname) - end - support.memcache():set2("builder", cachekey, builder) - end - return builder + return support.import_implementation_of(target, "builder") end function mark_build(target, name) diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua index 18f90cfca..5d5054460 100644 --- a/xmake/rules/c++/modules/scanner.lua +++ b/xmake/rules/c++/modules/scanner.lua @@ -28,22 +28,7 @@ import("support") import("stlheaders") function _scanner(target) - local cachekey = tostring(target) - local scanner = support.memcache():get2("scanner", cachekey) - if scanner == nil then - if target:has_tool("cxx", "clang", "clangxx", "clang_cl") then - scanner = import("clang.scanner", {anonymous = true}) - elseif target:has_tool("cxx", "gcc", "gxx") then - scanner = import("gcc.scanner", {anonymous = true}) - elseif target:has_tool("cxx", "cl") then - scanner = import("msvc.scanner", {anonymous = true}) - else - local _, toolname = target:tool("cxx") - raise("compiler(%s): does not support c++ module!", toolname) - end - support.memcache():set2("scanner", cachekey, scanner) - end - return scanner + return support.import_implementation_of(target, "scanner") end function _parse_meta_info(target, metafile) diff --git a/xmake/rules/c++/modules/support.lua b/xmake/rules/c++/modules/support.lua index e1e244c08..3d9f108ab 100644 --- a/xmake/rules/c++/modules/support.lua +++ b/xmake/rules/c++/modules/support.lua @@ -26,22 +26,27 @@ import("core.project.project") import("core.project.config") function _support(target) + return import_implementation_of(target, "support") +end + +function import_implementation_of(target, name) + local cachekey = tostring(target) - local support = memcache():get2("support", cachekey) - if support == nil then + local implementation = memcache():get2(name, cachekey) + if implementation == nil then if target:has_tool("cxx", "clang", "clangxx", "clang_cl") then - support = import("clang.support", {anonymous = true}) + implementation = import("clang." .. name, {anonymous = true}) elseif target:has_tool("cxx", "gcc", "gxx") then - support = import("gcc.support", {anonymous = true}) + implementation = import("gcc." .. name, {anonymous = true}) elseif target:has_tool("cxx", "cl") then - support = import("msvc.support", {anonymous = true}) + implementation = import("msvc." .. name, {anonymous = true}) else local _, toolname = target:tool("cxx") - raise("compiler(%s): does not support c++ module!", toolname) + raise("compiler(%s): does not implementation c++ module!", toolname) end - memcache():set2("support", cachekey, support) + memcache():set2(name, cachekey, implementation) end - return support + return implementation end -- load module support for the current target |
