diff options
| author | ruki <[email protected]> | 2018-12-02 21:42:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-02 21:42:40 +0800 |
| commit | a0005982fa5e99c6c910ab7f5602f7b9809993c2 (patch) | |
| tree | 7157868111b3ceace52c066cb663c28bb48fc809 | |
| parent | 47b2b81350a97f8434403df141102bcf5b2bb148 (diff) | |
improve to switch debug mode for packages
| -rw-r--r-- | xmake/core/package/package.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 42 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 21 |
3 files changed, 33 insertions, 37 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 47f7eb718..e06bdf3be 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -572,6 +572,7 @@ function _instance:fetch(opt) -- and add cache key to make a distinction with finding system package if not fetchinfo and system ~= true then fetchinfo = self._find_package(self:name(), {prefixdirs = self:prefixdir(), + mode = self:debug() and "debug" or nil, system = false, global = self:from("local") and false or nil, version = require_ver, @@ -582,7 +583,11 @@ function _instance:fetch(opt) -- fetch it from the system directories if not fetchinfo and system ~= false then - fetchinfo = self._find_package(self:name(), {force = opt.force, version = require_ver, cachekey = "fetch:system", system = true}) + fetchinfo = self._find_package(self:name(), {force = opt.force, + version = require_ver, + cachekey = "fetch:system", + mode = self:debug() and "debug" or nil, + system = true}) if fetchinfo then fetchfrom = "system" end end end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index 3b7446442..9ff067a06 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -72,9 +72,9 @@ function sandbox_lib_detect_find_package._find_from_packagedirs(name, opt) -- init maps local maps = { - arch = opt.arch - , plat = opt.plat - , mode = opt.mode + arch = opt.arch + , plat = opt.plat + , mode = opt.mode or config.get("mode") } -- get variable @@ -141,36 +141,20 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) 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 - if opt.mode then - table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, opt.mode)) - end - table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, "release")) - table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, "debug")) + table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, opt.mode or "release")) if opt.global ~= false then - if opt.mode then - table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, opt.mode)) - end - table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, "release")) - table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, "debug")) + table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, opt.mode or "release")) end 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, "*") - if opt.mode then - table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, opt.mode, packagepath)) - end - table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, "release", packagepath)) - table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, "debug", packagepath)) + table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, opt.mode or "release", packagepath)) -- find the prefix info file from the global prefix directory if opt.global ~= false then - if opt.mode then - table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, opt.mode, packagepath)) - end - table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, "release", packagepath)) - table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, "debug", packagepath)) + table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, opt.mode or "release", packagepath)) end local prefixfile = find_file("info.txt", packagedirs) if not prefixfile then @@ -423,7 +407,7 @@ function sandbox_lib_detect_find_package._find(name, opt) table.insert(findscripts, sandbox_lib_detect_find_package._find_from_systemdirs) end end - + -- find it local result = nil for _, find in ipairs(findscripts) do @@ -476,10 +460,9 @@ end function sandbox_lib_detect_find_package.main(name, opt) -- init options - opt = opt or {} - opt.plat = opt.plat or config.get("plat") or os.host() - opt.arch = opt.arch or config.get("arch") or os.arch() - opt.mode = opt.mode or config.get("mode") + opt = opt or {} + opt.plat = opt.plat or config.get("plat") or os.host() + opt.arch = opt.arch or config.get("arch") or os.arch() -- init cache key local key = "find_package_" .. opt.plat .. "_" .. opt.arch @@ -489,6 +472,9 @@ function sandbox_lib_detect_find_package.main(name, opt) if opt.cachekey then key = key .. "_" .. opt.cachekey end + if opt.mode then + key = key .. "_" .. opt.mode + end -- attempt to get result from cache first local cacheinfo = cache.load(key) diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 1f18e15ef..7766b0dcd 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -69,22 +69,27 @@ function info(name, opt) os.addenv("PKG_CONFIG_PATH", unpack(configdirs)) end + -- only find debug package? clear the other pkg-config pathes + if opt.mode == "debug" then + os.setenv("PKG_CONFIG_PATH", nil) + end + -- attempt to get pkg-config path from `brew --prefix` if no flags local brewprefix = nil if not flags then -- find the config directories from the prefix directories of xmake local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch()) - os.addenv("PKG_CONFIG_PATH", path.join(config.directory(), "prefix", platsubdirs, "release", "lib", "pkgconfig")) - os.addenv("PKG_CONFIG_PATH", path.join(config.directory(), "prefix", platsubdirs, "debug", "lib", "pkgconfig")) - os.addenv("PKG_CONFIG_PATH", path.join(global.directory(), "prefix", platsubdirs, "release", "lib", "pkgconfig")) - os.addenv("PKG_CONFIG_PATH", path.join(global.directory(), "prefix", platsubdirs, "debug", "lib", "pkgconfig")) + os.addenv("PKG_CONFIG_PATH", path.join(config.directory(), "prefix", platsubdirs, opt.mode or "release", "lib", "pkgconfig")) + os.addenv("PKG_CONFIG_PATH", path.join(global.directory(), "prefix", platsubdirs, opt.mode or "release", "lib", "pkgconfig")) -- find the prefix directory of brew directly, because `brew --prefix name` is too slow! - local pcfile = find_file(name .. ".pc", "/usr/local/Cellar/" .. (opt.brewhint or name) .. "/*/lib/pkgconfig") - if pcfile then - brewprefix = path.directory(path.directory(path.directory(pcfile))) - os.addenv("PKG_CONFIG_PATH", path.directory(pcfile)) + if opt.mode ~= "debug" then + local pcfile = find_file(name .. ".pc", "/usr/local/Cellar/" .. (opt.brewhint or name) .. "/*/lib/pkgconfig") + if pcfile then + brewprefix = path.directory(path.directory(path.directory(pcfile))) + os.addenv("PKG_CONFIG_PATH", path.directory(pcfile)) + end end end |
