diff options
| author | ruki <[email protected]> | 2022-08-24 16:37:18 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-24 16:37:18 +0800 |
| commit | d0cf3945938f7e3ea971f825c22ef93a7684ac0b (patch) | |
| tree | 76c3081ca4f89848de0a49f6e9be46d79615dbe5 /xmake/rules/c++/modules/modules_support/common.lua | |
| parent | 27f07791a6ba754bb2bd07e87513af3da9c68f29 (diff) | |
| parent | ab8143a85b50dab08e1a3573f3456fb9573a699a (diff) | |
Merge pull request #2717 from xmake-io/modules
improve modules
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/common.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/common.lua | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 580d52dd9..92c92d465 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -381,26 +381,31 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile) local rule = {outputs = {jsonfile}} rule["primary-output"] = target:objectfile(sourcefile) - local module_name + local module_name_export + local module_name_private local module_deps = {} + local module_deps_set = hashset.new() local sourcecode = io.readfile(sourcefile) sourcecode = sourcecode:gsub("//.-\n", "\n") sourcecode = sourcecode:gsub("/%*.-%*/", "") for _, line in ipairs(sourcecode:split("\n", {plain = true})) do - if not module_name then - module_name = line:match("export%s+module%s+(.+)%s*;") + if not module_name_export then + module_name_export = line:match("export%s+module%s+(.+)%s*;") + end + if not module_name_private then + module_name_private = line:match("module%s+(.+)%s*;") end local module_depname = line:match("import%s+(.+)%s*;") -- we need parse module interface dep in cxx/impl_unit.cpp, e.g. hello.mpp and hello_impl.cpp -- @see https://github.com/xmake-io/xmake/pull/2664#issuecomment-1213167314 if not module_depname and not has_module_extension(sourcefile) then - module_depname = line:match("module%s+(.+)%s*;") + module_depname = module_name_private end - if module_depname then + if module_depname and not module_deps_set:has(module_depname) then local module_dep = {} -- partition? import :xxx; if module_depname:startswith(":") then - module_depname = module_name .. module_depname + module_depname = (module_name_export or module_name_private or "") .. module_depname elseif module_depname:startswith("\"") then module_depname = module_depname:sub(2, -2) module_dep["lookup-method"] = "include-quote" @@ -414,14 +419,15 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile) end module_dep["logical-name"] = module_depname table.insert(module_deps, module_dep) + module_deps_set:insert(module_depname) end end - if module_name then - table.insert(rule.outputs, module_name .. bmi_extension(target)) + if module_name_export then + table.insert(rule.outputs, module_name_export .. bmi_extension(target)) local provide = {} - provide["logical-name"] = module_name + provide["logical-name"] = module_name_export provide["source-path"] = path.absolute(sourcefile, project.directory()) rule.provides = {} |
