summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-29 22:34:11 +0800
committerruki <[email protected]>2019-01-29 09:25:07 +0800
commit2a8b05d146a9fd53aa5784e36dca45cbce2ce272 (patch)
treed2b942facef69e155e054fa808bdc4a256b0af01
parent25d080557a3667ebd49015728bfe860585be0ed8 (diff)
improve to find_package
-rw-r--r--xmake/core/package/package.lua59
-rw-r--r--xmake/modules/package/manager/conan/find_package.lua27
-rw-r--r--xmake/modules/package/manager/conan/install_package.lua4
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua9
4 files changed, 64 insertions, 35 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index f9b935cd6..6c9bb0f92 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -56,20 +56,6 @@ function _instance.new(name, info)
return instance
end
--- get the build mode
-function _instance:_buildmode()
- if self._BUILDMODE == nil then
- local buildmode = self:debug() and "debug" or "release"
- local configs = self:configs()
- if configs then
- self._BUILDMODE = buildmode .. "_" .. hash.uuid(string.serialize(configs, true)):split('-')[1]:lower()
- else
- self._BUILDMODE = buildmode
- end
- end
- return self._BUILDMODE
-end
-
-- get the package configure
function _instance:get(name)
@@ -108,6 +94,11 @@ function _instance:arch()
return config.get("arch") or os.arch()
end
+-- get the build mode
+function _instance:mode()
+ return self:debug() and "debug" or "release"
+end
+
-- get the repository of this package
function _instance:repo()
return self._REPO
@@ -234,7 +225,7 @@ end
function _instance:installdir(...)
-- make the given install directory
- local dir = path.join(package.installdir(self:_buildmode(), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), ...)
+ local dir = path.join(package.installdir(table.concat({self:mode(), self:configs_hash()}, '_'), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), ...)
-- ensure the install directory
if not os.isdir(dir) then
@@ -247,7 +238,7 @@ end
function _instance:prefixdir(...)
-- make the given prefix directory
- local dir = path.join(package.prefixdir(self:from("global"), self:_buildmode(), self:plat(), self:arch()), ...)
+ local dir = path.join(package.prefixdir(self:from("global"), table.concat({self:mode(), self:configs_hash()}, '_'), self:plat(), self:arch()), ...)
-- ensure the prefix directory
if not os.isdir(dir) then
@@ -267,7 +258,7 @@ end
-- get the prefix info file
function _instance:prefixfile()
- return path.join(package.prefixinfodir(self:from("global"), self:_buildmode(), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), "info.txt")
+ return path.join(package.prefixinfodir(self:from("global"), table.concat({self:mode(), self:configs_hash()}, '_'), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), "info.txt")
end
-- get prefix variables
@@ -307,7 +298,7 @@ function _instance:register()
-- register the environment variables
for name, values in pairs(table.wrap(self:prefixinfo().envars)) do
- package.addenv(self:from("global"), self:_buildmode(), self:plat(), self:arch(), name, values)
+ package.addenv(self:from("global"), table.concat({self:mode(), self:configs_hash()}, '_'), self:plat(), self:arch(), name, values)
end
end
@@ -316,7 +307,7 @@ function _instance:unregister()
-- unregister the environment variables
for name, values in pairs(table.wrap(self:prefixinfo().envars)) do
- package.delenv(self:from("global"), self:_buildmode(), self:plat(), self:arch(), name, values)
+ package.delenv(self:from("global"), table.concat({self:mode(), self:configs_hash()}, '_'), self:plat(), self:arch(), name, values)
end
end
@@ -442,6 +433,17 @@ function _instance:configs()
end
end
+-- get the hash of configs
+function _instance:configs_hash()
+ if self._CONFIGS_HASH == nil then
+ local configs = self:configs()
+ if configs then
+ self._CONFIGS_HASH = hash.uuid(string.serialize(configs, true)):split('-')[1]:lower()
+ end
+ end
+ return self._CONFIGS_HASH
+end
+
-- get the group name
function _instance:group()
local requireinfo = self:requireinfo()
@@ -588,16 +590,14 @@ function _instance:fetch(opt)
-- false: only find local packages
local system = opt.system or self:requireinfo().system
- -- fetch it from the prefix directories first
- -- and add cache key to make a distinction with finding system package
+ -- only fetch it from the xmake repository first
if not fetchinfo and system ~= true and not self:from("system") then
- fetchinfo = self._find_package(self:name(), {prefixdirs = self:prefixdir(),
- mode = self:_buildmode(),
- system = false,
- islocal = self:from("local"),
- version = require_ver,
- cachekey = "fetch:prefix",
- force = opt.force or self:from("local")})
+ fetchinfo = self._find_package("xmake::" .. self:name(), {prefixdirs = self:prefixdir(),
+ mode = self:mode(),
+ islocal = self:from("local"),
+ version = require_ver,
+ configs_hash = self:configs_hash(),
+ force = opt.force or self:from("local")})
if fetchinfo then fetchfrom = self._FROMKIND end
end
@@ -605,8 +605,7 @@ function _instance:fetch(opt)
if not fetchinfo and system ~= false then
fetchinfo = self._find_package(self:name(), {force = opt.force,
version = require_ver,
- cachekey = "fetch:system",
- mode = self:_buildmode(),
+ mode = self:mode(),
system = true})
if fetchinfo then fetchfrom = "system" end
end
diff --git a/xmake/modules/package/manager/conan/find_package.lua b/xmake/modules/package/manager/conan/find_package.lua
index bc386d50a..ca39a2f12 100644
--- a/xmake/modules/package/manager/conan/find_package.lua
+++ b/xmake/modules/package/manager/conan/find_package.lua
@@ -24,6 +24,12 @@
-- imports
import("core.base.option")
+import("core.project.config")
+
+-- get build info file
+function _get_buildinfo_file(name)
+ return path.absolute(path.join(config.buildir() or os.tmpdir(), ".conan", name, "conanbuildinfo.xmake.lua"))
+end
-- find package using the conan package manager
--
@@ -32,4 +38,25 @@ import("core.base.option")
--
function main(name, opt)
+ -- get the build info
+ local buildinfo_file = _get_buildinfo_file(name)
+ if not os.isfile(buildinfo_file) then
+ return
+ end
+
+ -- load build info
+ local buildinfo = io.load(buildinfo_file)
+
+ -- get the package info of the given platform, architecture and mode
+ local found = false
+ local result = {}
+ for k, v in pairs(buildinfo[opt.plat .. "_" .. opt.arch .. "_" .. opt.mode]) do
+ if #table.wrap(v) > 0 then
+ result[k] = v
+ found = true
+ end
+ end
+ if found then
+ return result
+ end
end
diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua
index d1db99998..3d7af9078 100644
--- a/xmake/modules/package/manager/conan/install_package.lua
+++ b/xmake/modules/package/manager/conan/install_package.lua
@@ -29,14 +29,14 @@ import("lib.detect.find_tool")
-- get build directory
function _get_build_directory(name)
- return path.join(config.buildir() or os.tmpdir(), ".conan", name)
+ return path.absolute(path.join(config.buildir() or os.tmpdir(), ".conan", name))
end
-- generate conanfile.txt
function _generate_conanfile(name, opt)
-- trace
- dprint("generate conanfile.txt ..")
+ dprint("generate %s ..", path.join(_get_build_directory(name), "conanfile.txt"))
-- get conan options and imports
local options = table.wrap(opt.options)
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index dc0511476..f662a626f 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -35,17 +35,20 @@ import("lib.detect.find_library")
-- find package from the repository (maybe only include and no links)
function _find_package_from_repo(name, opt)
+ -- get build mode, e.g. debug_f7821231
+ local mode = table.concat({opt.mode or "release", opt.configs_hash}, '_')
+
-- get the prefix directories
local prefixdirs = table.wrap(opt.prefixdirs)
local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch())
if #prefixdirs == 0 then
- table.insert(prefixdirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", platsubdirs, opt.mode or "release"))
+ table.insert(prefixdirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", platsubdirs, mode))
end
-- find the prefix info file of package, .e.g prefix/info/z/zlib/1.2.11/info.txt
local packagedirs = {}
local packagepath = path.join(name:sub(1, 1), name, "*")
- table.insert(packagedirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", "info", platsubdirs, opt.mode or "release", packagepath))
+ table.insert(packagedirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", "info", platsubdirs, mode, packagepath))
local prefixfile = find_file("info.txt", packagedirs)
if not prefixfile then
return
@@ -256,7 +259,7 @@ end
-- find package using the xmake package manager
--
-- @param name the package name
--- @param opt the options, .e.g {verbose = true, version = "1.12.x")
+-- @param opt the options, .e.g {verbose = true, version = "1.12.x", configs_hash = "xxxxxx")
--
function main(name, opt)