summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-17 00:53:23 +0800
committerruki <[email protected]>2020-11-17 00:53:23 +0800
commitb0bb7321d5474c04becc4a1dab0502ad29203e73 (patch)
tree751a10fc577378e2e7c31d1fe18fca14dac1e44c
parent5126a44b24e0f3266e0f588308469225ff3d603d (diff)
improve vcpkg
-rw-r--r--xmake/modules/detect/sdks/find_vcpkgdir.lua112
-rw-r--r--xmake/modules/detect/tools/find_vcpkg.lua78
-rw-r--r--xmake/modules/detect/tools/find_zip.lua2
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua41
-rw-r--r--xmake/modules/package/manager/vcpkg/install_package.lua10
5 files changed, 120 insertions, 123 deletions
diff --git a/xmake/modules/detect/sdks/find_vcpkgdir.lua b/xmake/modules/detect/sdks/find_vcpkgdir.lua
deleted file mode 100644
index 8df048f25..000000000
--- a/xmake/modules/detect/sdks/find_vcpkgdir.lua
+++ /dev/null
@@ -1,112 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-2020, TBOOX Open Source Group.
---
--- @author ruki
--- @file find_vcpkgdir.lua
---
-
--- imports
-import("lib.detect.cache")
-import("lib.detect.find_file")
-import("core.base.option")
-import("core.base.global")
-import("core.project.config")
-
--- find vcpkg directory
-function _find_vcpkgdir(sdkdir)
-
- -- init the search directories
- local paths = {}
- if sdkdir then
- table.insert(paths, sdkdir)
- end
- if is_host("windows") then
- -- attempt to read path info after running `vcpkg integrate install`
- local pathfile = "~/../Local/vcpkg/vcpkg.path.txt"
- if os.isfile(pathfile) then
- local dir = io.readfile(pathfile):trim()
- if os.isdir(dir) then
- table.insert(paths, dir)
- end
- end
- end
-
- -- attempt to find it from the $PATH
- local pathenv = os.getenv("PATH")
- if pathenv then
- for _, p in ipairs(path.splitenv(pathenv)) do
- if p:find(string.ipattern("[\\/]vcpkg")) and os.isdir(p) then
- table.insert(paths, p)
- end
- end
- end
-
- -- attempt to find vcpkg
- local vcpkg = find_file(is_host("windows") and "vcpkg.exe" or "vcpkg", paths)
- if vcpkg then
- return path.directory(vcpkg)
- end
-end
-
--- find vcpkg directory
---
--- @param sdkdir the vcpkg directory
--- @param opt the argument options, e.g. {verbose = true, force = false}
---
--- @return the vcpkg directory
---
--- @code
---
--- local vcpkgdir = find_vcpkgdir()
---
--- @endcode
---
-function main(sdkdir, opt)
-
- -- init arguments
- opt = opt or {}
-
- -- attempt to load cache first
- local key = "detect.sdks.find_vcpkgdir." .. (sdkdir or "")
- local cacheinfo = cache.load(key)
- if not opt.force and cacheinfo.vcpkg ~= nil then
- return cacheinfo.vcpkg
- end
-
- -- find vcpkg
- local vcpkg = _find_vcpkgdir(sdkdir or config.get("vcpkg") or global.get("vcpkg"))
- if vcpkg then
-
- -- save to config
- config.set("vcpkg", vcpkg, {force = true, readonly = true})
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for vcpkg directory ... ${color.success}%s", vcpkg)
- end
- else
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for vcpkg directory ... ${color.nothing}${text.nothing}")
- end
- end
-
- -- save to cache
- cacheinfo.vcpkg = vcpkg or false
- cache.save(key, cacheinfo)
- return vcpkg
-end
diff --git a/xmake/modules/detect/tools/find_vcpkg.lua b/xmake/modules/detect/tools/find_vcpkg.lua
new file mode 100644
index 000000000..5c7e21370
--- /dev/null
+++ b/xmake/modules/detect/tools/find_vcpkg.lua
@@ -0,0 +1,78 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_vcpkg.lua
+--
+
+-- imports
+import("lib.detect.find_file")
+import("lib.detect.find_program")
+import("core.base.global")
+import("core.project.config")
+
+-- find vcpkg
+--
+-- @param opt the argument options, e.g. {version = true}
+--
+-- @return program, version
+--
+-- @code
+--
+-- local vcpkg = find_vcpkg()
+-- local vcpkg, version = find_vcpkg({version = true})
+--
+-- @endcode
+--
+function main(opt)
+
+ -- init options
+ opt = opt or {}
+ opt.check = opt.check or "version"
+ opt.command = opt.command or "version"
+
+ -- init the search directories
+ local paths = {}
+ local vcpkg = config.get("vcpkg") or global.get("vcpkg")
+ if vcpkg then
+ if os.isfile(vcpkg) then
+ vcpkg = path.directory(vcpkg)
+ end
+ table.insert(paths, vcpkg)
+ end
+ if is_host("windows") then
+ -- attempt to read path info after running `vcpkg integrate install`
+ local pathfile = "~/../Local/vcpkg/vcpkg.path.txt"
+ if os.isfile(pathfile) then
+ local dir = io.readfile(pathfile):trim()
+ if os.isdir(dir) then
+ table.insert(paths, dir)
+ end
+ end
+ end
+
+ -- find program
+ opt.paths = paths
+ opt.envs = {PATH = os.getenv("PATH")}
+ local program = find_program(opt.program or "version", opt)
+
+ -- find program version
+ local version = nil
+ if program and opt and opt.version then
+ version = find_programver(program, opt)
+ end
+ return program, version
+end
diff --git a/xmake/modules/detect/tools/find_zip.lua b/xmake/modules/detect/tools/find_zip.lua
index ec4dbf5ee..4d77c8715 100644
--- a/xmake/modules/detect/tools/find_zip.lua
+++ b/xmake/modules/detect/tools/find_zip.lua
@@ -50,7 +50,5 @@ function main(opt)
if program and opt and opt.version then
version = find_programver(program, opt)
end
-
- -- ok?
return program, version
end
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index fecf9e3c3..ff9ac3485 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -21,19 +21,52 @@
-- imports
import("lib.detect.find_file")
import("lib.detect.find_library")
-import("detect.sdks.find_vcpkgdir")
+import("lib.detect.find_tool")
import("core.project.config")
import("core.project.target")
--- find package from the brew package manager
+-- find vcpkg root directory
+function _find_vcpkgdir()
+ local vcpkgdir = _g.vcpkgdir
+ if vcpkgdir == nil then
+ local vcpkg = find_tool("vcpkg")
+ if vcpkg then
+ local dir = path.directory(vcpkg.program)
+ if os.isdir(path.join(dir, "installed")) then
+ vcpkgdir = dir
+ elseif is_host("macosx", "linux") then
+ local brew = find_tool("brew")
+ if brew then
+ dir = try
+ {
+ function ()
+ return os.iorunv(brew.program, {"--prefix", "vcpkg"})
+ end
+ }
+ end
+ if dir then
+ dir = path.join(dir:trim(), "libexec")
+ if os.isdir(path.join(dir, "installed")) then
+ vcpkgdir = dir
+ end
+ end
+
+ end
+ end
+ _g.vcpkgdir = vcpkgdir or false
+ end
+ return vcpkgdir or nil
+end
+
+-- find package from the vcpkg package manager
--
-- @param name the package name, e.g. zlib, pcre
-- @param opt the options, e.g. {verbose = true, version = "1.12.x")
--
function main(name, opt)
- -- attempt to find the vcpkg root directory
- local vcpkgdir = find_vcpkgdir(opt.vcpkgdir)
+ -- attempt to find vcpkg directory
+ local vcpkgdir = _find_vcpkgdir()
if not vcpkgdir then
return
end
diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua
index d04602a25..35c77b4b9 100644
--- a/xmake/modules/package/manager/vcpkg/install_package.lua
+++ b/xmake/modules/package/manager/vcpkg/install_package.lua
@@ -20,7 +20,7 @@
-- imports
import("core.base.option")
-import("detect.sdks.find_vcpkgdir")
+import("lib.detect.find_tool")
-- install package
--
@@ -31,9 +31,9 @@ import("detect.sdks.find_vcpkgdir")
--
function main(name, opt)
- -- attempt to find the vcpkg root directory
- local vcpkgdir = find_vcpkgdir(opt.vcpkgdir)
- if not vcpkgdir then
+ -- attempt to find vcpkg
+ local vcpkg = find_tool("vcpkg")
+ if not vcpkg then
raise("vcpkg not found!")
end
@@ -64,5 +64,5 @@ function main(name, opt)
end
-- install package
- os.vrunv(path.join(vcpkgdir, "vcpkg"), argv)
+ os.vrunv(vcpkg.program, argv)
end