diff options
| author | ruki <[email protected]> | 2025-01-24 23:03:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-01-24 23:03:27 +0800 |
| commit | 8be99bc6983b35ef18ed2147487fd28118bd34d7 (patch) | |
| tree | 4d0640a38ae140ee4d18320168de7d621a9e419c | |
| parent | 1b1ed22d618e6c31ede1cf2f1168476b504f5deb (diff) | |
improve to parser deps
| -rw-r--r-- | xmake/modules/core/project/depend.lua | 46 | ||||
| -rw-r--r-- | xmake/modules/core/tools/armcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl6x.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clang_cl.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/sdcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/tcc.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/swig/build_module_file.lua | 3 |
12 files changed, 45 insertions, 37 deletions
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index aea652779..b6f3976ba 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -21,12 +21,6 @@ -- imports import("core.base.option") import("core.project.project") -import("private.tools.cl.parse_deps", {alias = "parse_deps_cl"}) -import("private.tools.cl.parse_deps_json", {alias = "parse_deps_cl_json"}) -import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"}) -import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"}) -import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"}) -import("private.tools.cl6x.parse_deps", {alias = "parse_deps_cl6x"}) -- load depfiles function _load_depfiles(parser, dependinfo, depfiles, opt) @@ -40,32 +34,34 @@ function _load_depfiles(parser, dependinfo, depfiles, opt) end end +-- get depfiles parser +function _get_depfiles_parser(depfiles_format) + assert(depfiles_format, "no depfiles format") + local depfiles_parsers = _g._depfiles_parsers + if depfiles_parsers == nil then + depfiles_parsers = {} + _g._depfiles_parsers = depfiles_parsers + end + local parser = depfiles_parsers[depfiles_format] + if parser == nil then + parser = import("private.tools." .. depfiles_format .. ".parse_deps", {anonymous = true}) + depfiles_parsers[depfiles_format] = parser + end + return parser +end + -- load dependent info from the given file (.d) function load(dependfile, opt) - if os.isfile(dependfile) then -- may be the depend file has been incomplete when if the compilation process is abnormally interrupted local dependinfo = try { function() return io.load(dependfile) end } if dependinfo then -- attempt to load depfiles from the compilers - if dependinfo.depfiles_gcc then - _load_depfiles(parse_deps_gcc, dependinfo, dependinfo.depfiles_gcc, opt) - dependinfo.depfiles_gcc = nil - elseif dependinfo.depfiles_cl_json then - _load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json, opt) - dependinfo.depfiles_cl_json = nil - elseif dependinfo.depfiles_cl then - _load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl, opt) - dependinfo.depfiles_cl = nil - elseif dependinfo.depfiles_rc then - _load_depfiles(parse_deps_rc, dependinfo, dependinfo.depfiles_rc, opt) - dependinfo.depfiles_rc = nil - elseif dependinfo.depfiles_armcc then - _load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc, opt) - dependinfo.depfiles_armcc = nil - elseif dependinfo.depfiles_cl6x then - _load_depfiles(parse_deps_cl6x, dependinfo, dependinfo.depfiles_cl6x, opt) - dependinfo.depfiles_cl6x = nil + local depfiles = dependinfo.depfiles + if depfiles then + local depfiles_parser = _get_depfiles_parser(dependinfo.depfiles_format) + _load_depfiles(depfiles_parser, dependinfo, depfiles, opt) + dependinfo.depfiles = nil end return dependinfo end diff --git a/xmake/modules/core/tools/armcc.lua b/xmake/modules/core/tools/armcc.lua index 85aeda98c..3642feceb 100644 --- a/xmake/modules/core/tools/armcc.lua +++ b/xmake/modules/core/tools/armcc.lua @@ -186,7 +186,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if depfile and os.isfile(depfile) then if dependinfo then - dependinfo.depfiles_armcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "armcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index dab766482..8a2971328 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -778,10 +778,12 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if dependinfo then if depfile and os.isfile(depfile) then - dependinfo.depfiles_cl_json = io.readfile(depfile) + dependinfo.depfiles_format = "cl_json" + dependinfo.depfiles = io.readfile(depfile) os.tryrm(depfile) elseif outdata then - dependinfo.depfiles_cl = outdata + dependinfo.depfiles_format = "cl" + dependinfo.depfiles = outdata end end end diff --git a/xmake/modules/core/tools/cl6x.lua b/xmake/modules/core/tools/cl6x.lua index 334df4798..f350808da 100644 --- a/xmake/modules/core/tools/cl6x.lua +++ b/xmake/modules/core/tools/cl6x.lua @@ -192,7 +192,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if depfile and os.isfile(depfile) then if dependinfo then - dependinfo.depfiles_cl6x = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "cl6x" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/clang_cl.lua b/xmake/modules/core/tools/clang_cl.lua index 694a05fcd..175bcff2a 100644 --- a/xmake/modules/core/tools/clang_cl.lua +++ b/xmake/modules/core/tools/clang_cl.lua @@ -216,6 +216,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if dependinfo and outdata then - dependinfo.depfiles_cl = outdata + dependinfo.depfiles_format = "cl" + dependinfo.depfiles = outdata end end diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 4a14acfac..47378c570 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -267,7 +267,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) if depfile and os.isfile(depfile) then if dependinfo then -- it use makefile/gcc compatiable format - dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 10ac810f3..4ca8a717c 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -987,7 +987,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if depfile and os.isfile(depfile) then if dependinfo then - dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index fdb305631..ea8c8704a 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -436,7 +436,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) if depfile and os.isfile(depfile) then if dependinfo then -- nvcc uses gcc-style depfiles - dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index 930fa4942..91c1984ca 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -157,7 +157,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) end file:close() if dependinfo then - dependinfo.depfiles_rc = depfiles_rc + dependinfo.depfiles_format = "rc" + dependinfo.depfiles = depfiles_rc end end os.tryrm(outfile) diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua index 6cbec5d43..ed2d55737 100644 --- a/xmake/modules/core/tools/sdcc.lua +++ b/xmake/modules/core/tools/sdcc.lua @@ -243,7 +243,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if depfile and os.isfile(depfile) then if dependinfo then - dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/modules/core/tools/tcc.lua b/xmake/modules/core/tools/tcc.lua index 8251f9f64..cb97d4c05 100644 --- a/xmake/modules/core/tools/tcc.lua +++ b/xmake/modules/core/tools/tcc.lua @@ -201,7 +201,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- generate the dependent includes if depfile and os.isfile(depfile) then if dependinfo then - dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = io.readfile(depfile, {continuation = "\\"}) end -- remove the temporary dependent file diff --git a/xmake/rules/swig/build_module_file.lua b/xmake/rules/swig/build_module_file.lua index 3e6af313f..2cb289302 100644 --- a/xmake/rules/swig/build_module_file.lua +++ b/xmake/rules/swig/build_module_file.lua @@ -182,7 +182,8 @@ function swig_build_file(target, sourcefile, opt, par) local deps = io.readfile(swigdep, {continuation = "\\"}) os.tryrm(swigdep) dependinfo.files = {sourcefile} - dependinfo.depfiles_gcc = deps + dependinfo.depfiles_format = "gcc" + dependinfo.depfiles = deps dependinfo.values = argv depend.save(dependinfo, target:dependfile(objectfile)) |
