summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-02 12:35:14 +0800
committerGitHub <[email protected]>2023-03-02 12:35:14 +0800
commit5afbc8e9f237b3c782b75183c11ca5b2ed41e661 (patch)
treeaabe89d41d0dc5a316d000e29063d141a9120706 /xmake
parent415c4ad77003cd20d9f4edeb813fafb6dd31b3ba (diff)
parent6124bdc45b728effde95f96cf57aac7b21f0e20a (diff)
Merge pull request #3442 from xmake-io/package
improve plat/arch for package
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/package/package.lua29
-rw-r--r--xmake/core/sandbox/modules/import/core/package/package.lua4
-rw-r--r--xmake/modules/private/action/require/impl/package.lua9
3 files changed, 34 insertions, 8 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 28a130405..c0b60d289 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -2445,9 +2445,10 @@ function package.load_from_project(packagename, project)
end
-- load the package from the package directory or package description file
-function package.load_from_repository(packagename, repo, packagedir, packagefile)
+function package.load_from_repository(packagename, repo, packagedir, opt)
-- get it directly from cache first
+ opt = opt or {}
local instance = package._memcache():get2("packages", packagename)
if instance then
return instance
@@ -2459,8 +2460,8 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
end
-- find the package script path
- local scriptpath = packagefile
- if not packagefile and packagedir then
+ local scriptpath = opt.packagefile
+ if not opt.packagefile and packagedir then
scriptpath = path.join(packagedir, "xmake.lua")
end
if not scriptpath or not os.isfile(scriptpath) then
@@ -2470,6 +2471,20 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
-- get interpreter
local interp = package._interpreter()
+ -- we need modify plat/arch in description scope at same time
+ -- if plat/arch are passed to add_requires.
+ --
+ -- @see https://github.com/orgs/xmake-io/discussions/3439
+ --
+ -- e.g. add_requires("zlib~mingw", {plat = "mingw", arch = "x86_64"})
+ --
+ if opt.plat then
+ package._memcache():set("target_plat", opt.plat)
+ end
+ if opt.arch then
+ package._memcache():set("target_arch", opt.arch)
+ end
+
-- load script
local ok, errors = interp:load(scriptpath)
if not ok then
@@ -2491,6 +2506,14 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
-- new an instance
instance = _instance.new(packagename, packageinfo, {scriptdir = path.directory(scriptpath), repo = repo})
+ -- reset plat/arch
+ if opt.plat then
+ package._memcache():set("target_plat", nil)
+ end
+ if opt.arch then
+ package._memcache():set("target_arch", nil)
+ end
+
-- save instance to the cache
package._memcache():set2("packages", instance)
return instance
diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua
index f1ec8799f..906033fde 100644
--- a/xmake/core/sandbox/modules/import/core/package/package.lua
+++ b/xmake/core/sandbox/modules/import/core/package/package.lua
@@ -52,8 +52,8 @@ function sandbox_core_package_package.load_from_system(packagename)
end
-- load the package from repositories
-function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, packagefile)
- local instance, errors = package.load_from_repository(packagename, repo, packagedir, packagefile)
+function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, opt)
+ local instance, errors = package.load_from_repository(packagename, repo, packagedir, opt)
if not instance then
raise(errors)
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index f85a0095c..79801d675 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -167,7 +167,6 @@ function _load_require(require_str, requires_extra, parentinfo)
"verify", "external", "private", "build", "configs", "version")
for name, value in pairs(require_extra) do
if not extra_options:has(name) then
- print("not found")
wprint("add_requires(\"%s\") has unknown option: {%s=%s}!", require_str, name, tostring(value))
end
end
@@ -212,9 +211,10 @@ end
-- load package package from repositories
function _load_package_from_repository(packagename, opt)
+ opt = opt or {}
local packagedir, repo = repository.packagedir(packagename, opt)
if packagedir then
- return core_package.load_from_repository(packagename, repo, packagedir)
+ return core_package.load_from_repository(packagename, repo, packagedir, {plat = opt.plat, arch = opt.arch})
end
end
@@ -750,7 +750,10 @@ function _load_package(packagename, requireinfo, opt)
local from_repo = false
if not package then
package = _load_package_from_repository(packagename, {
- name = requireinfo.reponame, locked_repo = locked_requireinfo and locked_requireinfo.repo})
+ plat = requireinfo.plat,
+ arch = requireinfo.arch,
+ name = requireinfo.reponame,
+ locked_repo = locked_requireinfo and locked_requireinfo.repo})
if package then
from_repo = true
end