Skip to content

Commit 3ba28a7

Browse files
committed
(C++ modules support) normalize module progress format with regular C++
1 parent 406aa7c commit 3ba28a7

File tree

8 files changed

+199
-129
lines changed

8 files changed

+199
-129
lines changed

xmake/modules/private/utils/batchcmds.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ function batchcmds:compilev(argv, opt)
308308
-- bind target if exists
309309
opt = opt or {}
310310
opt.target = self._TARGET
311+
opt.verbose = (opt.verbose == nil) and true or opt.verbose
311312

312313
-- load compiler and get compilation command
313314
local compiler_inst = opt.compiler
@@ -337,7 +338,11 @@ function batchcmds:compilev(argv, opt)
337338
end
338339

339340
-- add compilation command and bind run environments of compiler
340-
self:vrunv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)})
341+
if opt.verbose then
342+
self:vrunv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)})
343+
else
344+
self:runv(compiler_inst:program(), argv, {envs = table.join(compiler_inst:runenvs(), opt.envs)})
345+
end
341346
end
342347

343348
-- add command: linker.link

xmake/rules/c++/modules/builder.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,36 @@ function is_dependencies_changed(target, module)
594594
return requires, changed
595595
end
596596

597+
function show_progress(target, module, opt)
598+
local show = function(...)
599+
local batchcmds = opt and opt.batchcmds
600+
if batchcmds then
601+
batchcmds:show_progress(opt.progress, ...)
602+
else
603+
progress.show(opt.progress, ...)
604+
end
605+
end
606+
local suffix = opt.suffix or ""
607+
local cmd = opt.cmd or ""
608+
local dim = ""
609+
if option.get("verbose") then
610+
dim = "${dim}"
611+
end
612+
local header = "${clear}${color.build.target}<%s>${clear}" .. dim
613+
if opt.headerunit then
614+
local name = module.method == "include-angle" and ("<" .. path.filename(module.name) .. ">") or module.name
615+
show(header .. " compiling.headerunit.$(mode) %s${clear}%s" .. suffix, target:fullname(), name, cmd)
616+
elseif opt.bmi then
617+
if opt.objectfile then
618+
show(header .. " compiling.module.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd)
619+
else
620+
show(header .. " compiling.module.bmi.$(mode) %s${clear}%s" .. suffix, target:fullname(), module.name, cmd)
621+
end
622+
else
623+
show("compiling.$(mode) %s${clear}%s" .. suffix, module.sourcefile, cmd)
624+
end
625+
end
626+
597627
function clean(target)
598628
-- we cannot use target:data("cxx.has_modules"),
599629
-- because on_config will be not called when cleaning targets

xmake/rules/c++/modules/clang/builder.lua

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ import(".mapper")
3232
import(".builder", {inherit = true})
3333

3434
function _make_modulebuildflags(target, module, opt)
35+
assert(not module.headerunit)
3536
local flags
36-
if opt and opt.bmi then
37+
if opt.bmi then
3738
local module_outputflag = support.get_moduleoutputflag(target)
3839

3940
flags = {"-x", "c++-module"}
@@ -45,8 +46,12 @@ function _make_modulebuildflags(target, module, opt)
4546
table.join2(flags, {"-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-Wno-deprecated-declarations"})
4647
end
4748
table.insert(flags, module_outputflag .. module.bmifile)
48-
elseif not module.headerunit and not module.implementation and not module.interface then
49+
else
4950
flags = {"-x", "c++"}
51+
local std = (module.name == "std" or module.name == "std.compat")
52+
if std then
53+
table.join2(flags, {"-Wno-include-angled-in-module-purview", "-Wno-reserved-module-identifier", "-Wno-deprecated-declarations"})
54+
end
5055
end
5156
return flags
5257
end
@@ -55,11 +60,11 @@ function _compile_one_step(target, module, opt)
5560
-- get flags
5661
local module_outputflag = support.get_moduleoutputflag(target)
5762
if module_outputflag then
58-
local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = true})
63+
local flags = _make_modulebuildflags(target, module, opt)
5964
if opt and opt.batchcmds then
60-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile)
65+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
6166
else
62-
_compile(target, flags, module.sourcefile, module.objectfile)
67+
_compile(target, flags, module, opt)
6368
end
6469
else
6570
_compile_bmi_step(target, module, opt)
@@ -68,20 +73,20 @@ function _compile_one_step(target, module, opt)
6873
end
6974

7075
function _compile_bmi_step(target, module, opt)
71-
local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = false})
76+
local flags = _make_modulebuildflags(target, module, opt)
7277
if opt and opt.batchcmds then
73-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.bmifile, opt)
78+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
7479
else
75-
_compile(target, flags, module.sourcefile, module.bmifile)
80+
_compile(target, flags, module, opt)
7681
end
7782
end
7883

7984
function _compile_objectfile_step(target, module, opt)
80-
local flags = _make_modulebuildflags(target, module, {bmi = false, objectfile = false})
85+
local flags = _make_modulebuildflags(target, module, opt)
8186
if opt and opt.batchcmds then
82-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile})
87+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
8388
else
84-
_compile(target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile})
89+
_compile(target, flags, module, opt)
8590
end
8691
end
8792

@@ -97,34 +102,47 @@ function _make_headerunitflags(target, headerunit)
97102
end
98103

99104
-- do compile
100-
function _compile(target, flags, sourcefile, outputfile, opt)
105+
function _compile(target, flags, module, opt)
106+
101107
opt = opt or {}
108+
local sourcefile = module.sourcefile
109+
local outputfile = ((opt.bmi and not opt.objectfile) or opt.headerunit) and module.bmifile or module.objectfile
102110
local dryrun = option.get("dry-run")
103111
local compinst = target:compiler("cxx")
104112
local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"})
105113
flags = table.join(compflags or {}, flags or {})
106-
107-
local bmifile = opt and opt.bmifile
108-
109114
-- trace
115+
local cmd
110116
if option.get("verbose") then
111-
print(compinst:compcmd(bmifile or sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true}))
117+
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
112118
end
119+
show_progress(target, module, table.join(opt, {cmd = cmd}))
113120

114121
-- do compile
115122
if not dryrun then
116-
assert(compinst:compile(bmifile or sourcefile, outputfile, {target = target, compflags = flags}))
123+
assert(compinst:compile(sourcefile, outputfile, {target = target, compflags = flags}))
117124
end
118125
end
119126

120127
-- do compile for batchcmds
121128
-- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx
122-
function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile, opt)
129+
function _batchcmds_compile(batchcmds, target, flags, module, opt)
123130
opt = opt or {}
131+
local sourcefile = module.sourcefile
132+
local outputfile = (opt.bmi and not opt.objectfile) and module.bmifile or module.objectfile
124133
local compinst = target:compiler("cxx")
125134
local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"})
126-
flags = table.join("-c", compflags or {}, flags or {}, {"-o", outputfile, opt.bmifile or sourcefile})
127-
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
135+
flags = table.join("-c", compflags or {}, flags or {}, {"-o", outputfile, sourcefile})
136+
137+
-- trace
138+
local cmd
139+
if option.get("verbose") then
140+
cmd = "\n" .. compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, sourcekind = "cxx", rawargs = true})
141+
end
142+
show_progress(target, module, table.join(opt, {cmd = cmd, batchcmds = batchcmds}))
143+
144+
-- do compile
145+
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx", verbose = false})
128146
end
129147

130148
-- get module requires flags
@@ -224,15 +242,12 @@ function make_module_job(target, module, opt)
224242
end
225243

226244
if bmi and objectfile then
227-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name)
228-
_compile_one_step(target, module)
245+
_compile_one_step(target, module, opt)
229246
elseif bmi then
230-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name)
231-
_compile_bmi_step(target, module)
247+
_compile_bmi_step(target, module, opt)
232248
else
233249
if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then
234-
progress.show(opt.progress, "compiling.$(mode) %s", module.sourcefile)
235-
_compile_objectfile_step(target, module)
250+
_compile_objectfile_step(target, module, opt)
236251
else
237252
os.tryrm(module.objectfile) -- force rebuild for .cpp files
238253
end
@@ -258,15 +273,12 @@ function make_module_buildcmds(target, batchcmds, module, opt)
258273
end
259274

260275
if bmi and objectfile then
261-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name)
262-
_compile_one_step(target, module, {batchcmds = batchcmds})
276+
_compile_one_step(target, module, table.join(opt, {batchcmds = batchcmds}))
263277
elseif bmi then
264-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name)
265-
_compile_bmi_step(target, module, {batchcmds = batchcmds})
278+
_compile_bmi_step(target, module, table.join(opt, {batchcmds = batchcmds}))
266279
else
267280
if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then
268-
batchcmds:show_progress(opt.progress, "compiling.$(mode) %s", module.sourcefile)
269-
_compile_objectfile_step(target, module, {batchcmds = batchcmds})
281+
_compile_objectfile_step(target, module, table.join(opt, {batchcmds = batchcmds}))
270282
else
271283
batchcmds:rm(module.objectfile) -- force rebuild for .cpp files
272284
end
@@ -280,9 +292,7 @@ end
280292
function make_headerunit_job(target, headerunit, opt)
281293
local build = should_build(target, headerunit)
282294
if build then
283-
local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name
284-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name)
285-
_compile(target, _make_headerunitflags(target, headerunit), headerunit.sourcefile, headerunit.bmifile)
295+
_compile(target, _make_headerunitflags(target, headerunit), headerunit, table.join(opt, {headerunit = true}))
286296
end
287297
end
288298

@@ -294,9 +304,7 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, opt)
294304

295305
local build = should_build(target, headerunit)
296306
if build then
297-
local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name
298-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name)
299-
_batchcmds_compile(batchcmds, target, table.join(_make_headerunitflags(target, headerunit)), headerunit.sourcefile, headerunit.bmifile)
307+
_batchcmds_compile(batchcmds, target, table.join(_make_headerunitflags(target, headerunit)), headerunit, table.join(opt, {headerunit = true}))
300308
batchcmds:add_depfiles(headerunit.sourcefile)
301309
end
302310
batchcmds:add_depvalues(depvalues)

xmake/rules/c++/modules/clang/scanner.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function scan_dependency_for(target, sourcefile, opt)
3737

3838
depend.on_changed(function()
3939
if opt.progress and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then
40-
progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile)
40+
progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.module.deps %s", target:fullname(), sourcefile)
4141
end
4242

4343
local outputdir = support.get_outputdir(target, sourcefile, {scan = true})

0 commit comments

Comments
 (0)