FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
binder-trace/kernel/scripts/generate_compdb.py at master · CKAndroidProject/binder-trace · GitHub
CKAndroidProject
/
binder-trace
Public
forked from
fuqiuluo/binder-trace
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
binder-trace
/
kernel
/
scripts
/
generate_compdb.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
93 lines (67 loc) · 2.88 KB
Breadcrumbs
binder-trace
/
kernel
/
scripts
/
generate_compdb.py
Copy path
File metadata and controls
executable file
·
93 lines (67 loc) · 2.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
from
__future__
import
print_function
,
division
import
argparse
import
fnmatch
import
functools
import
json
import
math
import
multiprocessing
import
os
import
re
import
sys
CMD_VAR_RE
=
re
.
compile
(
r'^\s*(?:saved)?cmd_(\S+)\s*:=\s*(.+)\s*$'
,
re
.
MULTILINE
)
SOURCE_VAR_RE
=
re
.
compile
(
r'^\s*source_(\S+)\s*:=\s*(.+)\s*$'
,
re
.
MULTILINE
)
def
print_progress_bar
(
progress
):
progress_bar
=
'['
+
'|'
*
int
(
50
*
progress
)
+
'-'
*
int
(
50
*
(
1.0
-
progress
))
+
']'
print
(
'
\r
'
,
progress_bar
,
"{0:.1%}"
.
format
(
progress
),
end
=
'
\r
'
,
file
=
sys
.
stderr
)
def
parse_cmd_file
(
out_dir
,
cmdfile_path
):
with
open
(
cmdfile_path
,
'r'
)
as
cmdfile
:
cmdfile_content
=
cmdfile
.
read
()
commands
=
{
match
.
group
(
1
):
match
.
group
(
2
)
for
match
in
CMD_VAR_RE
.
finditer
(
cmdfile_content
) }
sources
=
{
match
.
group
(
1
):
match
.
group
(
2
)
for
match
in
SOURCE_VAR_RE
.
finditer
(
cmdfile_content
) }
return
[{
'directory'
:
out_dir
,
'command'
:
commands
[
o_file_name
],
'file'
:
source
,
'output'
:
o_file_name
}
for
o_file_name
,
source
in
sources
.
items
()]
def
gen_compile_commands
(
cmd_file_search_path
,
out_dir
):
print
(
"正在收集 *.o.cmd 文件列表..."
,
file
=
sys
.
stderr
)
out_dir
=
os
.
path
.
abspath
(
out_dir
)
if
not
cmd_file_search_path
:
cmd_file_search_path
=
[
out_dir
]
cmd_files
=
[]
for
search_path
in
cmd_file_search_path
:
if
(
os
.
path
.
isdir
(
search_path
)):
for
cur_dir
,
subdir
,
files
in
os
.
walk
(
search_path
):
cmd_files
.
extend
(
os
.
path
.
join
(
cur_dir
,
cmdfile_name
)
for
cmdfile_name
in
fnmatch
.
filter
(
files
,
'*.o.cmd'
))
else
:
cmd_files
.
extend
(
search_path
)
if
not
cmd_files
:
print
(
"没有找到 *.o.cmd 文件:"
,
", "
.
join
(
cmd_file_search_path
),
file
=
sys
.
stderr
)
return
print
(
"正在解析 *.o.cmd 文件..."
,
file
=
sys
.
stderr
)
n_processed
=
0
print_progress_bar
(
0
)
compdb
=
[]
pool
=
multiprocessing
.
Pool
()
try
:
for
compdb_chunk
in
pool
.
imap_unordered
(
functools
.
partial
(
parse_cmd_file
,
out_dir
),
cmd_files
,
chunksize
=
int
(
math
.
sqrt
(
len
(
cmd_files
)))):
compdb
.
extend
(
compdb_chunk
)
n_processed
+=
1
print_progress_bar
(
n_processed
/
len
(
cmd_files
))
finally
:
pool
.
terminate
()
pool
.
join
()
print
(
file
=
sys
.
stderr
)
print
(
"正在写入 compile_commands.json..."
,
file
=
sys
.
stderr
)
with
open
(
'compile_commands.json'
,
'w'
)
as
compdb_file
:
json
.
dump
(
compdb
,
compdb_file
,
indent
=
1
)
def
main
():
cmd_parser
=
argparse
.
ArgumentParser
()
cmd_parser
.
add_argument
(
'-O'
,
'--out-dir'
,
type
=
str
,
default
=
os
.
getcwd
(),
help
=
"构建输出目录"
)
cmd_parser
.
add_argument
(
'cmd_file_search_path'
,
nargs
=
'*'
,
help
=
"*.cmd 文件搜索路径"
)
gen_compile_commands
(
**
vars
(
cmd_parser
.
parse_args
()))
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL