summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDiederik de Groot <ddegroot@talon.nl>2017-04-21 16:39:03 +0200
committerDiederik de Groot <ddegroot@talon.nl>2017-04-21 16:39:03 +0200
commit50f03f595092b2976f263592ee8cfef0aa02258c (patch)
tree521b0c71a3ad687676b2c4f6bb3147aecb48afd5 /scripts
parent5570748dd27e5b1e8c109b80fb31500fcd8f7fad (diff)
Enh: scripts/MakeHeader script
Only write a new .h file if something changed for the header file being created. This prevents a lot of recompilation during development
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/MakeHeader.py57
1 files changed, 33 insertions, 24 deletions
diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py
index bcf1005a..a9a5f205 100755
--- a/scripts/MakeHeader.py
+++ b/scripts/MakeHeader.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python
-
import os, sys, string
+try:
+ from cStringIO import StringIO
+except:
+ from StringIO import StringIO
ANY=1
COPY=2
@@ -13,23 +16,15 @@ static = 0
file = open(sys.argv[1])
name = sys.argv[1][:-2]
-out = open(name + ".h", "w")
-class writer:
- def __init__(self, file):
- self.file = file
- def write(self, text):
- self.file.write(text + "\n")
-out = writer(out)
-
-print("Generating "+name+".h")
+out = StringIO()
selfheader = '#include "' + name + '.h"'
-out.write( "/* Do not edit this file. It was automatically generated. */" )
-out.write( "" )
+out.write( "/* Do not edit this file. It was automatically generated. */\n" )
+out.write( "\n" )
-out.write( "#ifndef HEADER_" + os.path.basename(name) )
-out.write( "#define HEADER_" + os.path.basename(name) )
+out.write( "#ifndef HEADER_" + os.path.basename(name) + "\n")
+out.write( "#define HEADER_" + os.path.basename(name) + "\n")
is_blank = False
for line in file.readlines():
line = line[:-1]
@@ -41,7 +36,7 @@ for line in file.readlines():
elif line.find("#include") == 0:
pass
elif line.find("htop - ") == 0 and line[-2:] == ".c":
- out.write(line[:-2] + ".h")
+ out.write(line[:-2] + ".h\n")
elif line.find("static ") != -1:
if line[-1] == "{":
state = SKIP
@@ -52,31 +47,31 @@ for line in file.readlines():
static = 0
equals = line.find(" = ")
if line[-3:] == "= {":
- out.write( "extern " + line[:-4] + ";" )
+ out.write( "extern " + line[:-4] + ";\n" )
state = SKIP
elif equals != -1:
- out.write("extern " + line[:equals] + ";" )
+ out.write("extern " + line[:equals] + ";\n" )
elif line.startswith("typedef struct"):
state = SKIP
elif line[-1] == "{":
- out.write( line[:-2].replace("inline", "extern") + ";" )
+ out.write( line[:-2].replace("inline", "extern") + ";\n" )
state = SKIP
else:
- out.write( line )
+ out.write( line + "\n")
is_blank = False
elif line == "":
if not is_blank:
- out.write( line )
+ out.write( line + "\n")
is_blank = True
else:
- out.write( line )
+ out.write( line + "\n")
is_blank = False
elif state == COPY:
is_blank = False
if line == "}*/":
state = ANY
else:
- out.write( line )
+ out.write( line + "\n")
elif state == SKIP:
is_blank = False
if len(line) >= 1 and line[0] == "}":
@@ -89,5 +84,19 @@ for line in file.readlines():
is_blank = False
state = ANY
-out.write( "" )
-out.write( "#endif" )
+out.write( "\n" )
+out.write( "#endif\n" )
+
+# only write a new .h file if something changed.
+# This prevents a lot of recompilation during development
+out.seek(0)
+try:
+ with open(name + ".h", "r") as orig:
+ origcontents = orig.readlines()
+except:
+ origcontents = ""
+if origcontents != out.readlines():
+ with open(name + ".h", "w") as new:
+ print("Writing "+name+".h")
+ new.write(out.getvalue())
+out.close()

© 2014-2024 Faster IT GmbH | imprint | privacy policy