diff options
| author | ruki <[email protected]> | 2025-01-09 10:19:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-01-09 10:19:14 +0800 |
| commit | 8e24b5a44dcffbee1444d715909a64014e11e866 (patch) | |
| tree | a2f0aaf7b582dae30d4db636efd199ccb158e0d8 /xmake/plugins | |
| parent | 1cf6a7f479837b471a5f91410359d86983828e6a (diff) | |
| parent | 6317ffd0fe312360eb5f6e079320c01c95870ad0 (diff) | |
Merge pull request #6001 from xmake-io/namespace
Support for namespace
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 26 | ||||
| -rw-r--r-- | xmake/plugins/project/make/makefile.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/ninja/build_ninja.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/utils/target_cmds.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/show/info/target.lua | 6 |
6 files changed, 30 insertions, 11 deletions
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 203fcbe6d..5cd3431a5 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -32,13 +32,24 @@ import("filter") import("xpack_component") -- define module -local xpack = xpack or object {_init = {"_name", "_info"}} +local xpack = xpack or object {_init = {"_name", "_info", "_namespace"}} -- get name function xpack:name() return self._name end +-- get namespace +function xpack:namespace() + return self._namespace +end + +-- get fullname +function xpack:fullname() + local namespace = self:namespace() + return namespace and namespace .. "::" .. self:name() or self:name() +end + -- get values function xpack:get(name) if self._info then @@ -131,7 +142,7 @@ function xpack:targets() local targetnames = self:get("targets") if targetnames then for _, name in ipairs(targetnames) do - local target = project.target(name) + local target = project.target(name, {namespace = self:namespace()}) if target then table.insert(targets, target) else @@ -148,7 +159,7 @@ end function xpack:target(name) local targetnames = self:get("targets") if targetnames and table.contains(table.wrap(targetnames), name) then - return project.target(name) + return project.target(name, {namespace = self:namespace()}) end end @@ -506,7 +517,14 @@ end -- new a xpack, and we need to clone scope info, -- because two different format packages maybe have same scope function _new(name, info) - return xpack {name, info:clone()} + local parts = name:split("::", {plain = true}) + name = parts[#parts] + table.remove(parts) + local namespace + if #parts > 0 then + namespace = table.concat(parts, "::") + end + return xpack {name, info:clone(), namespace} end -- get xpack packages diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index 12b1b77e0..3d4d5507f 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -547,7 +547,7 @@ function _add_build_target(makefile, target, targetflags, outputdir) -- make dependence for the dependent targets for _, depname in ipairs(target:get("deps")) do - local dep = project.target(depname) + local dep = project.target(depname, {namespace = target:namespace()}) makefile:write(" " .. (dep:is_phony() and depname or _get_relative_unix_path(dep:targetfile(), outputdir))) end diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index 1264ed60c..94d6495ef 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -367,7 +367,7 @@ function _add_build_for_target(ninjafile, target, outputdir) ninjafile:print(" || $") ninjafile:write(" ") for _, dep in ipairs(deps) do - ninjafile:write(" " .. _get_relative_unix_path(project.target(dep):targetfile(), outputdir)) + ninjafile:write(" " .. _get_relative_unix_path(project.target(dep, {namespace = target:namespace()}):targetfile(), outputdir)) end end ninjafile:print("") diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua index 0b98a4ed7..332e4858d 100644 --- a/xmake/plugins/project/utils/target_cmds.lua +++ b/xmake/plugins/project/utils/target_cmds.lua @@ -64,7 +64,8 @@ function get_target_buildcmd_files(target, cmds, sourcebatch, opt) -- get rule local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!") - local ruleinst = assert(target:rule(rulename) or project.rule(rulename) or rule.rule(rulename), "unknown rule: %s", rulename) + local ruleinst = assert(target:rule(rulename) or project.rule(rulename, {namespace = target:namespace()}) or + rule.rule(rulename), "unknown rule: %s", rulename) local ignored_rules = hashset.from(opt.ignored_rules or {}) if ignored_rules:has(ruleinst:name()) then return diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index e566ab160..12d6497c0 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -585,7 +585,7 @@ function main(outputdir, vsinfo) if target:get("default") == true then table.insert(targetnames, 1, targetname) elseif target:is_binary() then - local first_target = targetnames[1] and project.target(targetnames[1]) + local first_target = targetnames[1] and project.target(targetnames[1], {namespace = target:namespace()}) if not first_target or first_target:get("default") ~= true then table.insert(targetnames, 1, targetname) else diff --git a/xmake/plugins/show/info/target.lua b/xmake/plugins/show/info/target.lua index e3aa8829d..871ed321a 100644 --- a/xmake/plugins/show/info/target.lua +++ b/xmake/plugins/show/info/target.lua @@ -78,11 +78,11 @@ function _get_values_from_pkgs(target, name) local info = components[component_name] if info then for _, value in ipairs(info[name]) do - values[value] = string.format(" -> package(%s)", pkg:name()) + values[value] = string.format(" -> package(%s)", pkg:fullname()) end else local components_str = table.concat(table.wrap(configinfo.components), ", ") - utils.warning("unknown component(%s) in add_packages(%s, {components = {%s}})", component_name, pkg:name(), components_str) + utils.warning("unknown component(%s) in add_packages(%s, {components = {%s}})", component_name, pkg:fullname(), components_str) end end end @@ -95,7 +95,7 @@ function _get_values_from_pkgs(target, name) else -- get values from the builtin package configs for _, value in ipairs(pkg:get(name)) do - values[value] = string.format(" -> package(%s)", pkg:name()) + values[value] = string.format(" -> package(%s)", pkg:fullname()) end end end |
