Skip to content

Commit

Permalink
Merge pull request #5226 from xmake-io/longcmd
Browse files Browse the repository at this point in the history
Improve long compile command
  • Loading branch information
waruqi committed Jun 19, 2024
2 parents a298a7d + 35e5c8c commit 872ddbd
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions xmake/modules/core/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ function _preprocess(program, argv, opt)

-- do preprocess
local cppinfo = try {function ()
if is_host("windows") then
cppflags = winos.cmdargv(cppflags, {escape = true})
end
local outdata, errdata = os.iorunv(program, cppflags, opt)
return {outdata = outdata, errdata = errdata,
sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags}
Expand All @@ -754,7 +757,11 @@ end

-- compile preprocessed file
function _compile_preprocessed_file(program, cppinfo, opt)
local outdata, errdata = os.iorunv(program, table.join(cppinfo.cppflags, "-o", cppinfo.objectfile, cppinfo.cppfile), opt)
local argv = table.join(cppinfo.cppflags, "-o", cppinfo.objectfile, cppinfo.cppfile)
if is_host("windows") then
argv = winos.cmdargv(argv, {escape = true})
end
local outdata, errdata = os.iorunv(program, argv, opt)
-- we need to get warning information from output
cppinfo.outdata = outdata
cppinfo.errdata = errdata
Expand All @@ -763,9 +770,13 @@ end
-- do compile
function _compile(self, sourcefile, objectfile, compflags, opt)
opt = opt or {}
local program, argv = compargv(self, sourcefile, objectfile, compflags)
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
local function _compile_fallback()
return os.iorunv(program, argv, {envs = self:runenvs(), shell = opt.shell})
local runargv = argv
if is_host("windows") then
runargv = winos.cmdargv(argv, {escape = true})
end
return os.iorunv(program, runargv, {envs = self:runenvs(), shell = opt.shell})
end
local cppinfo
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
Expand All @@ -785,7 +796,7 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
end

-- make the compile arguments list for the precompiled header
function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
function _compargv_pch(self, pcheaderfile, pcoutputfile, flags, opt)

-- remove "-include xxx.h" and "-include-pch xxx.pch"
local pchflags = {}
Expand Down Expand Up @@ -817,17 +828,21 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
end

-- make the compile arguments list
return self:program(), table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile)
local argv = table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile)
return self:program(), argv
end

-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
function compargv(self, sourcefile, objectfile, flags, opt)

-- precompiled header?
local extension = path.extension(sourcefile)
if (extension:startswith(".h") or extension == ".inl") then
return _compargv_pch(self, sourcefile, objectfile, flags)
return _compargv_pch(self, sourcefile, objectfile, flags, opt)
end
return self:program(), table.join("-c", flags, "-o", objectfile, sourcefile)

local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
return self:program(), argv
end

-- compile the source file
Expand Down

0 comments on commit 872ddbd

Please sign in to comment.