summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-04-21 00:28:41 +0800
committerruki <[email protected]>2021-04-21 00:28:41 +0800
commit072137dccbce50de95b938f4bb836310cb3081cb (patch)
treee1fb2825ec51c1886411d33610702e12c8c25820
parentb70fe375bb38b77e8e38b7139bc2f8cdda1dd95d (diff)
improve label for package
-rw-r--r--xmake/core/package/package.lua41
-rw-r--r--xmake/core/sandbox/modules/import/core/package/package.lua24
-rw-r--r--xmake/modules/private/action/require/impl/package.lua26
3 files changed, 48 insertions, 43 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 3decd832e..dad9b5cc2 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -48,11 +48,13 @@ local sandbox_os = require("sandbox/modules/os")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
-- new an instance
-function _instance.new(name, info, scriptdir)
+function _instance.new(name, info, opt)
+ opt = opt or {}
local instance = table.inherit(_instance)
- instance._NAME = name
- instance._INFO = info
- instance._SCRIPTDIR = scriptdir and path.absolute(scriptdir)
+ instance._NAME = name
+ instance._INFO = info
+ instance._REPO = opt.repo
+ instance._SCRIPTDIR = opt.scriptdir and path.absolute(opt.scriptdir)
return instance
end
@@ -828,6 +830,12 @@ function _instance:requireinfo_set(requireinfo)
self._REQUIREINFO = requireinfo
end
+-- get label
+function _instance:label()
+ local requireinfo = self:requireinfo()
+ return requireinfo and requireinfo.label
+end
+
-- get the display name
function _instance:displayname()
return self._DISPLAYNAME
@@ -885,6 +893,10 @@ function _instance:buildhash()
local function _get_buildhash(configs, opt)
opt = opt or {}
local str = self:plat() .. self:arch()
+ local label = self:label()
+ if label then
+ str = str .. label
+ end
if configs then
-- since luajit v2.1, the key order of the table is random and undefined.
-- We cannot directly deserialize the table, so the result may be different each time
@@ -1389,7 +1401,7 @@ end
-- has the given c++ funcs?
--
-- @param funcs the funcs
--- @param opt the argument options, e.g. { includes = ""}
+-- @param opt the argument options, e.g. {includes = ""}
--
-- @return true or false
--
@@ -1679,7 +1691,7 @@ function package.searchdirs()
end
-- load the package from the system directories
-function package.load_from_system(packagename)
+function package.load_from_system(packagename, opt)
-- get it directly from cache first
local instance = package._memcache():get2("packages", packagename)
@@ -1747,9 +1759,10 @@ function package.load_from_system(packagename)
end
-- load the package from the project file
-function package.load_from_project(packagename, project)
+function package.load_from_project(packagename, project, opt)
-- get it directly from cache first
+ opt = opt or {}
local instance = package._memcache():get2("packages", packagename)
if instance then
return instance
@@ -1780,9 +1793,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
@@ -1794,8 +1808,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
+ if packagedir then
scriptpath = path.join(packagedir, "xmake.lua")
end
if not scriptpath or not os.isfile(scriptpath) then
@@ -1820,7 +1834,7 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
-- get the package info
local packageinfo = nil
for _, info in pairs(results) do
- -- @note we cannot use the name of package(), because we need support `xxx~tag` for add_requires("zlib~xxx")
+ -- @note we cannot use the name of package() to index it, because we need support `xxx~tag` for add_requires("zlib~xxx")
-- so we use `xxx~tag` as the real package
packageinfo = info
break
@@ -1832,10 +1846,7 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
end
-- new an instance
- instance = _instance.new(packagename, packageinfo, path.directory(scriptpath))
-
- -- save repository
- instance._REPO = repo
+ instance = _instance.new(packagename, packageinfo, {scriptdir = path.directory(scriptpath), repo = repo})
-- save instance to the cache
package._memcache():set2("packages", instance)
diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua
index c08462c10..7f8bcc4fd 100644
--- a/xmake/core/sandbox/modules/import/core/package/package.lua
+++ b/xmake/core/sandbox/modules/import/core/package/package.lua
@@ -42,41 +42,29 @@ function sandbox_core_package_package.searchdirs()
end
-- load the package from the project file
-function sandbox_core_package_package.load_from_project(packagename)
-
- -- load package instance
- local instance, errors = package.load_from_project(packagename, project)
+function sandbox_core_package_package.load_from_project(packagename, opt)
+ local instance, errors = package.load_from_project(packagename, project, opt)
if errors then
raise(errors)
end
-
- -- ok
return instance
end
-- load the package from the system
-function sandbox_core_package_package.load_from_system(packagename)
-
- -- load package instance
- local instance, errors = package.load_from_system(packagename)
+function sandbox_core_package_package.load_from_system(packagename, opt)
+ local instance, errors = package.load_from_system(packagename, opt)
if errors then
raise(errors)
end
-
- -- ok
return instance
end
-- load the package from repositories
-function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, packagefile)
-
- -- load package instance
- 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
-
- -- ok
return instance
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 2915d3e78..9e8a3e1a2 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -177,20 +177,21 @@ function _load_require(require_str, requires_extra, parentinfo)
end
-- load package package from system
-function _load_package_from_system(packagename)
- return core_package.load_from_system(packagename)
+function _load_package_from_system(packagename, opt)
+ return core_package.load_from_system(packagename, opt)
end
-- load package package from project
-function _load_package_from_project(packagename)
- return core_package.load_from_project(packagename)
+function _load_package_from_project(packagename, opt)
+ return core_package.load_from_project(packagename, opt)
end
-- load package package from repositories
-function _load_package_from_repository(packagename, reponame)
- local packagedir, repo = repository.packagedir(packagename, reponame)
+function _load_package_from_repository(packagename, opt)
+ opt = opt or {}
+ local packagedir, repo = repository.packagedir(packagename, opt.reponame)
if packagedir then
- return core_package.load_from_repository(packagename, repo, packagedir)
+ return core_package.load_from_repository(packagename, repo, packagedir, opt)
end
end
@@ -360,7 +361,7 @@ function _init_requireinfo(requireinfo, package, opt)
end
requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or project.get("target.runtimes") or get_config("vs_runtime")
end
- if requireinfo.configs.vs_runtime == nil then
+ if requireinfo.configs.vs_runtime == nil and package:is_plat("windows") then
requireinfo.configs.vs_runtime = "MT"
end
end
@@ -454,6 +455,9 @@ function _get_packagekey(packagename, requireinfo, version)
if requireinfo.arch then
key = key .. "/" .. requireinfo.arch
end
+ if requireinfo.label then
+ key = key .. "/" .. requireinfo.label
+ end
local configs = requireinfo.configs
if configs then
local configs_order = {}
@@ -503,8 +507,10 @@ function _load_package(packagename, requireinfo, opt)
local displayname
if packagename:find('~', 1, true) then
displayname = packagename
- packagename = packagename:gsub("~.+$", "")
+ local splitinfo = packagename:split('~', {plain = true, limit = 2})
+ packagename = splitinfo[1]
requireinfo.alias = requireinfo.alias or displayname
+ requireinfo.label = splitinfo[2]
end
-- load package from project first
@@ -515,7 +521,7 @@ function _load_package(packagename, requireinfo, opt)
-- load package from repositories
if not package then
- package = _load_package_from_repository(packagename, requireinfo.reponame)
+ package = _load_package_from_repository(packagename, {reponame = requireinfo.reponame})
end
-- load package from system