Skip to content

Commit 9ecfe9b

Browse files
authored
Merge pull request #6423 from Arthapz/improve-module-format-output
(C++ modules support) Improve module format output
2 parents 5a580f0 + 3ba28a7 commit 9ecfe9b

File tree

8 files changed

+204
-133
lines changed

8 files changed

+204
-133
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: 48 additions & 39 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,20 +46,25 @@ 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
5358

5459
function _compile_one_step(target, module, opt)
5560
-- get flags
61+
local module_outputflag = support.get_moduleoutputflag(target)
5662
if module_outputflag then
57-
local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = true})
63+
local flags = _make_modulebuildflags(target, module, opt)
5864
if opt and opt.batchcmds then
59-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile)
65+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
6066
else
61-
_compile(target, flags, module.sourcefile, module.objectfile)
67+
_compile(target, flags, module, opt)
6268
end
6369
else
6470
_compile_bmi_step(target, module, opt)
@@ -67,20 +73,20 @@ function _compile_one_step(target, module, opt)
6773
end
6874

6975
function _compile_bmi_step(target, module, opt)
70-
local flags = _make_modulebuildflags(target, module, {bmi = true, objectfile = false})
76+
local flags = _make_modulebuildflags(target, module, opt)
7177
if opt and opt.batchcmds then
72-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.bmifile, opt)
78+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
7379
else
74-
_compile(target, flags, module.sourcefile, module.bmifile)
80+
_compile(target, flags, module, opt)
7581
end
7682
end
7783

7884
function _compile_objectfile_step(target, module, opt)
79-
local flags = _make_modulebuildflags(target, module, {bmi = false, objectfile = false})
85+
local flags = _make_modulebuildflags(target, module, opt)
8086
if opt and opt.batchcmds then
81-
_batchcmds_compile(opt.batchcmds, target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile})
87+
_batchcmds_compile(opt.batchcmds, target, flags, module, opt)
8288
else
83-
_compile(target, flags, module.sourcefile, module.objectfile, {bmifile = module.bmifile})
89+
_compile(target, flags, module, opt)
8490
end
8591
end
8692

@@ -96,34 +102,47 @@ function _make_headerunitflags(target, headerunit)
96102
end
97103

98104
-- do compile
99-
function _compile(target, flags, sourcefile, outputfile, opt)
105+
function _compile(target, flags, module, opt)
106+
100107
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
101110
local dryrun = option.get("dry-run")
102111
local compinst = target:compiler("cxx")
103112
local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"})
104-
flags = table.join(flags or {}, compflags or {})
105-
106-
local bmifile = opt and opt.bmifile
107-
113+
flags = table.join(compflags or {}, flags or {})
108114
-- trace
115+
local cmd
109116
if option.get("verbose") then
110-
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})
111118
end
119+
show_progress(target, module, table.join(opt, {cmd = cmd}))
112120

113121
-- do compile
114122
if not dryrun then
115-
assert(compinst:compile(bmifile or sourcefile, outputfile, {target = target, compflags = flags}))
123+
assert(compinst:compile(sourcefile, outputfile, {target = target, compflags = flags}))
116124
end
117125
end
118126

119127
-- do compile for batchcmds
120128
-- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx
121-
function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile, opt)
129+
function _batchcmds_compile(batchcmds, target, flags, module, opt)
122130
opt = opt or {}
131+
local sourcefile = module.sourcefile
132+
local outputfile = (opt.bmi and not opt.objectfile) and module.bmifile or module.objectfile
123133
local compinst = target:compiler("cxx")
124134
local compflags = compinst:compflags({sourcefile = sourcefile, target = target, sourcekind = "cxx"})
125-
flags = table.join("-c", compflags or {}, flags, {"-o", outputfile, opt.bmifile or sourcefile})
126-
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})
127146
end
128147

129148
-- get module requires flags
@@ -223,15 +242,12 @@ function make_module_job(target, module, opt)
223242
end
224243

225244
if bmi and objectfile then
226-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name)
227-
_compile_one_step(target, module)
245+
_compile_one_step(target, module, opt)
228246
elseif bmi then
229-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name)
230-
_compile_bmi_step(target, module)
247+
_compile_bmi_step(target, module, opt)
231248
else
232249
if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then
233-
progress.show(opt.progress, "compiling.$(mode) %s", module.sourcefile)
234-
_compile_objectfile_step(target, module)
250+
_compile_objectfile_step(target, module, opt)
235251
else
236252
os.tryrm(module.objectfile) -- force rebuild for .cpp files
237253
end
@@ -257,15 +273,12 @@ function make_module_buildcmds(target, batchcmds, module, opt)
257273
end
258274

259275
if bmi and objectfile then
260-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:fullname(), module.name)
261-
_compile_one_step(target, module, {batchcmds = batchcmds})
276+
_compile_one_step(target, module, table.join(opt, {batchcmds = batchcmds}))
262277
elseif bmi then
263-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.bmi.$(mode) %s", target:fullname(), module.name)
264-
_compile_bmi_step(target, module, {batchcmds = batchcmds})
278+
_compile_bmi_step(target, module, table.join(opt, {batchcmds = batchcmds}))
265279
else
266280
if support.has_module_extension(module.sourcefile) or module.interface or module.implementation then
267-
batchcmds:show_progress(opt.progress, "compiling.$(mode) %s", module.sourcefile)
268-
_compile_objectfile_step(target, module, {batchcmds = batchcmds})
281+
_compile_objectfile_step(target, module, table.join(opt, {batchcmds = batchcmds}))
269282
else
270283
batchcmds:rm(module.objectfile) -- force rebuild for .cpp files
271284
end
@@ -279,9 +292,7 @@ end
279292
function make_headerunit_job(target, headerunit, opt)
280293
local build = should_build(target, headerunit)
281294
if build then
282-
local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name
283-
progress.show(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name)
284-
_compile(target, _make_headerunitflags(target, headerunit), headerunit.sourcefile, headerunit.bmifile)
295+
_compile(target, _make_headerunitflags(target, headerunit), headerunit, table.join(opt, {headerunit = true}))
285296
end
286297
end
287298

@@ -293,9 +304,7 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, opt)
293304

294305
local build = should_build(target, headerunit)
295306
if build then
296-
local name = headerunit.unique and path.filename(headerunit.name) or headerunit.name
297-
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), name)
298-
_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}))
299308
batchcmds:add_depfiles(headerunit.sourcefile)
300309
end
301310
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)