From f6303f591c1a968dfc505da386d8634dab06170a Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 4 May 2023 17:55:15 -0700 Subject: [PATCH] add check that generated .py files are in .gitignore --- src/openpower/decoder/isa/.gitignore | 1 + src/openpower/decoder/power_pseudo.py | 18 +++++++++++++++++- src/openpower/decoder/pseudo/pyfnwriter.py | 4 +++- src/openpower/decoder/pseudo/pywriter.py | 6 ++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/openpower/decoder/isa/.gitignore b/src/openpower/decoder/isa/.gitignore index 4567f8c3..555dab2c 100644 --- a/src/openpower/decoder/isa/.gitignore +++ b/src/openpower/decoder/isa/.gitignore @@ -3,6 +3,7 @@ /bcd.py /bitmanip.py /branch.py +/butterfly.py /comparefixed.py /condition.py /fixedarith.py diff --git a/src/openpower/decoder/power_pseudo.py b/src/openpower/decoder/power_pseudo.py index 637826bc..8feb80df 100644 --- a/src/openpower/decoder/power_pseudo.py +++ b/src/openpower/decoder/power_pseudo.py @@ -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) diff --git a/src/openpower/decoder/pseudo/pyfnwriter.py b/src/openpower/decoder/pseudo/pyfnwriter.py index 611c16ee..3560f782 100644 --- a/src/openpower/decoder/pseudo/pyfnwriter.py +++ b/src/openpower/decoder/pseudo/pyfnwriter.py @@ -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 diff --git a/src/openpower/decoder/pseudo/pywriter.py b/src/openpower/decoder/pseudo/pywriter.py index 49d51c09..e8ab004b 100644 --- a/src/openpower/decoder/pseudo/pywriter.py +++ b/src/openpower/decoder/pseudo/pywriter.py @@ -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') -- 2.30.2