Initial commit

This commit is contained in:
SweetId 2023-10-20 20:23:23 -04:00
commit 498a03c1f3
7 changed files with 366 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 NazaraEngine
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# xmake-repo
XMake-repo containing latest Nazara Localization packages for xmake, for testing before integration on https://github.com/xmake-io/xmake-repo

View File

@ -0,0 +1,18 @@
package("nazaralocalization")
set_kind("library")
set_homepage("https://github.com/NazaraEngine")
set_description("Localization package for Nazara projects")
set_license("MIT")
add_urls("https://github.com/SweetId/NazaraLocalization.git")
add_versions("2023.10.20", "0b747c4d0a34df82b93717f129512da2e0936d89")
add_deps("nazaraengine")
add_deps("fmt")
on_install(function (package)
import("package.tools.xmake").install(package)
end)

14
scripts/list.lua Normal file
View File

@ -0,0 +1,14 @@
import("packages")
function main(...)
for plat, pkgs in pairs(packages()) do
cprint("${magenta}%s${clear}:", plat)
for _, pkg in ipairs(pkgs) do
if pkg.generic then
cprint(" ${yellow}->${clear} %s", pkg.name)
else
cprint(" ${yellow}->${clear} %s (%s)", pkg.name, table.concat(pkg.archs, ", "))
end
end
end
end

95
scripts/packages.lua Normal file
View File

@ -0,0 +1,95 @@
-- imports
import("core.package.package")
import("core.platform.platform")
-- is supported platform and architecture?
function is_supported(instance, plat, arch, opt)
-- ignore template package
if instance.is_template and instance:is_template() then
return false
end
-- get script
local script = instance:get("install")
local result = nil
if type(script) == "function" then
result = script
elseif type(script) == "table" then
-- get plat and arch
local plat = plat or ""
local arch = arch or ""
-- match pattern
--
-- `@linux`
-- `@linux|x86_64`
-- `@macosx,linux`
-- `android@macosx,linux`
-- `android|armeabi-v7a@macosx,linux`
-- `android|armeabi-v7a@macosx,linux|x86_64`
-- `android|armeabi-v7a@linux|x86_64`
--
for _pattern, _script in pairs(script) do
local hosts = {}
local hosts_spec = false
_pattern = _pattern:gsub("@(.+)", function (v)
for _, host in ipairs(v:split(',')) do
hosts[host] = true
hosts_spec = true
end
return ""
end)
if _pattern:trim() == "" and opt and opt.onlyhost then
_pattern = os.subhost()
end
if not _pattern:startswith("__") and (not hosts_spec or hosts[os.subhost() .. '|' .. os.subarch()] or hosts[os.subhost()])
and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
result = _script
break
end
end
-- get generic script
result = result or script["__generic__"]
end
return result
end
-- the main entry
function main(opt)
local packages = {}
for _, packagedir in ipairs(os.dirs(path.join("packages", "*", "*"))) do
local packagename = path.filename(packagedir)
local packagefile = path.join(packagedir, "xmake.lua")
local instance = package.load_from_repository(packagename, nil, packagedir, packagefile)
local basename = instance:get("base")
if instance and basename then
local basedir = path.join("packages", basename:sub(1, 1):lower(), basename:lower())
local basefile = path.join(basedir, "xmake.lua")
instance._BASE = package.load_from_repository(basename, nil, basedir, basefile)
end
if instance then
for _, plat in ipairs({"windows", "linux", "macosx", "iphoneos", "android", "mingw", "msys", "bsd", "wasm", "cross"}) do
local archs = platform.archs(plat)
if archs then
local package_archs = {}
for _, arch in ipairs(archs) do
if is_supported(instance, plat, arch, opt) then
table.insert(package_archs, arch)
end
end
if #package_archs > 0 then
packages[plat] = packages[plat] or {}
table.insert(packages[plat], {name = instance:name(), instance = instance, archs = package_archs, generic = #package_archs == #archs})
end
end
end
end
end
for _, packages_plat in pairs(packages) do
table.sort(packages_plat, function(a, b) return a.name < b.name end)
end
return packages
end

209
scripts/test.lua Normal file
View File

@ -0,0 +1,209 @@
-- imports
import("core.base.option")
import("core.platform.platform")
import("packages", {alias = "get_packages"})
-- 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." }
, {'f', "configs", "kv", nil, "Set the configs." }
, {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." }
, {nil, "vs", "kv", nil, "Set the VS Compiler version." }
, {nil, "vs_sdkver", "kv", nil, "Set the Windows SDK version." }
, {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." }
, {nil, "toolchain", "kv", nil, "Set the toolchain name." }
, {nil, "packages", "vs", nil, "The package list." }
}
-- 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
if argv.vs then
table.insert(config_argv, "--vs=" .. argv.vs)
end
if argv.vs_sdkver then
table.insert(config_argv, "--vs_sdkver=" .. argv.vs_sdkver)
end
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
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
os.vexecv("xmake", config_argv)
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
if argv.linkjobs then
table.insert(require_argv, "--linkjobs=" .. argv.linkjobs)
end
local extra = {}
if argv.mode == "debug" then
extra.debug = true
end
if argv.kind == "shared" then
extra.configs = extra.configs or {}
extra.configs.shared = true
end
local configs = argv.configs
if configs then
extra.system = false
extra.configs = extra.configs or {}
local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
if extra_configs then
table.join2(extra.configs, extra_configs)
else
raise(errors)
end
end
local extra_str = string.serialize(extra, {indent = false, strip = true})
table.insert(require_argv, "--extra=" .. extra_str)
table.join2(require_argv, packages)
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 = table.wrap(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
-- the main entry
function main(...)
-- parse arguments
local argv = option.parse({...}, options, "Test all the given or changed packages.")
-- get packages
local packages = argv.packages or {}
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)
local package = path.filename(path.directory(file))
table.insert(packages, package)
end
end
end
if #packages == 0 then
table.insert(packages, "tbox dev")
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())
return
end
-- prepare test project
local repodir = os.curdir()
local workdir = path.join(os.tmpdir(), "xmake-repo")
print(packages)
os.setenv("XMAKE_STATS", "false")
os.tryrm(workdir)
os.mkdir(workdir)
os.cd(workdir)
os.exec("xmake create test")
os.cd("test")
print(os.curdir())
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
_require_packages(argv, package)
end]]
end

7
xmake.lua Normal file
View File

@ -0,0 +1,7 @@
-- set xmake minimal version
set_xmakever("2.6.5")
-- set repository description
set_description("Nazara Localization xmake repository")