Skip to content
Snippets Groups Projects
Commit b3c32994 authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[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
...@@ -43,12 +43,14 @@ from pathlib import Path ...@@ -43,12 +43,14 @@ from pathlib import Path
import re import re
import subprocess import subprocess
import sys import sys
import warnings import logging
import yaml import yaml
from yaml.representer import Representer from yaml.representer import Representer
my_path = Path(sys.argv[0]).parent my_path = Path(sys.argv[0]).parent
logging.basicConfig(format='%(levelname)s: %(message)s')
parser = argparse.ArgumentParser(prog="make_machdep") parser = argparse.ArgumentParser(prog="make_machdep")
parser.add_argument("-v", "--verbose", action="store_true") parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-o", type=argparse.FileType("w"), dest="dest_file") parser.add_argument("-o", type=argparse.FileType("w"), dest="dest_file")
...@@ -119,10 +121,10 @@ def check_machdep(machdep): ...@@ -119,10 +121,10 @@ def check_machdep(machdep):
validate(machdep, schema) validate(machdep, schema)
return True return True
except ImportError: except ImportError:
warnings.warn("jsonschema is not available: no validation will be performed") logging.warning("jsonschema is not available: no validation will be performed")
return True return True
except ValidationError: except ValidationError:
warnings.warn("machdep object is not conforming to machdep schema") logging.warning("machdep object is not conforming to machdep schema")
return False return False
...@@ -242,7 +244,7 @@ def find_value(name, typ, output): ...@@ -242,7 +244,7 @@ def find_value(name, typ, output):
default = "" default = ""
else: else:
warnings.warn(f"unexpected type '{typ}' for field '{name}', skipping") logging.warning(f"unexpected type '{typ}' for field '{name}', skipping")
return return
if name in machdep: if name in machdep:
msg = re.compile(name + " is " + expected) msg = re.compile(name + " is " + expected)
...@@ -253,12 +255,12 @@ def find_value(name, typ, output): ...@@ -253,12 +255,12 @@ def find_value(name, typ, output):
print(f"[INFO] setting {name} to {value}") print(f"[INFO] setting {name} to {value}")
machdep[name] = value machdep[name] = value
else: else:
warnings.warn(f"cannot find value of field '{name}', using default value: '{default}'") logging.warning(f"cannot find value of field '{name}', using default value: '{default}'",stacklevel=-1)
machdep[name] = default machdep[name] = default
if args.verbose: if args.verbose:
print(f"compiler output is:{output}") print(f"compiler output is:{output}")
else: else:
warnings.warn(f"unexpected symbol '{name}', ignoring") logging.warning(f"unexpected symbol '{name}', ignoring")
def cleanup_cpp(output): def cleanup_cpp(output):
...@@ -284,7 +286,7 @@ def find_macros_value(output, is_list=False, entry=None): ...@@ -284,7 +286,7 @@ def find_macros_value(output, is_list=False, entry=None):
print(f"[INFO] setting {name} to {value}") print(f"[INFO] setting {name} to {value}")
machdep[name] = value machdep[name] = value
else: else:
warnings.warn(f"unexpected symbol '{name}', ignoring") logging.warning(f"unexpected symbol '{name}', ignoring")
if args.verbose: if args.verbose:
print(f"compiler output is:{output}") print(f"compiler output is:{output}")
...@@ -302,7 +304,7 @@ for (f, typ) in source_files: ...@@ -302,7 +304,7 @@ for (f, typ) in source_files:
Path(f).with_suffix(".o").unlink(missing_ok=True) Path(f).with_suffix(".o").unlink(missing_ok=True)
if typ == "macro": if typ == "macro":
if proc.returncode != 0: if proc.returncode != 0:
warnings.warn(f"error in preprocessing value '{p}', some values won't be filled") logging.warning(f"error in preprocessing value '{p}', some values won't be filled")
if args.verbose: if args.verbose:
print(f"compiler output is:{proc.stderr.decode()}") print(f"compiler output is:{proc.stderr.decode()}")
name = p.stem name = p.stem
...@@ -314,7 +316,7 @@ for (f, typ) in source_files: ...@@ -314,7 +316,7 @@ for (f, typ) in source_files:
if typ == "macrolist": if typ == "macrolist":
name = p.stem name = p.stem
if proc.returncode != 0: if proc.returncode != 0:
warnings.warn(f"error in preprocessing value '{p}', some value might not be filled") logging.warning(f"error in preprocessing value '{p}', some value might not be filled")
if args.verbose: if args.verbose:
print(f"compiler output is:{proc.stderr.decode()}") print(f"compiler output is:{proc.stderr.decode()}")
if name in machdep: if name in machdep:
...@@ -329,7 +331,7 @@ for (f, typ) in source_files: ...@@ -329,7 +331,7 @@ for (f, typ) in source_files:
if proc.returncode == 0: if proc.returncode == 0:
# all tests should fail on an appropriate _Static_assert # all tests should fail on an appropriate _Static_assert
# if compilation succeeds, we have a problem # if compilation succeeds, we have a problem
warnings.warn(f"WARNING: could not identify value of '{p.stem}', skipping") logging.warning(f"WARNING: could not identify value of '{p.stem}', skipping")
continue continue
find_value(p.stem, typ, proc.stderr.decode()) find_value(p.stem, typ, proc.stderr.decode())
...@@ -387,7 +389,7 @@ if proc.returncode == 0: ...@@ -387,7 +389,7 @@ if proc.returncode == 0:
lines += f"{line.strip()}\n" lines += f"{line.strip()}\n"
machdep["custom_defs"] = custom_defs(lines) machdep["custom_defs"] = custom_defs(lines)
else: else:
warnings.warn("could not determine predefined macros") logging.warning("could not determine predefined macros")
if args.verbose: if args.verbose:
print(f"compiler output is:{proc.stderr}") print(f"compiler output is:{proc.stderr}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment