summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-09-23 22:37:51 +0800
committerruki <[email protected]>2022-09-23 22:37:51 +0800
commit58c3481877ba5dea65715cb3aaf255d68f31ad2e (patch)
tree62a948862ad316a6df6857261be038c55667a1ee
parent766f61852a6665a6c180baf37518f7ea988e48e3 (diff)
add trybuild/xrepo
-rw-r--r--xmake/actions/build/main.lua2
-rw-r--r--xmake/modules/private/action/require/impl/search_packages.lua2
-rw-r--r--xmake/modules/private/action/trybuild/xrepo.lua113
3 files changed, 114 insertions, 3 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 9e05f6948..5a36e0960 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -60,7 +60,7 @@ function _try_build()
raise("unknown build tool: %s", trybuild)
end
else
- for _, name in ipairs({"autoconf", "cmake", "meson", "scons", "bazel", "msbuild", "xcodebuild", "make", "ninja", "ndkbuild"}) do
+ for _, name in ipairs({"xrepo", "autoconf", "cmake", "meson", "scons", "bazel", "msbuild", "xcodebuild", "make", "ninja", "ndkbuild"}) do
tool = import("private.action.trybuild." .. name, {anonymous = true})
configfile = tool.detect()
if configfile then
diff --git a/xmake/modules/private/action/require/impl/search_packages.lua b/xmake/modules/private/action/require/impl/search_packages.lua
index 276747db4..aea1783ae 100644
--- a/xmake/modules/private/action/require/impl/search_packages.lua
+++ b/xmake/modules/private/action/require/impl/search_packages.lua
@@ -41,8 +41,6 @@ end
-- search packages
function main(names)
-
- -- search all names
local results = {}
for _, name in ipairs(names) do
local packages = _search_packages(name)
diff --git a/xmake/modules/private/action/trybuild/xrepo.lua b/xmake/modules/private/action/trybuild/xrepo.lua
new file mode 100644
index 000000000..0005ce1f0
--- /dev/null
+++ b/xmake/modules/private/action/trybuild/xrepo.lua
@@ -0,0 +1,113 @@
+--!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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xrepo.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.semver")
+import("core.project.config")
+import("lib.detect.find_file")
+import("lib.detect.find_tool")
+import("private.action.require.impl.search_packages")
+
+-- get build directory
+function _get_buildir()
+ return config.buildir() or "build"
+end
+
+-- get artifacts directory
+function _get_artifacts_dir()
+ return path.absolute(path.join(_get_buildir(), "artifacts"))
+end
+
+-- detect build-system and configuration file
+function detect()
+
+ -- we need xrepo
+ local xrepo = find_tool("xrepo")
+ if not xrepo then
+ return
+ end
+
+ -- get package name and version
+ local dirname = path.filename(os.curdir())
+ local packagename = dirname
+ local version = semver.match(dirname)
+ if version then
+ local pos = dirname:find(version:rawstr(), 1, true)
+ if pos then
+ packagename = dirname:sub(1, pos - 1)
+ if packagename:endswith("-") or packagename:endswith("_") then
+ packagename = packagename:sub(1, #packagename - 1)
+ end
+ end
+ end
+ packagename = packagename:trim()
+ if #packagename == 0 then
+ return
+ end
+
+ -- search packages
+ -- TODO search the given version
+ local result
+ for name, packages in pairs(search_packages(packagename)) do
+ if #packages > 0 then
+ local package = packages[1]
+ _g.package = package
+ return ("%s %s in %s"):format(package.name, package.version, package.reponame)
+ end
+ end
+end
+
+-- do clean
+function clean()
+end
+
+-- do build
+function build()
+
+ -- get xrepo
+ local xrepo = assert(find_tool("xrepo"), "xrepo not found!")
+
+ -- get package info
+ local package = assert(_g.package, "package not found!")
+
+ -- do install for building
+ local argv = {"install", "-v"}
+ if option.get("diagnosis") then
+ table.insert(argv, "-D")
+ end
+ table.insert(argv, "-d")
+ table.insert(argv, ".")
+ table.insert(argv, package.name .. " " .. package.version)
+ os.vexecv(xrepo.program, argv)
+
+ -- do export
+ local artifacts_dir = _get_artifacts_dir()
+ local argv = {"export", "-v", "--shallow"}
+ if option.get("diagnosis") then
+ table.insert(argv, "-D")
+ end
+ table.insert(argv, "-o")
+ table.insert(argv, artifacts_dir)
+ table.insert(argv, package.name .. " " .. package.version)
+ os.vexecv(xrepo.program, argv)
+ cprint("output to ${bright}%s", artifacts_dir)
+ cprint("${color.success}build ok!")
+end