diff options
| author | ruki <[email protected]> | 2022-05-19 00:29:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-19 00:29:15 +0800 |
| commit | 05eff25304b1a440b481fc71ec2dcb082be98e4f (patch) | |
| tree | 5d7ded42e0c235618db7722418e6f7e42097268e /xmake/modules | |
| parent | 17db46f7afecc8dce915b4440ed1461b19325974 (diff) | |
fix preprocessor
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 40 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 43 | ||||
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 37 |
3 files changed, 61 insertions, 59 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index b768c1fce..148957029 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -442,7 +442,7 @@ function _preprocess(program, argv, opt) assert(objectfile and sourcefile, "%s: iorunv(%s): invalid arguments!", self, program) -- do preprocess - local cppfile = objectfile .. ".p" + local cppfile = path.join(path.directory(objectfile), path.basename(objectfile) .. path.extension(sourcefile)) local cppfiledir = path.directory(cppfile) if not os.isdir(cppfiledir) then os.mkdir(cppfiledir) @@ -450,8 +450,8 @@ function _preprocess(program, argv, opt) table.insert(cppflags, "-P") table.insert(cppflags, "-Fi" .. cppfile) table.insert(cppflags, sourcefile) - local outdata, errdata = vstool.iorunv(program, winos.cmdargv(cppflags), opt) - return outdata, errdata, sourcefile, objectfile, cppfile, flags + local ok = try{ function() vstool.runv(program, winos.cmdargv(cppflags), opt); return true end} + return ok, sourcefile, objectfile, cppfile, flags end -- make the compile arguments list @@ -506,29 +506,31 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) end -- use vstool to compile and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528 + local preprocessed = false if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true})) - return distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), + preprocessed = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), preprocess = _preprocess, tool = self, target = opt.target}) elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then local program, argv = compargv(self, sourcefile, objectfile, compflags, table.join(opt, {rawargs = true})) - local outdata, errdata, _, objectfile_real, cppfile, cppflags = _preprocess(program, argv, {envs = self:runenvs(), target = opt.target}) - local cached = false - local cachekey - cachekey = build_cache.cachekey(program, cppfile, cppflags, self:runenvs()) - local objectfile_cached = build_cache.get(cachekey) - if objectfile_cached then - os.cp(objectfile_cached, objectfile_real) - cached = true - end - if not cached then - vstool.iorunv(program, winos.cmdargv(argv), {envs = self:runenvs()}) - if cachekey then - build_cache.put(cachekey, objectfile_real) + local ok, _, objectfile_real, cppfile, cppflags = _preprocess(program, argv, {envs = self:runenvs(), target = opt.target}) + if ok then + local cachekey + cachekey = build_cache.cachekey(program, cppfile, cppflags, self:runenvs()) + local objectfile_cached = build_cache.get(cachekey) + if objectfile_cached then + os.cp(objectfile_cached, objectfile_real) + else + vstool.iorunv(program, winos.cmdargv(table.join(cppflags, "-Fo" .. objectfile_real, cppfile)), {envs = self:runenvs()}) + if cachekey then + build_cache.put(cachekey, objectfile_real) + end end + preprocessed = true + os.rm(cppfile) end - return outdata, errdata - else + end + if not preprocessed then local program, argv = compargv(self, sourcefile, objectfile, compflags, opt) return vstool.iorunv(program, argv, {envs = self:runenvs()}) end diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 744b2cfd6..6a6f5fadd 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -358,11 +358,7 @@ end -- link the target file function link(self, objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory os.mkdir(path.directory(targetfile)) - - -- link it local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags) os.runv(program, argv, {envs = self:runenvs()}) end @@ -425,7 +421,7 @@ function _preprocess(program, argv, opt) assert(objectfile and sourcefile, "%s: iorunv(%s): invalid arguments!", self, program) -- do preprocess - local cppfile = objectfile .. ".p" + local cppfile = path.join(path.directory(objectfile), path.basename(objectfile) .. path.extension(sourcefile)) local cppfiledir = path.directory(cppfile) if not os.isdir(cppfiledir) then os.mkdir(cppfiledir) @@ -434,8 +430,8 @@ function _preprocess(program, argv, opt) table.insert(cppflags, "-o") table.insert(cppflags, cppfile) table.insert(cppflags, sourcefile) - local outdata, errdata = os.iorunv(program, cppflags, opt) - return outdata, errdata, sourcefile, objectfile, cppfile, flags + local ok = try {function () os.runv(program, cppflags, opt); return true end} + return ok, sourcefile, objectfile, cppfile, flags end -- make the compile arguments list for the precompiled header @@ -505,26 +501,29 @@ function compile(self, sourcefile, objectfile, dependinfo, flags) end -- do compile + local preprocessed = false local program, argv = compargv(self, sourcefile, objectfile, compflags) if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then - distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), preprocess = _preprocess, tool = self}) + preprocessed = distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), preprocess = _preprocess, tool = self}) elseif build_cache.is_enabled() and build_cache.is_supported(self:kind()) then - local _, _, _, objectfile_real, cppfile, cppflags = _preprocess(program, argv, opt) - local cached = false - local cachekey - cachekey = build_cache.cachekey(program, cppfile, cppflags, self:runenvs()) - local objectfile_cached = build_cache.get(cachekey) - if objectfile_cached then - os.cp(objectfile_cached, objectfile_real) - cached = true - end - if not cached then - os.iorunv(program, argv, {envs = self:runenvs()}) - if cachekey then - build_cache.put(cachekey, objectfile_real) + local ok, _, objectfile_real, cppfile, cppflags = _preprocess(program, argv, opt) + if ok then + local cachekey + cachekey = build_cache.cachekey(program, cppfile, cppflags, self:runenvs()) + local objectfile_cached = build_cache.get(cachekey) + if objectfile_cached then + os.cp(objectfile_cached, objectfile_real) + else + os.iorunv(program, table.join(cppflags, "-o", objectfile_real, cppfile), {envs = self:runenvs()}) + if cachekey then + build_cache.put(cachekey, objectfile_real) + end end + preprocessed = true + os.rm(cppfile) end - else + end + if not preprocessed then os.iorunv(program, argv, {envs = self:runenvs()}) end end, diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index 7e8f46b6f..e4ade5c13 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -232,25 +232,26 @@ function distcc_build_client:compile(program, argv, opt) -- do preprocess opt = opt or {} local preprocess = assert(opt.preprocess, "preprocessor not found!") - local outdata, errdata, sourcefile, objectfile, cppfile, cppflags = preprocess(program, argv, opt) - - -- get objectfile from the build cache first - local cached = false - local cachekey - if build_cache.is_enabled() then - cachekey = build_cache.cachekey(program, cppfile, cppflags, opt.envs) - local objectfile_cached = build_cache.get(cachekey) - if objectfile_cached then - os.cp(objectfile_cached, objectfile) - cached = true + local ok, sourcefile, objectfile, cppfile, cppflags = preprocess(program, argv, opt) + if ok then + -- get objectfile from the build cache first + local cached = false + local cachekey + if build_cache.is_enabled() then + cachekey = build_cache.cachekey(program, cppfile, cppflags, opt.envs) + local objectfile_cached = build_cache.get(cachekey) + if objectfile_cached then + os.cp(objectfile_cached, objectfile) + cached = true + end end - end - -- do distcc compilation - if not cached then - session:compile(sourcefile, objectfile, cppfile, cppflags, opt) - if cachekey then - build_cache.put(cachekey, objectfile) + -- do distcc compilation + if not cached then + session:compile(sourcefile, objectfile, cppfile, cppflags, opt) + if cachekey then + build_cache.put(cachekey, objectfile) + end end end @@ -259,7 +260,7 @@ function distcc_build_client:compile(program, argv, opt) -- unlock this host self:_host_status_unlock(host) - return outdata, errdata + return ok end -- get the status |
