summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-08 11:48:43 +0800
committerruki <[email protected]>2022-10-08 11:48:43 +0800
commitf49f2916627c39a5656417190efd94a0ec690388 (patch)
treee81509e12f673300b9b25e29f9e4a2f4e5078bff
parent2ac4dddd95828211c20099833353d722f7ff531e (diff)
fix package rule deps
-rw-r--r--xmake/core/project/package.lua12
-rw-r--r--xmake/core/project/rule.lua43
2 files changed, 41 insertions, 14 deletions
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
index 0e0b4f964..6c9155daf 100644
--- a/xmake/core/project/package.lua
+++ b/xmake/core/project/package.lua
@@ -67,16 +67,6 @@ function _instance:name()
return self._NAME
end
--- get raw package name
-function _instance:package_name()
- local packagename = self._PACKAGE_NAME
- if not packagename then
- packagename = self:requirestr():split("%s")[1]
- self._PACKAGE_NAME = packagename
- end
- return packagename
-end
-
-- get the package version
function _instance:version()
@@ -206,7 +196,7 @@ function _instance:rules()
rules = {}
for rulename, ruleinfo in pairs(ruleinfos) do
rulename = "@" .. self:name() .. "/" .. rulename
- local instance = rule.new(rulename, ruleinfo)
+ local instance = rule.new(rulename, ruleinfo, {package = self})
rules[rulename] = instance
end
self._RULES = rules
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua
index 40426906e..367107393 100644
--- a/xmake/core/project/rule.lua
+++ b/xmake/core/project/rule.lua
@@ -35,6 +35,11 @@ local sandbox = require("sandbox/sandbox")
local sandbox_os = require("sandbox/modules/os")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
+-- get package
+function _instance:_package()
+ return self._PACKAGE
+end
+
-- invalidate the previous cache
function _instance:_invalidate(name)
if name == "deps" then
@@ -45,9 +50,12 @@ end
-- build deps
function _instance:_build_deps()
- local instances = rule.rules()
+ local instances = table.clone(rule.rules())
if rule._project() then
- instances = table.join(rule.rules(), rule._project().rules())
+ table.join2(instances, rule._project().rules())
+ end
+ if self:_package() then
+ table.join2(instances, self:_package():rules())
end
self._DEPS = self._DEPS or {}
self._ORDERDEPS = self._ORDERDEPS or {}
@@ -59,6 +67,7 @@ function _instance:clone()
local instance = rule.new(self:name(), self._INFO:clone())
instance._DEPS = self._DEPS
instance._ORDERDEPS = self._ORDERDEPS
+ instance._PACKAGE = self._PACKAGE
return instance
end
@@ -84,6 +93,11 @@ function _instance:extraconf(name, item, key)
return self._INFO:extraconf(name, item, key)
end
+-- set the extra configuration
+function _instance:extraconf_set(name, item, key, value)
+ return self._INFO:extraconf_set(name, item, key, value)
+end
+
-- get the rule name
function _instance:name()
return self._NAME
@@ -343,10 +357,33 @@ function rule.apis()
end
-- new a rule instance
-function rule.new(name, info)
+function rule.new(name, info, opt)
+ opt = opt or {}
local instance = table.inherit(_instance)
instance._NAME = name
instance._INFO = info
+ instance._PACKAGE = opt.package
+ if opt.package then
+ -- replace deps in package
+ local deps = {}
+ for _, depname in ipairs(table.wrap(instance:get("deps"))) do
+ -- @xxx -> @package/xxx
+ if depname:startswith("@") and not depname:find("/", 1, true) then
+ depname = "@" .. opt.package:name() .. "/" .. depname:sub(2)
+ end
+ table.insert(deps, depname)
+ end
+ deps = table.unwrap(deps)
+ if deps and #deps > 0 then
+ instance:set("deps", deps)
+ end
+ for depname, extraconf in pairs(table.wrap(instance:extraconf("deps"))) do
+ if depname:startswith("@") and not depname:find("/", 1, true) then
+ depname = "@" .. opt.package:name() .. "/" .. depname:sub(2)
+ instance:extraconf_set("deps", depname, extraconf)
+ end
+ end
+ end
return instance
end