Skip to content

Commit 4a1dd4e

Browse files
committed
add cl6x deps parser
1 parent 8a4e42c commit 4a1dd4e

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

xmake/modules/core/project/depend.lua

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import("private.tools.cl.parse_deps_json", {alias = "parse_deps_cl_json"})
2626
import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"})
2727
import("private.tools.gcc.parse_deps", {alias = "parse_deps_gcc"})
2828
import("private.tools.armcc.parse_deps", {alias = "parse_deps_armcc"})
29+
import("private.tools.cl6x.parse_deps", {alias = "parse_deps_cl6x"})
2930

3031
-- load depfiles
3132
function _load_depfiles(parser, dependinfo, depfiles, opt)
@@ -62,6 +63,9 @@ function load(dependfile, opt)
6263
elseif dependinfo.depfiles_armcc then
6364
_load_depfiles(parse_deps_armcc, dependinfo, dependinfo.depfiles_armcc, opt)
6465
dependinfo.depfiles_armcc = nil
66+
elseif dependinfo.depfiles_cl6x then
67+
_load_depfiles(parse_deps_cl6x, dependinfo, dependinfo.depfiles_cl6x, opt)
68+
dependinfo.depfiles_cl6x = nil
6569
end
6670
return dependinfo
6771
end

xmake/modules/core/tools/cl6x.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
192192
-- generate the dependent includes
193193
if depfile and os.isfile(depfile) then
194194
if dependinfo then
195-
dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
195+
dependinfo.depfiles_cl6x = io.readfile(depfile, {continuation = "\\"})
196196
end
197197

198198
-- remove the temporary dependent file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file parse_deps.lua
19+
--
20+
21+
-- imports
22+
import("core.project.config")
23+
import("core.project.project")
24+
import("core.base.hashset")
25+
26+
-- normailize path of a dependecy
27+
function _normailize_dep(dep, projectdir)
28+
-- escape characters, e.g. \#Qt.Widget_pch.h -> #Qt.Widget_pch.h
29+
-- @see https://github.com/xmake-io/xmake/issues/4134
30+
-- https://github.com/xmake-io/xmake/issues/4273
31+
if not is_host("windows") then
32+
dep = dep:gsub("\\(.)", "%1")
33+
end
34+
if path.is_absolute(dep) then
35+
dep = path.translate(dep)
36+
else
37+
dep = path.absolute(dep, projectdir)
38+
end
39+
if dep:startswith(projectdir) then
40+
return path.relative(dep, projectdir)
41+
else
42+
-- we also need to check header files outside project
43+
-- https://github.com/xmake-io/xmake/issues/1154
44+
return dep
45+
end
46+
end
47+
48+
-- parse depsfiles from string
49+
--
50+
-- parse_deps(io.readfile(depfile, {continuation = "\\"}))
51+
--
52+
-- eg.
53+
--
54+
-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.c
55+
-- build/.objs/foo/linux/x86_64/release/src/foo.c.o: src/foo.h
56+
--
57+
-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/main.c
58+
-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/foo.h
59+
-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/bar.h
60+
-- build/.objs/tests/linux/x86_64/release/src/main.c.o: src/zoo.h
61+
--
62+
function main(depsdata, opt)
63+
local results = hashset.new()
64+
local projectdir = os.projectdir()
65+
local line = depsdata:rtrim() -- maybe there will be an empty newline at the end. so we trim it first
66+
local plain = {plain = true}
67+
for _, includefile in ipairs(line:split('\n', plain)) do -- it will trim all internal spaces without `{strict = true}`
68+
includefile = includefile:split(": ", plain)[2]
69+
if includefile and #includefile > 0 then
70+
includefile = _normailize_dep(includefile, projectdir)
71+
if includefile then
72+
results:insert(includefile)
73+
end
74+
end
75+
end
76+
return results:to_array()
77+
end

0 commit comments

Comments
 (0)