diff options
| author | Christian Rendina <[email protected]> | 2025-04-10 09:50:37 +0200 |
|---|---|---|
| committer | Christian Rendina <[email protected]> | 2025-04-10 09:50:37 +0200 |
| commit | 78723913d76fb8b615df34541236b8ea588d30db (patch) | |
| tree | b6b6ff550e4a2f73d94c63a61876cec31a4b3ae3 /xmake/plugins | |
| parent | 2051c13f735a626f7b6fd8b98aa69f01fd9cef7e (diff) | |
| parent | fd49b7754c6709a87b5beb5526788bbc1a663965 (diff) | |
Merge branch 'dev' of https://github.com/xmake-io/xmake into dev
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 15 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_flags.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 25 | ||||
| -rw-r--r-- | xmake/plugins/project/make/makefile.lua | 28 | ||||
| -rw-r--r-- | xmake/plugins/project/ninja/build_ninja.lua | 8 | ||||
| -rw-r--r-- | xmake/plugins/project/utils/target_cmds.lua | 118 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 30 |
7 files changed, 73 insertions, 157 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 46a9bfa64..4cf6eb1ab 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -27,7 +27,6 @@ import("core.project.project") import("core.language.language") import("private.utils.batchcmds") import("private.utils.executable_path") -import("private.utils.rule_groups") import("plugins.project.utils.target_cmds", {rootdir = os.programdir()}) import("actions.test.main", {rootdir = os.programdir(), alias = "test_action"}) @@ -242,25 +241,16 @@ end -- add target commands function _add_target_commands(jsonfile, target) - -- build sourcebatch groups first - local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches()) - -- add before commands -- we use irpairs(groups), because the last group that should be given the highest priority. - local cmds_before = {} - target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before"}) - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before"}) - -- rule.on_buildcmd_files should also be executed before building the target, as cmake PRE_BUILD does not work. - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups) + local cmds_before = target_cmds.get_target_buildcmds(target, {stages = {"before", "on"}}) _add_target_custom_commands(jsonfile, target, "before", cmds_before) -- add target source commands _add_target_source_commands(jsonfile, target) -- add after commands - local cmds_after = {} - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"}) - target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"}) + local cmds_after = target_cmds.get_target_buildcmds(target, {stages = {"after"}}) _add_target_custom_commands(jsonfile, target, "after", cmds_after) end @@ -317,6 +307,7 @@ end function make(outputdir) local oldir = os.cd(os.projectdir()) local jsonfile = io.open(path.join(outputdir, "compile_commands.json"), "w") + target_cmds.prepare_targets() _add_targets(jsonfile) jsonfile:close() os.cd(oldir) diff --git a/xmake/plugins/project/clang/compile_flags.lua b/xmake/plugins/project/clang/compile_flags.lua index 3c76b1bdb..5cfedbb19 100644 --- a/xmake/plugins/project/clang/compile_flags.lua +++ b/xmake/plugins/project/clang/compile_flags.lua @@ -85,10 +85,11 @@ end -- - https://clang.llvm.org/docs/JSONCompilationDatabase.html -- function make(outputdir) - - -- enter project directory local oldir = os.cd(os.projectdir()) + -- prepare targets + target_cmds.prepare_targets() + -- make all local flags = {} flags = _make_all(flags) @@ -100,6 +101,5 @@ function make(outputdir) end flagfile:close() - -- leave project directory os.cd(oldir) end diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 22edabcd2..9d2fc453a 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -29,7 +29,6 @@ import("core.project.rule") import("core.platform.platform") import("lib.detect.find_tool") import("private.utils.batchcmds") -import("private.utils.rule_groups") import("private.utils.target", {alias = "target_utils"}) import("plugins.project.utils.target_cmds", {rootdir = os.programdir()}) import("rules.c++.modules.modules_support.compiler_support", {alias = "module_compiler_support", rootdir = os.programdir()}) @@ -1201,9 +1200,6 @@ end -- add target custom commands function _add_target_custom_commands(cmakelists, target, outputdir) - -- build sourcebatch groups first - local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches()) - -- ignore c++ modules rules local ignored_rules if _can_native_support_for_cxxmodules() then @@ -1212,17 +1208,12 @@ function _add_target_custom_commands(cmakelists, target, outputdir) -- add before commands -- we use irpairs(groups), because the last group that should be given the highest priority. - local cmds_before = {} - target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before", ignored_rules = ignored_rules}) - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before", ignored_rules = ignored_rules}) -- rule.on_buildcmd_files should also be executed before building the target, as cmake PRE_BUILD does not work. - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {ignored_rules = ignored_rules}) + local cmds_before = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"before", "on"}}) _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "before", cmds_before) -- add after commands - local cmds_after = {} - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after", ignored_rules = ignored_rules}) - target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after", ignored_rules = ignored_rules}) + local cmds_after = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"after"}}) _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "after", cmds_after) end @@ -1331,21 +1322,11 @@ function _generate_cmakelists(cmakelists, outputdir) end end --- make function make(outputdir) - - -- enter project directory local oldir = os.cd(os.projectdir()) - - -- open the cmakelists local cmakelists = io.open(path.join(outputdir, "CMakeLists.txt"), "w") - - -- generate cmakelists + target_cmds.prepare_targets() _generate_cmakelists(cmakelists, outputdir) - - -- close the cmakelists cmakelists:close() - - -- leave project directory os.cd(oldir) end diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index 3d4d5507f..79277b3f1 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -27,7 +27,6 @@ import("core.language.language") import("core.platform.platform") import("lib.detect.find_tool") import("private.utils.batchcmds") -import("private.utils.rule_groups") import("plugins.project.utils.target_cmds", {rootdir = os.programdir()}) -- tranlate path @@ -469,14 +468,11 @@ function _add_build_phony(makefile, target) end -- add custom commands before building target -function _add_build_custom_commands_before(makefile, target, sourcegroups, outputdir) +function _add_build_custom_commands_before(makefile, target, outputdir) -- add before commands -- we use irpairs(groups), because the last group that should be given the highest priority. - local cmds_before = {} - target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before"}) - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before"}) - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups) + local cmds_before = target_cmds.get_target_buildcmds(target, {stages = {"before", "on"}}) local targetname = target:name() local label = "precmds_" .. targetname @@ -494,10 +490,8 @@ function _add_build_custom_commands_before(makefile, target, sourcegroups, outpu end -- add custom commands after building target -function _add_build_custom_commands_after(makefile, target, sourcegroups, outputdir) - local cmds_after = {} - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"}) - target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"}) +function _add_build_custom_commands_after(makefile, target, outputdir) + local cmds_after = target_cmds.get_target_buildcmds(target, {stages = {"after"}}) if #cmds_after > 0 then for _, cmd in ipairs(cmds_after) do local command = _get_command_string(cmd, outputdir) @@ -514,11 +508,8 @@ function _add_build_target(makefile, target, targetflags, outputdir) -- https://github.com/xmake-io/xmake/issues/2337 target:data_set("plugin.project.kind", "makefile") - -- build sourcebatch groups first - local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches()) - -- add custom commands before building target - local precmds_label = _add_build_custom_commands_before(makefile, target, sourcegroups, outputdir) + local precmds_label = _add_build_custom_commands_before(makefile, target, outputdir) -- is phony target? if target:is_phony() then @@ -602,7 +593,7 @@ function _add_build_target(makefile, target, targetflags, outputdir) makefile:writef("\t$(VV)%s\n", command) -- add custom commands after building target - _add_build_custom_commands_after(makefile, target, sourcegroups, outputdir) + _add_build_custom_commands_after(makefile, target, outputdir) -- end makefile:print("") @@ -687,10 +678,11 @@ function _add_clean(makefile, outputdir) end function make(outputdir) - - -- enter project directory local oldir = os.cd(os.projectdir()) + -- prepare targets + target_cmds.prepare_targets() + -- open the makefile local makefile = io.open(path.join(outputdir, "makefile"), "w") @@ -715,7 +707,5 @@ function make(outputdir) -- close the makefile makefile:close() - - -- leave project directory os.cd(oldir) end diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua index 819758447..11be6f4ae 100644 --- a/xmake/plugins/project/ninja/build_ninja.lua +++ b/xmake/plugins/project/ninja/build_ninja.lua @@ -28,6 +28,7 @@ import("core.tool.compiler") import("lib.detect.find_tool") import("lib.detect.find_toolname") import("core.tools.cl.parse_include") +import("plugins.project.utils.target_cmds", {rootdir = os.programdir()}) -- this sourcebatch is built? function _sourcebatch_is_built(sourcebatch) @@ -449,10 +450,11 @@ function _add_build_for_targets(ninjafile, outputdir) end function make(outputdir) - - -- enter project directory local oldir = os.cd(os.projectdir()) + -- prepare targets + target_cmds.prepare_targets() + -- open the build.ninja file -- -- we need to change encoding to support msvc_deps_prefix @@ -474,8 +476,6 @@ function make(outputdir) -- close the ninjafile ninjafile:close() - - -- leave project directory os.cd(oldir) end diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua index 332e4858d..b18acb943 100644 --- a/xmake/plugins/project/utils/target_cmds.lua +++ b/xmake/plugins/project/utils/target_cmds.lua @@ -24,94 +24,60 @@ import("core.project.config") import("core.base.hashset") import("core.project.rule") import("private.utils.batchcmds") -import("private.utils.rule_groups") +import("private.action.build.target", {alias = "target_buildutils"}) --- this sourcebatch is built? -function _sourcebatch_is_built(sourcebatch) - -- we can only use rulename to filter them because sourcekind may be bound to multiple rules - local rulename = sourcebatch.rulename - if rulename == "c.build" or rulename == "c++.build" - or rulename == "asm.build" or rulename == "cuda.build" - or rulename == "objc.build" or rulename == "objc++.build" - or rulename == "win.sdk.resource" then - return true - end +-- prepare targets +function prepare_targets() + local targets_root = target_buildutils.get_root_targets() + target_buildutils.run_targetjobs(targets_root, {job_kind = "prepare"}) end --- get target buildcmd commands -function get_target_buildcmd(target, cmds, opt) +-- get target buildcmds +function get_target_buildcmds(target, opt) opt = opt or {} - local suffix = opt.suffix - local ignored_rules = hashset.from(opt.ignored_rules or {}) - for _, ruleinst in ipairs(target:orderules()) do - if not ignored_rules:has(ruleinst:name()) then - local scriptname = "buildcmd" .. (suffix and ("_" .. suffix) or "") - local script = ruleinst:script(scriptname) - if script then - local batchcmds_ = batchcmds.new({target = target}) - script(target, batchcmds_, {}) - if not batchcmds_:empty() then - table.join2(cmds, batchcmds_:cmds()) - end - end - end + local progress_wrapper = {} + progress_wrapper.current = function () + return count end -end - --- get target buildcmd_files commands -function get_target_buildcmd_files(target, cmds, sourcebatch, opt) - opt = opt or {} - - -- get rule - local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!") - local ruleinst = assert(target:rule(rulename) or project.rule(rulename, {namespace = target:namespace()}) or - rule.rule(rulename), "unknown rule: %s", rulename) - local ignored_rules = hashset.from(opt.ignored_rules or {}) - if ignored_rules:has(ruleinst:name()) then - return + progress_wrapper.total = function () + return total end - - -- generate commands for xx_buildcmd_files - local suffix = opt.suffix - local scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "") - local script = ruleinst:script(scriptname) - if script then - local batchcmds_ = batchcmds.new({target = target}) - script(target, batchcmds_, sourcebatch, {}) - if not batchcmds_:empty() then - table.join2(cmds, batchcmds_:cmds()) + progress_wrapper.percent = function () + if total and total > 0 then + return math.floor((count * 100) / total) + else + return 0 end end - - -- generate commands for xx_buildcmd_file - if not script then - scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "") - script = ruleinst:script(scriptname) - if script then - local sourcekind = sourcebatch.sourcekind - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local batchcmds_ = batchcmds.new({target = target}) - script(target, batchcmds_, sourcefile, {}) - if not batchcmds_:empty() then - table.join2(cmds, batchcmds_:cmds()) - end - end + debug.setmetatable(progress_wrapper, { + __tostring = function () + -- we do not output any progress info for the project generators + return "" end - end -end - --- get target buildcmd commands of source group -function get_target_buildcmd_sourcegroups(target, cmds, sourcegroups, opt) - for idx, group in irpairs(sourcegroups) do - for _, item in pairs(group) do - -- buildcmd scripts are always in rule, so we need to ignore target item (item.target). - local sourcebatch = item.sourcebatch - if item.rule then - if not _sourcebatch_is_built(sourcebatch) then - get_target_buildcmd_files(target, cmds, sourcebatch, opt) + }) + local buildcmds = batchcmds.new({target = target}) + local jobgraph = target_buildutils.get_targetjobs({target}, { + job_kind = "build", + buildcmds = buildcmds, + with_stages = hashset.from(opt.stages or {}), + ignored_rules = hashset.from(opt.ignored_rules or {})}) + if jobgraph and not jobgraph:empty() then + local total = jobgraph:size() + local index = 0 + local jobqueue = jobgraph:build() + while true do + local job = jobqueue:getfree() + if job then + if job.run then + job.run(index, total, {progress = progress_wrapper}) end + jobqueue:remove(job) + index = index + 1 + else + break end end end + return buildcmds:cmds() end diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index b6b2e11d7..e3b9ddc95 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -39,7 +39,6 @@ import("private.action.require.install", {alias = "install_requires"}) import("private.action.run.runenvs") import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("private.utils.batchcmds") -import("private.utils.rule_groups") import("plugins.project.utils.target_cmds", {rootdir = os.programdir()}) function _translate_path(dir, vcxprojdir) @@ -132,24 +131,18 @@ function _make_custom_commands(target, vcxprojdir) return _translate_path(p, vcxprojdir) end) - -- build sourcebatch groups first - local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches()) - -- ignore c++ modules rules local ignored_rules = _get_cxxmodules_rules() -- add before commands -- we use irpairs(groups), because the last group that should be given the highest priority. - local cmds_before = {} - target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before", ignored_rules = ignored_rules}) - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before", ignored_rules = ignored_rules}) - -- rule.on_buildcmd_files should also be executed before building the target, as cmake PRE_BUILD does not work. - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {ignored_rules = ignored_rules}) + -- rule.on_buildcmd_files should also be executed before building the target + local cmds_before = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"before", "on"}}) + _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "before", cmds_before) -- add after commands - local cmds_after = {} - target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after", ignored_rules = ignored_rules}) - target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after", ignored_rules = ignored_rules}) + local cmds_after = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"after"}}) + _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "after", cmds_after) local commands = {} for _, cmd in ipairs(cmds_before) do @@ -386,17 +379,14 @@ end -- make vstudio project function make(outputdir, vsinfo) - - -- enter project directory local oldir = os.cd(project.directory()) - -- init solution directory - vsinfo.solution_dir = path.join(outputdir, "vs" .. vsinfo.vstudio_version) + -- prepare targets + target_cmds.prepare_targets() - -- init modes + -- init vsinfo + vsinfo.solution_dir = path.join(outputdir, "vs" .. vsinfo.vstudio_version) vsinfo.modes = _make_vsinfo_modes() - - -- init archs vsinfo.archs = _make_vsinfo_archs() -- load targets @@ -519,7 +509,5 @@ function make(outputdir, vsinfo) -- clear local cache _clear_cache() - - -- leave project directory os.cd(oldir) end |
