diff options
| author | ruki <[email protected]> | 2025-03-23 23:33:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:55 +0800 |
| commit | b8b96a08063228fd7832862275c9f47c24b1546c (patch) | |
| tree | a21f7a19abc07b5e96b63f65d03fa69d70322a56 | |
| parent | 9b3f6f86ae92c9fb779fbb898801ab4c70a6390e (diff) | |
prepare files
| -rw-r--r-- | xmake/actions/build/build.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/build/build_files.lua | 22 | ||||
| -rw-r--r-- | xmake/actions/build/main.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/build/prepare_files.lua | 26 |
4 files changed, 48 insertions, 23 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua index 8d5ffb72e..d11b1841b 100644 --- a/xmake/actions/build/build.lua +++ b/xmake/actions/build/build.lua @@ -231,7 +231,7 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, target, jobrefs, end -- get batch jobs, @note we need to export it for private.diagnosis.dump_buildjobs -function get_batchjobs(targetnames, group_pattern) +function get_batchjobs(targetnames, opt) -- get root targets local targets_root = {} @@ -251,6 +251,7 @@ function get_batchjobs(targetnames, group_pattern) end end else + local group_pattern = opt.group_pattern local depset = hashset.new() local targets = {} for _, target in ipairs(project.ordertargets()) do @@ -300,10 +301,10 @@ function get_batchjobs(targetnames, group_pattern) return batchjobs end -function main(targetnames, group_pattern) +function main(targetnames, opt) -- prepare to build - prepare_build(targetnames, {group_pattern = group_pattern}) + prepare_build(targetnames, opt) -- enable distcc? local distcc @@ -312,7 +313,7 @@ function main(targetnames, group_pattern) end -- build all jobs - local batchjobs = get_batchjobs(targetnames, group_pattern) + local batchjobs = get_batchjobs(targetnames, opt) if batchjobs and batchjobs:size() > 0 then local curdir = os.curdir() runjobs("build", batchjobs, {on_exit = function (errors) diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua index c44b8ecd1..8848962db 100644 --- a/xmake/actions/build/build_files.lua +++ b/xmake/actions/build/build_files.lua @@ -26,7 +26,7 @@ import("core.project.project") import("private.async.jobpool") import("async.runjobs") import("kinds.object") -import("prepare", {alias = "prepare_build"}) +import("prepare_files", {alias = "prepare_build_files"}) -- match source files function _match_sourcefiles(sourcefile, filepatterns) @@ -49,7 +49,6 @@ end -- add batch jobs function _add_batchjobs(batchjobs, rootjob, target, filepatterns) - local newbatches = {} local sourcecount = 0 for rulename, sourcebatch in pairs(target:sourcebatches()) do @@ -116,13 +115,17 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target, end -- get batch jobs -function _get_batchjobs(targetname, group_pattern, filepatterns) +function _get_batchjobs(targetname, opt) + + -- convert all sourcefiles to lua pattern + local filepatterns = _get_file_patterns(opt.sourcefiles) -- get root targets local targets_root = {} if targetname then table.insert(targets_root, project.target(targetname)) else + local group_pattern = opt.group_pattern local depset = hashset.new() local targets = {} for _, target in pairs(project.targets()) do @@ -195,22 +198,19 @@ function _get_file_patterns(sourcefiles) end -- the main entry -function main(targetname, group_pattern, sourcefiles) +function main(targetname, opt) - -- prepare to build - prepare_build(targetnames, {group_pattern = group_pattern, sourcefiles = sourcefiles}) - - -- convert all sourcefiles to lua pattern - local filepatterns = _get_file_patterns(sourcefiles) + -- prepare to build files + prepare_build_files(targetnames, opt) -- build all jobs - local batchjobs = _get_batchjobs(targetname, group_pattern, filepatterns) + local batchjobs = _get_batchjobs(targetname, opt) if batchjobs and batchjobs:size() > 0 then local curdir = os.curdir() runjobs("build_files", batchjobs, {comax = option.get("jobs") or 1, curdir = curdir}) os.cd(curdir) else - wprint("%s not found!", sourcefiles) + wprint("%s not found!", opt.sourcefiles) end end diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index fe7fcc771..5a6aa1535 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -101,20 +101,18 @@ function _do_project_rules(scriptname, opt) end -- do build -function _do_build(targetname, group_pattern) +function _do_build(targetname, opt) local sourcefiles = option.get("files") if sourcefiles then - build_files(targetname, group_pattern, sourcefiles) + build_files(targetname, {group_pattern = opt.group_pattern, sourcefiles = sourcefiles}) else - build(targetname, group_pattern) + build(targetname, {group_pattern = opt.group_pattern}) end end -- build targets function build_targets(targetnames, opt) opt = opt or {} - - local group_pattern = opt.group_pattern try { function () @@ -123,7 +121,7 @@ function build_targets(targetnames, opt) _do_project_rules("build_before") -- do build - _do_build(targetnames, group_pattern) + _do_build(targetnames, opt) -- do check check_targets(targetnames, {build = true}) @@ -146,8 +144,8 @@ function build_targets(targetnames, opt) -- raise if errors then raise(errors) - elseif group_pattern then - raise("build targets with group(%s) failed!", group_pattern) + elseif opt.group_pattern then + raise("build targets with group(%s) failed!", opt.group_pattern) elseif targetnames then targetnames = table.wrap(targetnames) raise("build target: %s failed!", table.concat(targetnames, ", ")) diff --git a/xmake/actions/build/prepare_files.lua b/xmake/actions/build/prepare_files.lua new file mode 100644 index 000000000..acdc41b0e --- /dev/null +++ b/xmake/actions/build/prepare_files.lua @@ -0,0 +1,26 @@ +--!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 prepare_files.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") + +function main(targetnames, opt) +end |
