add check that generated .py files are in .gitignore
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 5 May 2023 00:55:15 +0000 (17:55 -0700)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:17 +0000 (19:51 +0100)
src/openpower/decoder/isa/.gitignore
src/openpower/decoder/power_pseudo.py
src/openpower/decoder/pseudo/pyfnwriter.py
src/openpower/decoder/pseudo/pywriter.py

index 4567f8c372b2793ae6653d48854cdcfef8213f3c..555dab2cdfc6a853b73e574be13862cfe0315ef5 100644 (file)
@@ -3,6 +3,7 @@
 /bcd.py
 /bitmanip.py
 /branch.py
+/butterfly.py
 /comparefixed.py
 /condition.py
 /fixedarith.py
index 637826bc02fc85da3f735b2a20f0e529e7b6e327..8feb80df4c7d21d0c2d777c0b7f37097dc3c9245 100644 (file)
@@ -8,7 +8,7 @@
 #             30 August 2006 / Cape Town, South Africa
 
 # Modifications for inclusion in PLY distribution
-import sys
+import os
 from pprint import pprint
 from copy import copy
 from ply import lex, yacc
@@ -282,6 +282,22 @@ def convert_to_python(pcode, form, incl_carry, helper=False, filename="string"):
     return astor.to_source(tree), regsused
 
 
+def check_in_gitignore(output_file):
+    gitignore_file = os.path.join(os.path.dirname(output_file), ".gitignore")
+    base_name = os.path.basename(output_file)
+    with open(gitignore_file, "r") as f:
+        for l in f.readlines():
+            l = l.strip()
+            if "/" + base_name == l:
+                return
+            if l == "*.py":
+                if base_name.endswith(".py"):
+                    return
+    raise ValueError(f"generated output file not in .gitignore:\n"
+                     f"output file: {output_file}\n"
+                     f".gitignore file: {gitignore_file}")
+
+
 def test():
 
     gsc = GardenSnakeCompiler(debug=True)
index 611c16eedd5d4d873247e3d27be7fd27351cc262..3560f782d39ceaa68341079e5e1be9cbf2e63ea1 100644 (file)
@@ -5,7 +5,8 @@ import sys
 import shutil
 import subprocess
 from openpower.decoder.pseudo.functionreader import ISAFunctions, get_isafn_dir
-from openpower.decoder.power_pseudo import convert_to_pure_python
+from openpower.decoder.power_pseudo import (convert_to_pure_python,
+                                            check_in_gitignore)
 
 
 def get_isafn_src_dir():
@@ -40,6 +41,7 @@ class PyISAFnWriter(ISAFunctions):
         os.makedirs(isadir, exist_ok=True)
         fname = os.path.join(isadir, "%s.py" % pagename)
         sourcecache = dict()
+        check_in_gitignore(fname)
         with open(fname, "w") as f:
             f.write(header % function['desc'])  # write out header
             # go through all instructions
index 49d51c098b3ae85db6b762c92979cc90c23becfc..e8ab004b5fd666ebdd86467498591db359863a10 100644 (file)
@@ -5,7 +5,8 @@ import sys
 import shutil
 import subprocess
 from openpower.decoder.pseudo.pagereader import ISA, get_isa_dir
-from openpower.decoder.power_pseudo import convert_to_python
+from openpower.decoder.power_pseudo import (convert_to_python,
+                                            check_in_gitignore)
 from openpower.decoder.orderedset import OrderedSet
 from openpower.decoder.isa.caller import create_args
 
@@ -61,6 +62,7 @@ class PyISAWriter(ISA):
         instrs = self.page[pagename]
         isadir = get_isasrc_dir()
         fname = os.path.join(isadir, "%s.py" % pagename)
+        check_in_gitignore(fname)
         with open(fname, "w") as f:
             iinf = ''
             # write headers: FP gets extra imports
@@ -134,7 +136,7 @@ class PyISAWriter(ISA):
     def write_isa_class(self):
         isadir = get_isasrc_dir()
         fname = os.path.join(isadir, "all.py")
-
+        check_in_gitignore(fname)
         with open(fname, "w") as f:
             f.write('# auto-generated by pywriter.py: do not edit or commit\n')
             f.write('from openpower.decoder.isa.caller import ISACaller\n')