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
b3c32994
Commit
b3c32994
authored
1 year ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
[machdep] better use of Python's stdlib in make_machdep
parent
3691bb78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
share/machdeps/make_machdep/make_machdep.py
+13
-11
13 additions, 11 deletions
share/machdeps/make_machdep/make_machdep.py
with
13 additions
and
11 deletions
share/machdeps/make_machdep/make_machdep.py
+
13
−
11
View file @
b3c32994
...
...
@@ -43,12 +43,14 @@ from pathlib import Path
import
re
import
subprocess
import
sys
import
warn
ing
s
import
logg
ing
import
yaml
from
yaml.representer
import
Representer
my_path
=
Path
(
sys
.
argv
[
0
]).
parent
logging
.
basicConfig
(
format
=
'
%(levelname)s: %(message)s
'
)
parser
=
argparse
.
ArgumentParser
(
prog
=
"
make_machdep
"
)
parser
.
add_argument
(
"
-v
"
,
"
--verbose
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
-o
"
,
type
=
argparse
.
FileType
(
"
w
"
),
dest
=
"
dest_file
"
)
...
...
@@ -119,10 +121,10 @@ def check_machdep(machdep):
validate
(
machdep
,
schema
)
return
True
except
ImportError
:
warn
ing
s
.
warn
(
"
jsonschema is not available: no validation will be performed
"
)
logg
ing
.
warn
ing
(
"
jsonschema is not available: no validation will be performed
"
)
return
True
except
ValidationError
:
warn
ing
s
.
warn
(
"
machdep object is not conforming to machdep schema
"
)
logg
ing
.
warn
ing
(
"
machdep object is not conforming to machdep schema
"
)
return
False
...
...
@@ -242,7 +244,7 @@ def find_value(name, typ, output):
default
=
""
else
:
warn
ing
s
.
warn
(
f
"
unexpected type
'
{
typ
}
'
for field
'
{
name
}
'
, skipping
"
)
logg
ing
.
warn
ing
(
f
"
unexpected type
'
{
typ
}
'
for field
'
{
name
}
'
, skipping
"
)
return
if
name
in
machdep
:
msg
=
re
.
compile
(
name
+
"
is
"
+
expected
)
...
...
@@ -253,12 +255,12 @@ def find_value(name, typ, output):
print
(
f
"
[INFO] setting
{
name
}
to
{
value
}
"
)
machdep
[
name
]
=
value
else
:
warn
ing
s
.
warn
(
f
"
cannot find value of field
'
{
name
}
'
, using default value:
'
{
default
}
'"
)
logg
ing
.
warn
ing
(
f
"
cannot find value of field
'
{
name
}
'
, using default value:
'
{
default
}
'"
,
stacklevel
=-
1
)
machdep
[
name
]
=
default
if
args
.
verbose
:
print
(
f
"
compiler output is:
{
output
}
"
)
else
:
warn
ing
s
.
warn
(
f
"
unexpected symbol
'
{
name
}
'
, ignoring
"
)
logg
ing
.
warn
ing
(
f
"
unexpected symbol
'
{
name
}
'
, ignoring
"
)
def
cleanup_cpp
(
output
):
...
...
@@ -284,7 +286,7 @@ def find_macros_value(output, is_list=False, entry=None):
print
(
f
"
[INFO] setting
{
name
}
to
{
value
}
"
)
machdep
[
name
]
=
value
else
:
warn
ing
s
.
warn
(
f
"
unexpected symbol
'
{
name
}
'
, ignoring
"
)
logg
ing
.
warn
ing
(
f
"
unexpected symbol
'
{
name
}
'
, ignoring
"
)
if
args
.
verbose
:
print
(
f
"
compiler output is:
{
output
}
"
)
...
...
@@ -302,7 +304,7 @@ for (f, typ) in source_files:
Path
(
f
).
with_suffix
(
"
.o
"
).
unlink
(
missing_ok
=
True
)
if
typ
==
"
macro
"
:
if
proc
.
returncode
!=
0
:
warn
ing
s
.
warn
(
f
"
error in preprocessing value
'
{
p
}
'
, some values won
'
t be filled
"
)
logg
ing
.
warn
ing
(
f
"
error in preprocessing value
'
{
p
}
'
, some values won
'
t be filled
"
)
if
args
.
verbose
:
print
(
f
"
compiler output is:
{
proc
.
stderr
.
decode
()
}
"
)
name
=
p
.
stem
...
...
@@ -314,7 +316,7 @@ for (f, typ) in source_files:
if
typ
==
"
macrolist
"
:
name
=
p
.
stem
if
proc
.
returncode
!=
0
:
warn
ing
s
.
warn
(
f
"
error in preprocessing value
'
{
p
}
'
, some value might not be filled
"
)
logg
ing
.
warn
ing
(
f
"
error in preprocessing value
'
{
p
}
'
, some value might not be filled
"
)
if
args
.
verbose
:
print
(
f
"
compiler output is:
{
proc
.
stderr
.
decode
()
}
"
)
if
name
in
machdep
:
...
...
@@ -329,7 +331,7 @@ for (f, typ) in source_files:
if
proc
.
returncode
==
0
:
# all tests should fail on an appropriate _Static_assert
# if compilation succeeds, we have a problem
warn
ing
s
.
warn
(
f
"
WARNING: could not identify value of
'
{
p
.
stem
}
'
, skipping
"
)
logg
ing
.
warn
ing
(
f
"
WARNING: could not identify value of
'
{
p
.
stem
}
'
, skipping
"
)
continue
find_value
(
p
.
stem
,
typ
,
proc
.
stderr
.
decode
())
...
...
@@ -387,7 +389,7 @@ if proc.returncode == 0:
lines
+=
f
"
{
line
.
strip
()
}
\n
"
machdep
[
"
custom_defs
"
]
=
custom_defs
(
lines
)
else
:
warn
ing
s
.
warn
(
"
could not determine predefined macros
"
)
logg
ing
.
warn
ing
(
"
could not determine predefined macros
"
)
if
args
.
verbose
:
print
(
f
"
compiler output is:
{
proc
.
stderr
}
"
)
...
...
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