Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
49eaa67c
Commit
49eaa67c
authored
4 years ago
by
Andre Maroneze
Browse files
Options
Downloads
Patches
Plain Diff
[Analysis-scripts] update list-files
parent
8bcc8742
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
share/analysis-scripts/list_files.py
+32
-21
32 additions, 21 deletions
share/analysis-scripts/list_files.py
tests/fc_script/oracle/list_files.res
+7
-6
7 additions, 6 deletions
tests/fc_script/oracle/list_files.res
tests/jcdb/oracle/list_files.res
+5
-4
5 additions, 4 deletions
tests/jcdb/oracle/list_files.res
with
44 additions
and
31 deletions
share/analysis-scripts/list_files.py
+
32
−
21
View file @
49eaa67c
...
@@ -31,58 +31,69 @@ import sys
...
@@ -31,58 +31,69 @@ import sys
import
os
import
os
import
json
import
json
import
re
import
re
from
pathlib
import
Path
MIN_PYTHON
=
(
3
,
6
)
# for glob(recursive) and automatic Path conversions
if
sys
.
version_info
<
MIN_PYTHON
:
sys
.
exit
(
"
Python %s.%s or later is required.
\n
"
%
MIN_PYTHON
)
arg
=
""
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
# no argument, assume default name
# no argument, assume default name
arg
=
"
compile_commands.json
"
arg
=
Path
(
"
compile_commands.json
"
)
else
:
else
:
arg
=
sys
.
argv
[
1
]
arg
=
Path
(
sys
.
argv
[
1
]
)
if
not
os
.
path
.
exists
(
arg
):
if
not
arg
.
exists
():
print
(
f
"
error: file
'
{
arg
}
'
not found
"
)
print
(
f
"
error: file
'
{
arg
}
'
not found
"
)
sys
.
exit
(
f
"
usage:
{
sys
.
argv
[
0
]
}
[compile_commands.json]
"
)
sys
.
exit
(
f
"
usage:
{
sys
.
argv
[
0
]
}
[compile_commands.json]
"
)
# check if arg has a known extension
# check if arg has a known extension
def
ha
s_known_c_extension
(
arg
):
def
i
s_known_c_extension
(
ext
):
return
arg
.
endswith
(
"
.c
"
)
or
arg
.
endswith
(
"
.i
"
)
or
arg
.
endswith
(
"
.h
"
)
return
ext
==
"
.c
"
or
ext
==
"
.i
"
or
ext
==
"
.h
"
pwd
=
os
.
getcwd
()
pwd
=
os
.
getcwd
()
fcmake_pwd
=
pwd
/
Path
(
"
.frama-c
"
)
# pwd as seen by the Frama-C makefile
json
=
json
.
loads
(
open
(
arg
).
read
())
json
=
json
.
loads
(
open
(
arg
).
read
())
jcdb_dir
=
os
.
path
.
dirname
(
arg
)
jcdb_dir
=
arg
.
parent
includes
=
set
()
includes
=
set
()
defines
=
set
()
defines
=
set
()
files
=
set
()
files
=
set
()
# set of pairs of (file, file_for_fcmake)
for
entry
in
json
:
for
entry
in
json
:
arg_includes
=
[]
# before normalization
arg_includes
=
[]
# before normalization
dir
=
entry
[
"
directory
"
]
if
not
"
file
"
in
entry
:
file
=
entry
[
"
file
"
]
# ignore entries without a filename
# json compile spec says either command or arguments are mandatory
continue
if
os
.
path
.
isabs
(
file
):
file
=
Path
(
entry
[
"
file
"
])
dir
=
Path
(
entry
[
"
directory
"
])
if
"
directory
"
in
entry
else
None
if
file
.
is_absolute
():
filepath
=
file
filepath
=
file
elif
os
.
path
.
isabs
(
dir
):
elif
dir
and
dir
.
is_absolute
():
filepath
=
os
.
path
.
join
(
dir
,
file
)
filepath
=
dir
/
file
elif
dir
:
filepath
=
jcdb_dir
/
dir
/
file
else
:
else
:
filepath
=
os
.
path
.
join
(
jcdb_dir
,
dir
,
file
)
filepath
=
jcdb_dir
/
file
if
not
ha
s_known_c_extension
(
filepath
):
if
not
i
s_known_c_extension
(
filepath
.
suffix
):
print
(
f
"
warning: ignoring file of unknown type:
{
filepath
}
"
)
print
(
f
"
warning: ignoring file of unknown type:
{
filepath
}
"
)
else
:
else
:
files
.
add
(
os
.
path
.
relpath
(
filepath
,
pwd
))
files
.
add
(
(
os
.
path
.
relpath
(
filepath
,
pwd
)
,
os
.
path
.
relpath
(
filepath
,
fcmake_pwd
))
)
print
(
"
SRCS=
\\\n
"
+
"
\\\n
"
.
join
(
sorted
(
files
))
+
"
\\
"
)
files_for_fcmake
=
map
(
lambda
x
:(
x
[
1
]),
files
)
print
(
"
# Paths as seen by a makefile inside subdirectory
'
.frama-c
'
:
"
)
print
(
"
SRCS=
\\\n
"
+
"
\\\n
"
.
join
(
sorted
(
files_for_fcmake
))
+
"
\\
"
)
print
(
""
)
print
(
""
)
files_defining_main
=
set
()
files_defining_main
=
set
()
re_main
=
re
.
compile
(
"
(int|void)\s+main\s*\([^)]*\)\s*\{
"
)
re_main
=
re
.
compile
(
"
(int|void)\s+main\s*\([^)]*\)\s*\{
"
)
for
file
in
files
:
for
(
file
,
file_for_fcmake
)
in
files
:
assert
os
.
path
.
exists
(
file
),
"
file does not exist: %s
"
%
file
assert
os
.
path
.
exists
(
file
),
"
file does not exist: %s
"
%
file
with
open
(
file
,
'
r
'
)
as
content_file
:
with
open
(
file
,
'
r
'
)
as
content_file
:
content
=
content_file
.
read
()
content
=
content_file
.
read
()
res
=
re
.
search
(
re_main
,
content
)
res
=
re
.
search
(
re_main
,
content
)
if
res
is
not
None
:
if
res
is
not
None
:
files_defining_main
.
add
(
file
)
files_defining_main
.
add
(
file
_for_fcmake
)
if
files_defining_main
!=
[]:
if
files_defining_main
!=
[]:
print
(
""
)
print
(
""
)
print
(
"
# Possible definition of main function in the following file(s):
"
)
print
(
"
# Possible definition of main function in the following file(s)
, as seen from
'
.frama-c
'
:
"
)
print
(
"
\n
"
.
join
(
sorted
(
files_defining_main
)))
print
(
"
\n
"
.
join
(
sorted
(
files_defining_main
)))
This diff is collapsed.
Click to expand it.
tests/fc_script/oracle/list_files.res
+
7
−
6
View file @
49eaa67c
#
Paths
as
seen
by
a
makefile
inside
subdirectory
'
.
frama
-
c'
:
SRCS
=
\
SRCS
=
\
tests
/
fc_script
/
main
.
c
\
..
/
tests
/
fc_script
/
main
.
c
\
tests
/
fc_script
/
main2
.
c
\
..
/
tests
/
fc_script
/
main2
.
c
\
tests
/
fc_script
/
main3
.
c
\
..
/
tests
/
fc_script
/
main3
.
c
\
#
Possible
definition
of
main
function
in
the
following
file
(
s
)
:
#
Possible
definition
of
main
function
in
the
following
file
(
s
)
,
as
seen
from
'
.
frama
-
c'
:
tests
/
fc_script
/
main
.
c
..
/
tests
/
fc_script
/
main
.
c
tests
/
fc_script
/
main3
.
c
..
/
tests
/
fc_script
/
main3
.
c
This diff is collapsed.
Click to expand it.
tests/jcdb/oracle/list_files.res
+
5
−
4
View file @
49eaa67c
#
Paths
as
seen
by
a
makefile
inside
subdirectory
'
.
frama
-
c'
:
SRCS
=
\
SRCS
=
\
tests
/
jcdb
/
file_without_main
.
c
\
..
/
tests
/
jcdb
/
file_without_main
.
c
\
tests
/
jcdb
/
jcdb
.
c
\
..
/
tests
/
jcdb
/
jcdb
.
c
\
#
Possible
definition
of
main
function
in
the
following
file
(
s
)
:
#
Possible
definition
of
main
function
in
the
following
file
(
s
)
,
as
seen
from
'
.
frama
-
c'
:
tests
/
jcdb
/
jcdb
.
c
..
/
tests
/
jcdb
/
jcdb
.
c
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment