diff options
| author | ruki <[email protected]> | 2021-12-15 22:40:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-15 22:40:15 +0800 |
| commit | f5aa67b72f9959a25532d4d03f08b1749ded3e30 (patch) | |
| tree | 2d90fe830cda4abe238ba536affbca9bf38eacc7 | |
| parent | 6200b2a43dd9ddc7a031bf23430b82e807a7be74 (diff) | |
build and run targets with group
| -rw-r--r-- | xmake/actions/build/build.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/build/build_files.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/build/main.lua | 29 | ||||
| -rw-r--r-- | xmake/actions/build/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 32 | ||||
| -rw-r--r-- | xmake/actions/run/xmake.lua | 13 |
6 files changed, 65 insertions, 32 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index 38e95f4b1..598d4b2cf 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -200,7 +200,7 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target) end -- get batch jobs, @note we need export it for private.diagnosis.dump_buildjobs -function get_batchjobs(targetname) +function get_batchjobs(targetname, group_pattern) -- get root targets local targets_root = {} @@ -210,7 +210,8 @@ function get_batchjobs(targetname) local depset = hashset.new() local targets = {} for _, target in pairs(project.targets()) do - if target:is_default() or option.get("all") then + local group = target:get("group") + if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then for _, depname in ipairs(target:get("deps")) do depset:insert(depname) end @@ -234,10 +235,10 @@ function get_batchjobs(targetname) end -- the main entry -function main(targetname) +function main(targetname, group_pattern) -- build all jobs - local batchjobs = get_batchjobs(targetname) + local batchjobs = get_batchjobs(targetname, group_pattern) if batchjobs and batchjobs:size() > 0 then local curdir = os.curdir() runjobs("build", batchjobs, {comax = option.get("jobs") or 1, on_exit = function (errors) diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua index dd89ea311..2f8af59ec 100644 --- a/xmake/actions/build/build_files.lua +++ b/xmake/actions/build/build_files.lua @@ -114,7 +114,7 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target, end -- get batch jobs -function _get_batchjobs(targetname, filepatterns) +function _get_batchjobs(targetname, group_pattern, filepatterns) -- get root targets local targets_root = {} @@ -124,7 +124,8 @@ function _get_batchjobs(targetname, filepatterns) local depset = hashset.new() local targets = {} for _, target in pairs(project.targets()) do - if target:is_default() or option.get("all") then + local group = target:get("group") + if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then for _, depname in ipairs(target:get("deps")) do depset:insert(depname) end @@ -192,13 +193,13 @@ function _get_file_patterns(sourcefiles) end -- the main entry -function main(targetname, sourcefiles) +function main(targetname, group_pattern, sourcefiles) -- convert all sourcefiles to lua pattern local filepatterns = _get_file_patterns(sourcefiles) -- build all jobs - local batchjobs = _get_batchjobs(targetname, filepatterns) + local batchjobs = _get_batchjobs(targetname, group_pattern, filepatterns) if batchjobs and batchjobs:size() > 0 then local curdir = os.curdir() runjobs("build_files", batchjobs, {comax = option.get("jobs") or 1, curdir = curdir, count_as_index = true}) diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index 70d15d75e..c355ae4ae 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -92,6 +92,16 @@ function _do_project_rules(scriptname, opt) end end +-- do build +function _do_build(targetname, group_pattern) + local sourcefiles = option.get("files") + if sourcefiles then + build_files(targetname, group_pattern, sourcefiles) + else + build(targetname, group_pattern) + end +end + -- main function main() @@ -106,10 +116,14 @@ function main() -- lock the whole project project.lock() - -- get the target name - local targetname = option.get("target") - -- config it first + local targetname + local group_pattern = option.get("group") + if group_pattern then + group_pattern = "^" .. path.pattern(group_pattern) .. "$" + else + targetname = option.get("target") + end task.run("config", {target = targetname}, {disable_dump = true}) -- enter project directory @@ -126,12 +140,7 @@ function main() _do_project_rules("build_before") -- do build - local sourcefiles = option.get("files") - if sourcefiles then - build_files(targetname, sourcefiles) - else - build(targetname) - end + _do_build(targetname, group_pattern) end, catch @@ -144,6 +153,8 @@ function main() -- raise if errors then raise(errors) + elseif group_pattern then + raise("build targets with group(%s) failed!", group_pattern) elseif targetname then raise("build target: %s failed!", targetname) else diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua index 631536f24..63677d594 100644 --- a/xmake/actions/build/xmake.lua +++ b/xmake/actions/build/xmake.lua @@ -44,6 +44,11 @@ task("build") {'b', "build", "k", nil , "Build target. This is default building mode and optional." } , {'r', "rebuild", "k", nil , "Rebuild the target." } , {'a', "all", "k", nil , "Build all targets." } + , {'g', "group", "kv", nil , "Run all targets of the given group. It support path pattern matching.", + "e.g.", + " xmake -g test", + " xmake -g test_*", + " xmake --group=benchmark/*" } , {nil, "dry-run", "k", nil , "Dry run to build target." } , {} diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 3b51c3c81..72983c446 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -144,17 +144,19 @@ function _run(target) end -- check targets -function _check_targets(targetname) +function _check_targets(targetname, group_pattern) -- get targets local targets = {} - if targetname and not targetname:startswith("__") then + if targetname then table.insert(targets, project.target(targetname)) else - -- install default or all targets for _, target in ipairs(project.ordertargets()) do - if (target:is_default() or option.get("all")) and target:is_binary() then - table.insert(targets, target) + if target:is_binary() then + local group = target:get("group") + if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then + table.insert(targets, target) + end end end end @@ -179,14 +181,18 @@ end -- main function main() - -- get the target name - local targetname = option.get("target") - -- config it first + local targetname + local group_pattern = option.get("group") + if group_pattern then + group_pattern = "^" .. path.pattern(group_pattern) .. "$" + else + targetname = option.get("target") + end task.run("config", {target = targetname, require = "n", verbose = false}) -- check targets first - _check_targets(targetname) + _check_targets(targetname, group_pattern) -- enter project directory local oldir = os.cd(project.directory()) @@ -195,10 +201,12 @@ function main() if targetname then _run(project.target(targetname)) else - -- run default or all binary targets for _, target in ipairs(project.ordertargets()) do - if (target:is_default() or option.get("all")) and target:is_binary() then - _run(target) + if target:is_binary() then + local group = target:get("group") + if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then + _run(target) + end end end end diff --git a/xmake/actions/run/xmake.lua b/xmake/actions/run/xmake.lua index 83d4d3f9f..7c5b1086e 100644 --- a/xmake/actions/run/xmake.lua +++ b/xmake/actions/run/xmake.lua @@ -43,13 +43,20 @@ task("run") { {'d', "debug", "k", nil , "Run and debug the given target." } , {'a', "all", "k", nil , "Run all targets." } + , {'g', "group", "kv", nil , "Run all targets of the given group. It support path pattern matching.", + "e.g.", + " xmake run -g test", + " xmake run -g test_*", + " xmake run --group=benchmark/*" } , {'w', "workdir", "kv", nil , "Work directory of running targets, default is folder of targetfile", "e.g.", - " --workdir=.", - " --workdir=`pwd`" } + " xmake run -w .", + " xmake run --workdir=`pwd`" } , {} , {nil, "target", "v", nil , "The target name. It will run all default targets if this parameter is not specified." - , values = function (complete, opt) return import("private.utils.complete_helper.runable_targets")(complete, opt) end } + , values = function (complete, opt) + return import("private.utils.complete_helper.runable_targets")(complete, opt) + end } , {nil, "arguments", "vs", nil , "The target arguments" } } |
