From 7f4308b2b0fa1df7b8d4f387455eda9ebb5947c0 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 31 Jan 2021 21:38:04 +0800 Subject: improve brew.find_package and fix localcache --- xmake/core/cache/localcache.lua | 16 ++++++++++------ xmake/modules/package/manager/brew/find_package.lua | 11 ++++++++++- 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) -- cgit v1.3.1