package An official xmake package repository https://xrepo.xmake.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.0 KiB

6 years ago
-- imports
import("core.base.option")
import("core.platform.platform")
import("packages", {alias = "get_packages"})
6 years ago
-- the options
local options =
{
{'v', "verbose", "k", nil, "Enable verbose information." }
, {'D', "diagnosis", "k", nil, "Enable diagnosis information." }
, {nil, "shallow", "k", nil, "Only install the root packages." }
, {'k', "kind", "kv", nil, "Enable static/shared library." }
, {'p', "plat", "kv", nil, "Set the given platform." }
, {'a', "arch", "kv", nil, "Set the given architecture." }
, {'m', "mode", "kv", nil, "Set the given mode." }
, {'j', "jobs", "kv", nil, "Set the build jobs." }
4 years ago
, {nil, "linkjobs", "kv", nil, "Set the link jobs." }
, {nil, "cflags", "kv", nil, "Set the cflags." }
, {nil, "cxxflags", "kv", nil, "Set the cxxflags." }
, {nil, "ldflags", "kv", nil, "Set the ldflags." }
, {nil, "ndk", "kv", nil, "Set the Android NDK directory." }
, {nil, "ndk_sdkver", "kv", nil, "Set the Android NDK platform sdk version." }
, {nil, "sdk", "kv", nil, "Set the SDK directory of cross toolchain." }
3 years ago
, {nil, "vs", "kv", nil, "Set the VS Compiler version." }
4 years ago
, {nil, "vs_sdkver", "kv", nil, "Set the Windows SDK version." }
3 years ago
, {nil, "vs_toolset", "kv", nil, "Set the Windows Toolset version." }
, {nil, "vs_runtime", "kv", nil, "Set the VS Runtime library." }
, {nil, "mingw", "kv", nil, "Set the MingW directory." }
4 years ago
, {nil, "toolchain", "kv", nil, "Set the toolchain name." }
, {nil, "packages", "vs", nil, "The package list." }
6 years ago
}
4 years ago
-- require packages
function _require_packages(argv, packages)
local config_argv = {"f", "-c"}
if argv.verbose then
table.insert(config_argv, "-v")
end
if argv.diagnosis then
table.insert(config_argv, "-D")
end
if argv.plat then
table.insert(config_argv, "--plat=" .. argv.plat)
end
if argv.arch then
table.insert(config_argv, "--arch=" .. argv.arch)
end
if argv.mode then
table.insert(config_argv, "--mode=" .. argv.mode)
end
if argv.ndk then
table.insert(config_argv, "--ndk=" .. argv.ndk)
end
if argv.sdk then
table.insert(config_argv, "--sdk=" .. argv.sdk)
end
if argv.ndk_sdkver then
table.insert(config_argv, "--ndk_sdkver=" .. argv.ndk_sdkver)
end
3 years ago
if argv.vs then
table.insert(config_argv, "--vs=" .. argv.vs)
end
4 years ago
if argv.vs_sdkver then
table.insert(config_argv, "--vs_sdkver=" .. argv.vs_sdkver)
end
3 years ago
if argv.vs_toolset then
table.insert(config_argv, "--vs_toolset=" .. argv.vs_toolset)
end
if argv.vs_runtime then
table.insert(config_argv, "--vs_runtime=" .. argv.vs_runtime)
end
if argv.mingw then
table.insert(config_argv, "--mingw=" .. argv.mingw)
end
4 years ago
if argv.toolchain then
table.insert(config_argv, "--toolchain=" .. argv.toolchain)
end
if argv.cflags then
table.insert(config_argv, "--cflags=" .. argv.cflags)
end
if argv.cxxflags then
table.insert(config_argv, "--cxxflags=" .. argv.cxxflags)
end
if argv.ldflags then
table.insert(config_argv, "--ldflags=" .. argv.ldflags)
end
5 years ago
os.vexecv("xmake", config_argv)
4 years ago
local require_argv = {"require", "-f", "-y", "--build"}
if argv.verbose then
table.insert(require_argv, "-v")
end
if argv.diagnosis then
table.insert(require_argv, "-D")
end
if argv.shallow then
table.insert(require_argv, "--shallow")
end
if argv.jobs then
table.insert(require_argv, "--jobs=" .. argv.jobs)
end
4 years ago
if argv.linkjobs then
table.insert(require_argv, "--linkjobs=" .. argv.linkjobs)
end
4 years ago
if argv.mode == "debug" and argv.kind == "shared" then
table.insert(require_argv, "--extra={debug=true,configs={shared=true}}")
elseif argv.mode == "debug" then
table.insert(require_argv, "--extra={debug=true}")
4 years ago
elseif argv.kind == "shared" then
table.insert(require_argv, "--extra={configs={shared=true}}")
end
table.join2(require_argv, packages)
5 years ago
os.vexecv("xmake", require_argv)
end
-- the given package is supported?
function _package_is_supported(argv, packagename)
local packages = get_packages()
if packages then
local plat = argv.plat or os.subhost()
local packages_plat = packages[plat]
for _, package in ipairs(packages_plat) do
if package and packagename:split("%s+")[1] == package.name then
local arch = argv.arch
if not arch and plat ~= os.subhost() then
arch = platform.archs(plat)[1]
end
if not arch then
arch = os.subarch()
end
for _, package_arch in ipairs(package.archs) do
if arch == package_arch then
return true
end
end
end
end
end
end
6 years ago
-- the main entry
6 years ago
function main(...)
6 years ago
-- parse arguments
local argv = option.parse({...}, options, "Test all the given or changed packages.")
-- get packages
6 years ago
local packages = argv.packages or {}
6 years ago
if #packages == 0 then
local files = os.iorun("git diff --name-only HEAD^")
for _, file in ipairs(files:split('\n'), string.trim) do
if file:find("packages", 1, true) and path.filename(file) == "xmake.lua" then
assert(file == file:lower(), "%s must be lower case!", file)
6 years ago
local package = path.filename(path.directory(file))
table.insert(packages, package)
end
end
end
6 years ago
if #packages == 0 then
6 years ago
table.insert(packages, "tbox dev")
6 years ago
end
-- remove unsupported packages
for idx, package in irpairs(packages) do
assert(package == package:lower(), "package(%s) must be lower case!", package)
if not _package_is_supported(argv, package) then
table.remove(packages, idx)
end
end
if #packages == 0 then
print("no testable packages on %s!", argv.plat or os.subhost())
4 years ago
return
end
-- prepare test project
6 years ago
local repodir = os.curdir()
local workdir = path.join(os.tmpdir(), "xmake-repo")
print(packages)
6 years ago
os.setenv("XMAKE_STATS", "false")
6 years ago
os.tryrm(workdir)
os.mkdir(workdir)
os.cd(workdir)
os.exec("xmake create test")
os.cd("test")
6 years ago
print(os.curdir())
6 years ago
os.exec("xmake repo --add local-repo %s", repodir)
os.exec("xmake repo -l")
-- require packages
_require_packages(argv, packages)
--[[for _, package in ipairs(packages) do
4 years ago
_require_packages(argv, package)
end]]
6 years ago
end