diff options
| author | ruki <[email protected]> | 2025-08-06 10:23:12 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-06 10:23:12 +0800 |
| commit | 3d0ccd9842e7083863f42870157aa76cc0cddff7 (patch) | |
| tree | 4944ef2b35ad46fcce4905606f604f1f8c64d0ca | |
| parent | c6383c7675cfcca1d973be0e416d2668d887ceb8 (diff) | |
| parent | 9483bc6bab728fc71debdfb08f874a2234f2d665 (diff) | |
Merge pull request #6675 from xmake-io/revert-6667-config
Revert "improve to config targets"
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 55 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/target.lua | 18 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 5 |
3 files changed, 56 insertions, 22 deletions
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index ae185dc2c..70f135706 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -126,7 +126,51 @@ function sandbox_core_project.check_options() end end --- config targets +-- config target +function sandbox_core_project._config_target(target, opt) + + -- enter the environments of the target packages + local oldenvs = os.addenvs(target:pkgenvs()) + + -- do config + local before_config = target:script("config_before") + if before_config then + before_config(target, opt) + end + for _, rule in ipairs(table.wrap(target:orderules())) do + local before_config = rule:script("config_before") + if before_config then + before_config(target, opt) + end + end + + for _, rule in ipairs(table.wrap(target:orderules())) do + local on_config = rule:script("config") + if on_config then + on_config(target, opt) + end + end + local on_config = target:script("config") + if on_config then + on_config(target, opt) + end + + for _, rule in ipairs(table.wrap(target:orderules())) do + local after_config = rule:script("config_after") + if after_config then + after_config(target, opt) + end + end + local config_after = target:script("config_after") + if config_after then + config_after(target, opt) + end + + -- leave the environments of the target packages + os.setenvs(oldenvs) +end + +-- config targets, TODO: We should support parallel configuration -- -- @param opt the extra option, e.g. {recheck = false} -- @@ -138,9 +182,12 @@ end -- end -- function sandbox_core_project._config_targets(opt) - import("private.action.build.target", {alias = "target_buildutils"}) - local targets_root = target_buildutils.get_root_targets() - target_buildutils.run_targetjobs(targets_root, {job_kind = "config", job_opt = opt}) + opt = opt or {} + for _, target in ipairs(table.wrap(project.ordertargets())) do + if target:is_enabled() then + sandbox_core_project._config_target(target, opt) + end + end end -- load rules in the required packages for target diff --git a/xmake/modules/private/action/build/target.lua b/xmake/modules/private/action/build/target.lua index bd5730e1c..370145188 100644 --- a/xmake/modules/private/action/build/target.lua +++ b/xmake/modules/private/action/build/target.lua @@ -131,13 +131,13 @@ end -- add target jobs for the builtin script function add_targetjobs_for_builtin_script(jobgraph, target, opt) opt = opt or {} - local job_kind = opt.job_kind or "build" + local job_kind = opt.job_kind if target:is_static() or target:is_binary() or target:is_shared() or target:is_object() or target:is_moduleonly() then if job_kind == "prepare" then import("private.action.build.prepare_files", {anonymous = true})(jobgraph, target, opt) elseif job_kind == "link" then import("private.action.build.link_objects", {anonymous = true})(jobgraph, target, opt) - elseif job_kind == "build" then + else import("private.action.build.build_" .. target:kind(), {anonymous = true})(jobgraph, target, opt) end end @@ -148,7 +148,6 @@ function add_targetjobs_for_script(jobgraph, target, instance, opt) opt = opt or {} local has_script = false local buildcmds = opt.buildcmds - local job_opt = opt.job_opt local job_prefix = target:fullname() if target == instance then job_prefix = job_prefix .. "/target" @@ -180,7 +179,7 @@ function add_targetjobs_for_script(jobgraph, target, instance, opt) -- end) local jobname = string.format("%s/%s", job_prefix, script_name) jobgraph:add(jobname, function (index, total, opt) - script(target, table.join({progress = opt.progress}, job_opt)) + script(target, {progress = opt.progress}) end) end has_script = true @@ -204,7 +203,7 @@ function add_targetjobs_for_script(jobgraph, target, instance, opt) scriptcmd(target, buildcmds, {progress = opt.progress}) else local batchcmds_ = batchcmds.new({target = target}) - scriptcmd(target, batchcmds_, table.join({progress = opt.progress}, job_opt)) + scriptcmd(target, batchcmds_, {progress = opt.progress}) batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) end end) @@ -238,20 +237,13 @@ function add_targetjobs_with_stage(jobgraph, target, stage, opt) table.insert(instances, ruleinst) end end - -- on_config is different from on_build/on_prepare, - -- it does not rewrite all rules, and target.on_config needs to be called last. - if job_kind == "config" then - instances = table.slice(instances, 2) - table.insert(instances, target) - end local jobsize = jobgraph:size() jobgraph:group(group_name, function () local has_script = false local script_opt = { script_name = script_name, scriptcmd_name = scriptcmd_name, - buildcmds = opt.buildcmds, - job_opt = opt.job_opt + buildcmds = opt.buildcmds } for _, instance in ipairs(instances) do -- we need to use this group to sort rule scripts with add_orders diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index 99f6c8c6e..69c8ff03a 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -68,7 +68,6 @@ rule("qt.shared") -- define rule: qt console rule("qt.console") add_deps("qt.qrc", "qt.ui", "qt.moc", "qt.ts") - add_orders("qt.console", "platform.windows.subsystem") -- we must set kind before target.on_load(), may we will use target in on_load() on_load(function (target) @@ -85,7 +84,6 @@ rule("qt.console") -- define rule: qt widgetapp rule("qt.widgetapp") add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts") - add_orders("qt.widgetapp", "platform.windows.subsystem") -- we must set kind before target.on_load(), may we will use target in on_load() on_load(function (target) @@ -121,7 +119,6 @@ rule("qt.widgetapp") -- define rule: qt static widgetapp rule("qt.widgetapp_static") add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts") - add_orders("qt.widgetapp_static", "platform.windows.subsystem") -- we must set kind before target.on_load(), may we will use target in on_load() on_load(function (target) @@ -150,7 +147,6 @@ rule("qt.widgetapp_static") -- define rule: qt quickapp rule("qt.quickapp") add_deps("qt.qrc", "qt.moc", "qt._wasm_app", "qt.ts") - add_orders("qt.quickapp", "platform.windows.subsystem") -- we must set kind before target.on_load(), may we will use target in on_load() on_load(function (target) @@ -173,7 +169,6 @@ rule("qt.quickapp") -- define rule: qt static quickapp rule("qt.quickapp_static") add_deps("qt.qrc", "qt.moc", "qt._wasm_app", "qt.ts") - add_orders("qt.quickapp_static", "platform.windows.subsystem") -- we must set kind before target.on_load(), may we will use target in on_load() on_load(function (target) |
