From 3ba28a72239a8d23d13cd577437e871eaebc155a Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 12 May 2025 03:49:31 +0200 Subject: (C++ modules support) normalize module progress format with regular C++ --- xmake/modules/private/utils/batchcmds.lua | 7 +- xmake/rules/c++/modules/builder.lua | 30 +++++++ xmake/rules/c++/modules/clang/builder.lua | 84 +++++++++++--------- xmake/rules/c++/modules/clang/scanner.lua | 2 +- xmake/rules/c++/modules/gcc/builder.lua | 128 +++++++++++++++++------------- xmake/rules/c++/modules/gcc/scanner.lua | 2 +- xmake/rules/c++/modules/msvc/builder.lua | 73 +++++++++-------- xmake/rules/c++/modules/msvc/scanner.lua | 2 +- 8 files changed, 199 insertions(+), 129 deletions(-) diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index bd3350954..8334475b9 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -308,6 +308,7 @@ function batchcmds:compilev(argv, opt) -- bind target if exists opt = opt or {} opt.target = self._TARGET + opt.verbose = (opt.verbose == nil) and true or opt.verbose -- load compiler and get compilation command local compiler_inst = opt.compiler @@ -337,7 +338,11 @@ function batchcmds:compilev(argv, opt) end -- add compilation command and bind run environments of compiler - self:vrunv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)}) + if opt.verbose then + self:vrunv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)}) + else + self:runv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)}) + end end -- add command: linker.link diff --git a/xmake/rules/c++/modules/builder.lua b/xmake/rules/c++/modules/builder.lua index 9a5a4b37e..44da4d622 100644 --- a/xmake/rules/c++/modules/builder.lua +++ b/xmake/rules/c++/modules/builder.lua @@ -594,6 +594,36 @@ function is_dependencies_changed(target, module) return requires, changed end +function show_progress(target, module, opt) + local show = function(...) + local batchcmds = opt and opt.batchcmds + if batchcmds then + batchcmds:show_progress(opt.progress, ...) + else + progress.show(opt.progress, ...) + end + end + local suffix = opt.suffix or "" + local cmd = opt.cmd or "" + local dim = "" + if option.get("verbose") then + dim = "${dim}" + end + local header = "${clear}${color.build.target}<%s>${clear}" .. dim + if opt.headerunit then + local name = module.method == "include-angle" and ("<" .. path.filename(module.name) .. ">") or module.name + show(header .. " compiling.headerunit.$(mode) %s${clear}%s" .. suffix, target:fullname(), name, cmd) + elseif opt.bmi then + if opt.objectfile then + show(header .. " compiling.module.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd) + else + show(header .. " compiling.module.bmi.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd) + end + else + show("compiling.$(mode) %s${clear}%s" .. suffix, module.sourcefile, cmd) + end +end + function clean(target) -- we cannot use target:data("cxx.has_modules"), -- because on_config will be not called when cleaning targets diff --git a/xmake/rules/c++/modules/clang/builder.lua b/xmake/rules/c++/modules/clang/builder.lua index 8d8a240e7..474793472 100644 --- a/xmake/rules/c++/modules/clang/builder.lua +++ b/xmake/rules/c++/modules/clang/builder.lua @@ -32,8 +32,9 @@ import(".mapper") import(".builder", {inherit = true}) function _make_modulebuildflags(target, module, opt) + assert(not module.headerunit) local flags - if opt and opt.bmi then + if opt.bmi then local module_outputflag = support.get_moduleoutputflag(target) flags = {"-x", "c++-module"} @@ -45,8 +46,12 @@ function _make_modulebuildflags(target, module, opt) table.join2(flags, {"-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-Wno-deprecated-declarations"}) end table.insert(flags, module_outputflag .. module.bmifile) - elseif not module.headerunit and not module.implementation and not module.interface then + else flags = {"-x", "c++"} + local std = (module.name == "std" or module.name == "std.compat") + if std then + table.join2(flags, {"-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-Wno-deprecated-declarations"}) + end end return flags end @@ -55,11 +60,11 @@ function _compile_one_step(target, module, opt) -- get flags local module_outputflag = support.get_moduleoutputflag(target) if module_outputflag then - local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = true}) + local flags = _make_modulebuildflags(target, module, opt) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.objectfile) + _compile(target, flags, module, opt) end else _compile_bmi_step(target, module, opt) @@ -68,20 +73,20 @@ function _compile_one_step(target, module, opt) end function _compile_bmi_step(target, module, opt) - local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = false}) + local flags = _make_modulebuildflags(target, module, opt) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.bmifile, opt) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.bmifile) + _compile(target, flags, module, opt) end end function _compile_objectfile_step(target, module, opt) - local flags = _make_modulebuildflags(target, module, {bmi = false, objectfile = false}) + local flags = _make_modulebuildflags(target, module, opt) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile}) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile}) + _compile(target, flags, module, opt) end end @@ -97,34 +102,47 @@ function _make_headerunitflags(target, headerunit) end -- do compile -function _compile(target, flags, sourcefile, outputfile, opt) +function _compile(target, flags, module, opt) + opt = opt or {} + local sourcefile = module.sourcefile + local outputfile = ((opt.bmi and not opt.objectfile) or opt.headerunit) and module.bmifile or module.objectfile local dryrun = option.get("dry-run") local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) flags = table.join(compflags or {}, flags or {}) - - local bmifile = opt and opt.bmifile - -- trace + local cmd if option.get("verbose") then - print(compinst:compcmd(bmifile or sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})) + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true}) end + show_progress(target, module, table.join(opt, {cmd = cmd})) -- do compile if not dryrun then - assert(compinst:compile(bmifile or sourcefile, outputfile, {target = target, compflags = flags})) + assert(compinst:compile(sourcefile, outputfile, {target = target, compflags = flags})) end end -- do compile for batchcmds -- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx -function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile, opt) +function _batchcmds_compile(batchcmds, target, flags, module, opt) opt = opt or {} + local sourcefile = module.sourcefile + local outputfile = (opt.bmi and not opt.objectfile) and module.bmifile or module.objectfile local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) - flags = table.join("-c", compflags or {}, flags or {}, {"-o", outputfile, opt.bmifile or sourcefile}) - batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"}) + flags = table.join("-c", compflags or {}, flags or {}, {"-o", outputfile, sourcefile}) + + -- trace + local cmd + if option.get("verbose") then + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true}) + end + show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds})) + + -- do compile + batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false}) end -- get module requires flags @@ -224,15 +242,12 @@ function make_module_job(target, module, opt) end if bmi and objectfile then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name) - _compile_one_step(target, module) + _compile_one_step(target, module, opt) elseif bmi then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name) - _compile_bmi_step(target, module) + _compile_bmi_step(target, module, opt) else if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - progress.show(opt.progress, "compiling.$(mode) %s", module.sourcefile) - _compile_objectfile_step(target, module) + _compile_objectfile_step(target, module, opt) else os.tryrm(module.objectfile) -- force rebuild for .cpp files end @@ -258,15 +273,12 @@ function make_module_buildcmds(target, batchcmds, module, opt) end if bmi and objectfile then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name) - _compile_one_step(target, module, {batchcmds = batchcmds}) + _compile_one_step(target, module, table.join(opt, {batchcmds = batchcmds})) elseif bmi then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name) - _compile_bmi_step(target, module, {batchcmds = batchcmds}) + _compile_bmi_step(target, module, table.join(opt, {batchcmds = batchcmds})) else if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - batchcmds:show_progress(opt.progress, "compiling.$(mode) %s", module.sourcefile) - _compile_objectfile_step(target, module, {batchcmds = batchcmds}) + _compile_objectfile_step(target, module, table.join(opt, {batchcmds = batchcmds})) else batchcmds:rm(module.objectfile) -- force rebuild for .cpp files end @@ -280,9 +292,7 @@ end function make_headerunit_job(target, headerunit, opt) local build = should_build(target, headerunit) if build then - local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) - _compile(target, _make_headerunitflags(target, headerunit), headerunit.sourcefile, headerunit.bmifile) + _compile(target, _make_headerunitflags(target, headerunit), headerunit, table.join(opt, {headerunit = true})) end end @@ -294,9 +304,7 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, opt) local build = should_build(target, headerunit) if build then - local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) - _batchcmds_compile(batchcmds, target, table.join(_make_headerunitflags(target, headerunit)), headerunit.sourcefile, headerunit.bmifile) + _batchcmds_compile(batchcmds, target, table.join(_make_headerunitflags(target, headerunit)), headerunit, table.join(opt, {headerunit = true})) batchcmds:add_depfiles(headerunit.sourcefile) end batchcmds:add_depvalues(depvalues) diff --git a/xmake/rules/c++/modules/clang/scanner.lua b/xmake/rules/c++/modules/clang/scanner.lua index d565cd63e..adb4d0dd8 100644 --- a/xmake/rules/c++/modules/clang/scanner.lua +++ b/xmake/rules/c++/modules/clang/scanner.lua @@ -37,7 +37,7 @@ function scan_dependency_for(target, sourcefile, opt) depend.on_changed(function() if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) diff --git a/xmake/rules/c++/modules/gcc/builder.lua b/xmake/rules/c++/modules/gcc/builder.lua index 0b3a50fd3..7e207f396 100644 --- a/xmake/rules/c++/modules/gcc/builder.lua +++ b/xmake/rules/c++/modules/gcc/builder.lua @@ -47,16 +47,32 @@ function _make_headerunitflags(target, headerunit_mapper, headerunit) end -- do compile -function _compile(target, flags, sourcefile, outputfile) +function _compile(target, flags, module, opt) + + opt = opt or {} + local sourcefile = opt.headerunit and path.filename(module.sourcefile) or module.sourcefile + local outputfile = opt.headerunit and module.bmifile or module.objectfile local dryrun = option.get("dry-run") local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) flags = table.join(compflags or {}, flags or {}) -- trace + local cmd if option.get("verbose") then - print(compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, rawargs = true})) + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, rawargs = true}) + end + local mapper_str + if option.get("diagnosis") then + if opt.headerunit then + mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", sourcefile, module.name, io.readfile(opt.mapper_file):trim()) + elseif module.name then + mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", module.name, sourcefile, io.readfile(opt.mapper_file):trim()) + else + mapper_str = format("\n${dim color.warning}mapper file for %s --------\n%s\n--------", sourcefile, io.readfile(opt.mapper_file):trim()) + end end + show_progress(target, module, table.join(opt, {cmd = cmd, suffix = mapper_str})) -- do compile if not dryrun then @@ -66,11 +82,32 @@ end -- do compile for batchcmds -- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx -function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile) +function _batchcmds_compile(batchcmds, target, flags, module, opt) + local sourcefile = opt.headerunit and path.filename(module.sourcefile) or module.sourcefile + local outputfile = opt.headerunit and module.bmifile or module.objectfile local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) flags = table.join("-c", compflags or {}, flags or {}, {"-o", outputfile, sourcefile}) - batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"}) + + -- trace + local cmd + if option.get("verbose") then + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, rawargs = true}) + end + local mapper_str + if option.get("diagnosis") then + if opt.headerunit then + mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", sourcefile, module.name, io.readfile(opt.mapper_file):trim()) + elseif module.name then + mapper_str = format("\n${dim color.warning}mapper file for %s (%s) --------\n%s\n--------", module.name, sourcefile, io.readfile(opt.mapper_file):trim()) + else + mapper_str = format("\n${dim color.warning}mapper file for %s --------\n%s\n--------", sourcefile, io.readfile(opt.mapper_file):trim()) + end + end + show_progress(target, module, table.join(opt, {cmd = cmd, suffix = mapper_str, batchcmds = batchcmds})) + + -- do compile + batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false}) end function _module_map_cachekey(target) @@ -187,18 +224,15 @@ function make_module_job(target, module, opt) local flags = {"-x", "c++"} if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - if bmi and objectfile then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name) - table.insert(flags, module_flag) - elseif bmi then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name) - table.insert(flags, module_flag) - table.insert(flags, module_onlyflag) - else - progress.show(opt.progress, "compiling.$(mode) %s", module.sourcefile) + if bmi then + if objectfile then + table.insert(flags, module_flag) + else + table.insert(flags, module_flag) + table.insert(flags, module_onlyflag) + end end - _compile(target, flags, module.sourcefile, module.objectfile) - -- os.tryrm(module_mapper) -- force rebuild for .cpp files + _compile(target, flags, module, table.join(opt or {}, {mapper_file = module_mapper})) else os.tryrm(module.objectfile) -- force rebuild for .cpp files end @@ -213,48 +247,42 @@ function make_module_buildcmds(target, batchcmds, module, opt) local module_flag = support.get_modulesflag(target) local module_mapper - if module.implementation or module.interface or module.deps then + if module.deps then module_mapper = _get_modulemapper_file(target, module) target:fileconfig_add(module.sourcefile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) end -- generate and append module mapper file local build = should_build(target, module) + local bmi = opt and opt.bmi + local objectfile = opt and opt.objectfile - local fileconfig = target:fileconfig(module.sourcefile) - local external = fileconfig and fileconfig.external - local bmionly = external and external.bmionly - local reused = external and external.reused - if build and not reused then - if module.implementation or module.interface or module.deps then - _generate_modulemapper_file(target, module) + if build then + local objectdir = path.directory(module.objectfile) + batchcmds:mkdir(objectdir) + if module.bmifile then + local bmidir = path.directory(module.bmifile) + batchcmds:mkdir(bmidir) end - if option.get("diagnosis") then - if module.name then - batchcmds:show("mapper file for %s (%s) --------\n%s--------", module.name, module.sourcefile, io.readfile(module_mapper)) - else - batchcmds:show("mapper file for %s --------\n%s--------", module.sourcefile, io.readfile(module_mapper)) - end + if module.deps then + _generate_modulemapper_file(target, module) end + + local flags = {"-x", "c++"} if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - batchcmds:mkdir(path.directory(module.objectfile)) - local flags = {"-x", "c++"} - table.insert(flags, module_flag) - local name = module.name or module.sourcefile - if bmionly then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), name) - table.insert(flags, module_onlyflag) - else - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), name) + if bmi then + if objectfile then + table.insert(flags, module_flag) + else + table.insert(flags, module_flag) + table.insert(flags, module_onlyflag) + end end - _batchcmds_compile(batchcmds, target, flags, module.sourcefile, module.objectfile) - batchcmds:rm(module_mapper) + _batchcmds_compile(batchcmds, target, flags, module, table.join(opt, {batchcmds = batchcmds, mapper_file = module_mapper})) else batchcmds:rm(module.objectfile) -- force rebuild for .cpp files end - batchcmds:add_depfiles(module.sourcefile) - support.memcache():set2(target:fullname(), "has_built_" .. module.sourcefile, true) end return os.mtime(module.objectfile) end @@ -264,15 +292,9 @@ function make_headerunit_job(target, headerunit, opt) local build = should_build(target, headerunit) if build then local headerunit_mapper = _generate_headerunit_modulemapper_file(target, headerunit) - local name = headerunit.unique and path.filename(headerunit.sourcefile) or headerunit.name - if option.get("diagnosis") then - print("mapper file for %s (%s) --------\n%s--------", name, headerunit_mapper, io.readfile(headerunit_mapper)) - end - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) _compile(target, _make_headerunitflags(target, headerunit_mapper, headerunit), - path.filename(headerunit.sourcefile), headerunit.bmifile) - os.tryrm(headerunit_mapper) + headerunit, table.join(opt, {mapper_file = headerunit_mapper, headerunit = true})) end end @@ -285,16 +307,10 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, opt) local build = should_build(target, headerunit) if build then local headerunit_mapper = _generate_headerunit_modulemapper_file(target, headerunit) - local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name - if option.get("diagnosis") then - batchcmds:show("mapper file for %s (%s) --------\n%s--------", name, headerunit_mapper, io.readfile(headerunit_mapper)) - end - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit_mapper, headerunit), - path.filename(headerunit.sourcefile), headerunit.bmifile) + headerunit, table.join(opt, {mapper_file = headerunit_mapper, headerunit = true})) batchcmds:add_depfiles(headerunit.sourcefile) - batchcmds:rm(headerunit_mapper) end batchcmds:add_depvalues(depvalues) end diff --git a/xmake/rules/c++/modules/gcc/scanner.lua b/xmake/rules/c++/modules/gcc/scanner.lua index c8f61c83a..3b2b8b3ca 100644 --- a/xmake/rules/c++/modules/gcc/scanner.lua +++ b/xmake/rules/c++/modules/gcc/scanner.lua @@ -44,7 +44,7 @@ function scan_dependency_for(target, sourcefile, opt) depend.on_changed(function() if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${color.build.target}<%s> scanning.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}${color.build.target}<%s> scanning.module.deps %s", target:fullname(), sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) diff --git a/xmake/rules/c++/modules/msvc/builder.lua b/xmake/rules/c++/modules/msvc/builder.lua index acf3cb984..fa9c7021c 100644 --- a/xmake/rules/c++/modules/msvc/builder.lua +++ b/xmake/rules/c++/modules/msvc/builder.lua @@ -34,12 +34,13 @@ import(".builder", {inherit = true}) -- get flags for building a module function _make_modulebuildflags(target, module, opt) + opt = opt or {} local ifcoutputflag = support.get_ifcoutputflag(target) local ifconlyflag = support.get_ifconlyflag(target) local interfaceflag = support.get_interfaceflag(target) local internalpartitionflag = support.get_internalpartitionflag(target) - local bmionly = opt and opt.bmionly + local bmionly = opt.bmi and not opt.objectfile local flags if module.interface or module.implementation then -- named module @@ -54,9 +55,9 @@ function _compile_one_step(target, module, opt) -- get flags local flags = _make_modulebuildflags(target, module) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.objectfile) + _compile(target, flags, module, opt) end end @@ -65,11 +66,11 @@ function _compile_bmi_step(target, module, opt) if not ifconlyflag then _compile_one_step(target, module, opt) else - local flags = _make_modulebuildflags(target, module, {bmionly = true}) + local flags = _make_modulebuildflags(target, module, opt) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.objectfile) + _compile(target, flags, module, opt) end end end @@ -77,9 +78,9 @@ end function _compile_objectfile_step(target, module, opt) local flags = _make_modulebuildflags(target, module) if opt and opt.batchcmds then - _batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile) + _batchcmds_compile(opt.batchcmds, target, flags, module, opt) else - _compile(target, flags, module.sourcefile, module.objectfile) + _compile(target, flags, module, opt) end end @@ -102,20 +103,25 @@ function _make_headerunitflags(target, headerunit, headertype) end -- do compile -function _compile(target, flags, sourcefile, outputfile) +function _compile(target, flags, module, opt) + opt = opt or {} + local sourcefile = module.sourcefile + local outputfile = opt.headerunit and nil or module.objectfile local dryrun = option.get("dry-run") local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) flags = table.join(compflags or {}, flags or {}) -- trace + local cmd if option.get("verbose") then if not outputfile then - print(os.args(table.join(compinst:program(), flags, sourcefile))) + cmd = "\n" .. os.args(table.join(compinst:program(), flags, sourcefile)) else - print(compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})) + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true}) end end + show_progress(target, module, table.join(opt, {cmd = cmd})) -- do compile if not dryrun then @@ -125,12 +131,27 @@ end -- do compile for batchcmds -- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx -function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile) +function _batchcmds_compile(batchcmds, target, flags, module, opt) opt = opt or {} + local sourcefile = module.sourcefile + local outputfile = opt.headerunit and nil or module.objectfile local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"}) flags = table.join("/c", compflags or {}, flags or {}, outputfile and "-Fo" .. outputfile or {}, sourcefile or {}) - batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"}) + + -- trace + local cmd + if option.get("verbose") then + if not outputfile then + cmd = "\n" .. os.args(table.join(compinst:program(), flags, sourcefile)) + else + cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true}) + end + end + show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds})) + + -- do compile + batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false}) end -- get module requires flags @@ -233,15 +254,12 @@ function make_module_job(target, module, opt) end if bmi and objectfile then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name) - _compile_one_step(target, module) + _compile_one_step(target, module, opt) elseif bmi then - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name) - _compile_bmi_step(target, module) + _compile_bmi_step(target, module, opt) else if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - progress.show(opt.progress, "compiling.$(mode) %s", module.sourcefile) - _compile_objectfile_step(target, module) + _compile_objectfile_step(target, module, opt) else os.tryrm(module.objectfile) -- force rebuild for .cpp files end @@ -265,15 +283,12 @@ function make_module_buildcmds(target, batchcmds, module, opt) batchcmds:mkdir(bmidir) end if bmi and objectfile then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name) - _compile_one_step(target, module, {batchcmds = batchcmds}) + _compile_one_step(target, module, table.join(opt, {batchcmds = batchcmds})) elseif bmi then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name) - _compile_bmi_step(target, module, {batchcmds = batchcmds}) + _compile_bmi_step(target, module, table.join(opt, {batchcmds = batchcmds})) else if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then - batchcmds:show_progress(opt.progress, "compiling.$(mode) %s", module.sourcefile) - _compile_objectfile_step(target, module, {batchcmds = batchcmds}) + _compile_objectfile_step(target, module, table.join(opt, {batchcmds = batchcmds})) else batchcmds:rm(module.objectfile) -- force rebuild for .cpp files end @@ -287,10 +302,8 @@ end function make_headerunit_job(target, headerunit, opt) local build = should_build(target, headerunit) if build then - local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name local headertype = (headerunit.method == "include-angle") and ":angle" or ":quote" - progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) - _compile(target, _make_headerunitflags(target, headerunit, headertype), (headertype == ":angle") and headerunit.name or headerunit.sourcefile) + _compile(target, _make_headerunitflags(target, headerunit, headertype), {sourcefile = (headertype == ":angle") and headerunit.name or headerunit.sourcefile}, table.join(opt, {headerunit = true})) end end @@ -302,10 +315,8 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, opt) local build = should_build(target, headerunit) if build then - local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name local headertype = (headerunit.method == "include-angle") and ":angle" or ":quote" - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name) - _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, headertype), (headertype == ":angle") and headerunit.name or headerunit.sourcefile) + _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, headertype), {(headertype == ":angle") and headerunit.name or headerunit.sourcefile}, table.join(opt, {headerunit = true})) batchcmds:add_depfiles(headerunit.sourcefile) end batchcmds:add_depvalues(depvalues) diff --git a/xmake/rules/c++/modules/msvc/scanner.lua b/xmake/rules/c++/modules/msvc/scanner.lua index 20cc29d69..ea3717ea1 100644 --- a/xmake/rules/c++/modules/msvc/scanner.lua +++ b/xmake/rules/c++/modules/msvc/scanner.lua @@ -45,7 +45,7 @@ function scan_dependency_for(target, sourcefile, opt) depend.on_changed(function () if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then - progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) + progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile) end local outputdir = support.get_outputdir(target, sourcefile, {scan = true}) -- cgit v1.3.1