Skip to content

Commit

Permalink
Add xmake ci --dump command (#564)
Browse files Browse the repository at this point in the history
* Add xmake ci --dump command

* Add ci task to the existing plugin category
  • Loading branch information
bitonality authored Jun 15, 2024
1 parent 2a436a6 commit e74956a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/xmakescripts/plugins/ci/dump/modes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import("core.project.project")
import("core.base.json")

function main()
local modes = {}
for _, mode in pairs(project.modes()) do
table.append(modes, mode)
end
local jsonString = json.encode(modes)
io.write(jsonString)
end
20 changes: 20 additions & 0 deletions tools/xmakescripts/plugins/ci/dump/targets.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import("core.project.config")
import("core.project.project")
import("core.base.json")
import("core.base.task")

function main()
project.lock()
-- Check to ensure that config has been run. This will not trample the existing config if it exists.
task.run("config", {yes=true}, {disable_dump = true})
project.load_targets()
project.unlock()

local targets = {}
for targetname, target in pairs(project.targets()) do
targets[targetname] = {target = target:targetfile(), symbol = target:symbolfile()}
end

local jsonString = json.encode(targets)
io.write(jsonString)
end
10 changes: 10 additions & 0 deletions tools/xmakescripts/plugins/ci/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import("core.base.option")

function main()
if option.get("dump") then
local module_name = string.format("dump.%s", string.lower(option.get("dump")))
assert(import(module_name, {try = true, anonymous = true}))()
else
raise("No options provided to the xmake ci command.")
end
end
13 changes: 13 additions & 0 deletions tools/xmakescripts/plugins/ci/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
task("ci")
set_category("plugin")
on_run("main")

set_menu {
usage = "xmake ci [options]",
description = "Pass build information to external tools.",
options =
{
{'d', "dump", "kv", nil, "Dump the specified information in JSON format.",
values = {"modes", "targets"} }
}
}
3 changes: 3 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set_config("buildir", "Intermediates")
-- /modules/rules/my_module.lua import("rules.my_module")
add_moduledirs("tools/xmakescripts/modules")

-- Add the plugins dir to support custom xmake <command>.
add_plugindirs("tools/xmakescripts/plugins")

-- Load our rule files into the global scope.
includes("tools/xmakescripts/rules/**.lua")

Expand Down

0 comments on commit e74956a

Please sign in to comment.