From cf960dbb6579f19874b59b6b8a34d3ab31b2580a Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Wed, 22 Feb 2023 19:02:01 +0100
Subject: [PATCH] [machdep] generator ends the file with a proper \n + pass
 lint and headers

---
 .gitattributes                              |  2 +-
 share/machdeps/machdep_avr_16.json          |  2 +-
 share/machdeps/machdep_gcc_x86_32.json      |  2 +-
 share/machdeps/machdep_gcc_x86_64.json      |  2 +-
 share/machdeps/machdep_ppc_32.json          |  2 +-
 share/machdeps/make_machdep/make_machdep.py | 19 ++++++++++++-------
 6 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index b56c468b60c..31a62b58ca5 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -267,7 +267,7 @@ README* header_spec=.ignore
 /share/win32_manual_installation_step.txt header_spec=.ignore
 /share/compliance/*.json header_spec=.ignore
 /share/machdeps/machdep-schema.json header_spec=.ignore
-
+/share/machdeps/machdep_*.json header_spec=.ignore
 /tests/**/* header_spec=.ignore
 
 #######################
diff --git a/share/machdeps/machdep_avr_16.json b/share/machdeps/machdep_avr_16.json
index 785839a0b5a..73c347759aa 100644
--- a/share/machdeps/machdep_avr_16.json
+++ b/share/machdeps/machdep_avr_16.json
@@ -33,4 +33,4 @@
     "sizeof_void": 1,
     "version": "clang version 15.0.7",
     "wchar_t": "int"
-}
\ No newline at end of file
+}
diff --git a/share/machdeps/machdep_gcc_x86_32.json b/share/machdeps/machdep_gcc_x86_32.json
index f7030722574..242baf3bcf9 100644
--- a/share/machdeps/machdep_gcc_x86_32.json
+++ b/share/machdeps/machdep_gcc_x86_32.json
@@ -31,4 +31,4 @@
     "sizeof_void": 1,
     "version": "gcc (GCC) 12.2.1 20230201",
     "wchar_t": "long"
-}
\ No newline at end of file
+}
diff --git a/share/machdeps/machdep_gcc_x86_64.json b/share/machdeps/machdep_gcc_x86_64.json
index 28932cf951b..426898d9c08 100644
--- a/share/machdeps/machdep_gcc_x86_64.json
+++ b/share/machdeps/machdep_gcc_x86_64.json
@@ -31,4 +31,4 @@
     "sizeof_void": 1,
     "version": "gcc (GCC) 12.2.1 20230201",
     "wchar_t": "int"
-}
\ No newline at end of file
+}
diff --git a/share/machdeps/machdep_ppc_32.json b/share/machdeps/machdep_ppc_32.json
index 610cbb38fab..aec4b71b5ba 100644
--- a/share/machdeps/machdep_ppc_32.json
+++ b/share/machdeps/machdep_ppc_32.json
@@ -33,4 +33,4 @@
     "sizeof_void": 1,
     "version": "clang version 15.0.7",
     "wchar_t": "int"
-}
\ No newline at end of file
+}
diff --git a/share/machdeps/make_machdep/make_machdep.py b/share/machdeps/make_machdep/make_machdep.py
index a5fbaa1eaea..a4295c73770 100755
--- a/share/machdeps/make_machdep/make_machdep.py
+++ b/share/machdeps/make_machdep/make_machdep.py
@@ -72,12 +72,13 @@ parser.add_argument(
 
 parser.add_argument(
     "--from-file",
-    help="reads compiler and arch flags from existing json file. Use -i to update it in place"
+    help="reads compiler and arch flags from existing json file. Use -i to update it in place",
 )
 parser.add_argument(
-    "-i", "--in-place",
+    "-i",
+    "--in-place",
     action="store_true",
-    help="when reading compiler config from json, update the file in place. unused otherwise"
+    help="when reading compiler config from json, update the file in place. unused otherwise",
 )
 
 parser.add_argument(
@@ -102,21 +103,25 @@ if not args.compiler_flags:
 
 
 if args.from_file:
-    orig_file = open(args.from_file,"r")
+    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):
+    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
+    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")
+        args.dest_file = open(args.from_file, "w")
     json.dump(machdep, args.dest_file, indent=4, sort_keys=True)
+    # Python does not end the dump with a newline by itself
+    args.dest_file.write("\n")
+
 
 def check_machdep(machdep):
     try:
-- 
GitLab