Skip to content
Snippets Groups Projects
Commit 9e4820a8 authored by Virgile Prevosto's avatar Virgile Prevosto Committed by Andre Maroneze
Browse files

[machdeps] update schema: arch flags are a list, not a single string

Also allows script to update an existing machdep, by reusing its arch flags
parent 0d8adb85
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,8 @@
},
"cpp_arch_flags": {
"description": "arguments to be given to the compiler when this machdep is selected (e.g. '-m32')",
"type" : "string"
"type" : "array",
"items" : { "type": "string" }
},
"sizeof_short": {
"description": "size of 'short' type",
......
......@@ -12,7 +12,11 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "clang",
"cpp_arch_flags": "-target avr -m16",
"cpp_arch_flags": [
"-target",
"avr",
"-m16"
],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "int",
......
......@@ -12,7 +12,7 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "gcc",
"cpp_arch_flags": "-m16",
"cpp_arch_flags": ["-m16"],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "int",
......
......@@ -12,7 +12,9 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "gcc",
"cpp_arch_flags": "-m32",
"cpp_arch_flags": [
"-m32"
],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "int",
......
......@@ -12,8 +12,10 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "gcc",
"cpp_arch_flags": "-m64",
"has__builtin_va_list": false,
"cpp_arch_flags": [
"-m64"
],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "long",
"size_t": "unsigned long",
......
......@@ -12,7 +12,11 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "clang",
"cpp_arch_flags": "-target powerpc-apple-darwin -mcpu=603",
"cpp_arch_flags": [
"-target",
"powerpc-apple-darwin",
"-mcpu=603"
],
"has__builtin_va_list": false,
"little_endian": false,
"ptrdiff_t": "int",
......
......@@ -12,7 +12,7 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "generic",
"cpp_arch_flags": "-m16",
"cpp_arch_flags": [ "-m16" ],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "int",
......
......@@ -12,7 +12,9 @@
"alignof_str": 1,
"char_is_unsigned": false,
"compiler": "generic",
"cpp_arch_flags": "-m32",
"cpp_arch_flags": [
"-m32"
],
"has__builtin_va_list": true,
"little_endian": true,
"ptrdiff_t": "int",
......
......@@ -69,6 +69,17 @@ parser.add_argument(
default="--version",
help="option to pass to the compiler to obtain its version; default is --version",
)
parser.add_argument(
"--from-file",
help="reads compiler and arch flags from existing json file. Use -i to update it in place"
)
parser.add_argument(
"-i", "--in-place",
action="store_true",
help="when reading compiler config from json, update the file in place. unused otherwise"
)
parser.add_argument(
"--cpp-arch-flags",
nargs="+",
......@@ -90,10 +101,23 @@ if not args.compiler_flags:
args.compiler_flags = ["-c"]
if args.from_file:
orig_file = open(args.from_file,"r")
orig_machdep = json.load(orig_file)
orig_file.close()
if not "compiler" in orig_machdep or not "cpp_arch_flags" in orig_machdep:
raise Exception("Missing fields in json file")
args.compiler = orig_machdep["compiler"]
if isinstance(orig_machdep["cpp_arch_flags"],list):
args.cpp_arch_flags = orig_machdep["cpp_arch_flags"]
else: # old version of the schema used a single string
args.cpp_arch_flags = orig_machdep["cpp_arch_flags"].split()
def print_machdep(machdep):
if args.in_place:
args.dest_file = open(args.from_file,"w")
json.dump(machdep, args.dest_file, indent=4, sort_keys=True)
def check_machdep(machdep):
try:
from jsonschema import validate, ValidationError
......@@ -238,7 +262,7 @@ version_output = subprocess.run(
version = version_output.stdout.splitlines()[0]
machdep["compiler"] = args.compiler
machdep["cpp_arch_flags"] = " ".join(args.cpp_arch_flags)
machdep["cpp_arch_flags"] = args.cpp_arch_flags
machdep["version"] = version
missing_fields = [f for [f, v] in machdep.items() if v is None]
......
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