summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-31 21:38:04 +0800
committerruki <[email protected]>2021-01-31 21:38:16 +0800
commit7f4308b2b0fa1df7b8d4f387455eda9ebb5947c0 (patch)
tree0e12a64871d23c643fc8be7ce890fbbd5c6c848d
parente1589ecac2413cc3ae13ad7d71e01b6831e64576 (diff)
improve brew.find_package and fix localcache
-rw-r--r--xmake/core/cache/localcache.lua16
-rw-r--r--xmake/modules/package/manager/brew/find_package.lua11
2 files changed, 20 insertions, 7 deletions
diff --git a/xmake/core/cache/localcache.lua b/xmake/core/cache/localcache.lua
index 3fd5d040f..c40fe9ba9 100644
--- a/xmake/core/cache/localcache.lua
+++ b/xmake/core/cache/localcache.lua
@@ -50,17 +50,21 @@ end
-- load cache
function _instance:load()
- local result = io.load(path.join(config.cachedir(), self:name()))
- if result ~= nil then
- self._DATA = result
+ if os.isfile(os.projectfile()) then
+ local result = io.load(path.join(config.cachedir(), self:name()))
+ if result ~= nil then
+ self._DATA = result
+ end
end
end
-- save cache
function _instance:save()
- local ok, errors = io.save(path.join(config.cachedir(), self:name()), self._DATA)
- if not ok then
- os.raise(errors)
+ if os.isfile(os.projectfile()) then
+ local ok, errors = io.save(path.join(config.cachedir(), self:name()), self._DATA)
+ if not ok then
+ os.raise(errors)
+ end
end
end
diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua
index 1fa9d6978..df0737a06 100644
--- a/xmake/modules/package/manager/brew/find_package.lua
+++ b/xmake/modules/package/manager/brew/find_package.lua
@@ -65,9 +65,18 @@ function main(name, opt)
local nameinfo = name:split('/')
local pcname = nameinfo[2] or nameinfo[1]
- -- find package from pkg-config/*.pc
+ -- find package from pkg-config/*.pc, attempt to find it from `brew --prefix`/package first
local result = nil
local pcfile = find_file(pcname .. ".pc", path.join(brew_pkg_rootdir, nameinfo[1], "*/lib/pkgconfig"))
+ if not pcfile then
+ -- attempt to find it from `brew --prefix package`
+ local brew = find_tool("brew")
+ local brew_pkgdir = brew and try {function () return os.iorunv(brew.program, {"--prefix", nameinfo[1]}) end}
+ if brew_pkgdir then
+ brew_pkgdir = brew_pkgdir:trim()
+ pcfile = find_file(pcname .. ".pc", path.join(brew_pkgdir, "lib/pkgconfig"))
+ end
+ end
if pcfile then
opt.configdirs = path.directory(pcfile)
result = find_package("pkg_config::" .. pcname, opt)