From f577d02f4a750e462814d385e416c9fd45986d1e Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 20 Jan 2022 14:39:48 -0800 Subject: [PATCH] [reorg] Fix check-* scripts to work with sources files in directories. --- src/Makefile.sources | 4 ++++ src/OT/Layout/GSUB/Common.hh | 6 +++--- src/OT/Layout/GSUB/SingleSubst.hh | 6 +++--- src/OT/Layout/GSUB/SingleSubstFormat1.hh | 6 +++--- src/OT/Layout/GSUB/SingleSubstFormat2.hh | 6 +++--- src/check-c-linkage-decls.py | 14 +++++++++++--- src/check-header-guards.py | 19 +++++++++++++++---- src/check-includes.py | 17 ++++++++++++++--- 8 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/Makefile.sources b/src/Makefile.sources index 40fbd99a6..77fa85bfc 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -88,6 +88,10 @@ HB_BASE_sources = \ hb-ot-layout-gdef-table.hh \ hb-ot-layout-gpos-table.hh \ hb-ot-layout-gsub-table.hh \ + OT/Layout/GSUB/Common.hh \ + OT/Layout/GSUB/SingleSubstFormat1.hh \ + OT/Layout/GSUB/SingleSubstFormat2.hh \ + OT/Layout/GSUB/SingleSubst.hh \ hb-ot-layout-gsubgpos.hh \ hb-ot-layout-jstf-table.hh \ hb-ot-layout.cc \ diff --git a/src/OT/Layout/GSUB/Common.hh b/src/OT/Layout/GSUB/Common.hh index 951c278d0..f02375715 100644 --- a/src/OT/Layout/GSUB/Common.hh +++ b/src/OT/Layout/GSUB/Common.hh @@ -1,5 +1,5 @@ -#ifndef OT_LAYOUT_GSUB_COMMON -#define OT_LAYOUT_GSUB_COMMON +#ifndef OT_LAYOUT_GSUB_COMMON_HH +#define OT_LAYOUT_GSUB_COMMON_HH #include "hb-serialize.hh" @@ -17,4 +17,4 @@ static void SingleSubst_serialize (hb_serialize_context_t *c, } } -#endif +#endif /* OT_LAYOUT_GSUB_COMMON_HH */ diff --git a/src/OT/Layout/GSUB/SingleSubst.hh b/src/OT/Layout/GSUB/SingleSubst.hh index f1e88b3f8..c30d860c1 100644 --- a/src/OT/Layout/GSUB/SingleSubst.hh +++ b/src/OT/Layout/GSUB/SingleSubst.hh @@ -1,5 +1,5 @@ -#ifndef OT_LAYOUT_GSUB_SINGLE_SUBST -#define OT_LAYOUT_GSUB_SINGLE_SUBST +#ifndef OT_LAYOUT_GSUB_SINGLESUBST_HH +#define OT_LAYOUT_GSUB_SINGLESUBST_HH #include "Common.hh" #include "SingleSubstFormat1.hh" @@ -71,4 +71,4 @@ SingleSubst_serialize (hb_serialize_context_t *c, } } -#endif +#endif /* OT_LAYOUT_GSUB_SINGLESUBST_HH */ diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index dc59e97dd..4528094ca 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -1,5 +1,5 @@ -#ifndef OT_LAYOUT_GSUB_SINGLE_SUBST_FORMAT_1 -#define OT_LAYOUT_GSUB_SINGLE_SUBST_FORMAT_1 +#ifndef OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH +#define OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH #include "Common.hh" #include "hb-ot-layout-gsubgpos.hh" @@ -122,4 +122,4 @@ struct SingleSubstFormat1 } -#endif +#endif /* OT_LAYOUT_GSUB_SINGLESUBSTFORMAT1_HH */ diff --git a/src/OT/Layout/GSUB/SingleSubstFormat2.hh b/src/OT/Layout/GSUB/SingleSubstFormat2.hh index 654167e63..a82753599 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat2.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat2.hh @@ -1,5 +1,5 @@ -#ifndef OT_LAYOUT_GSUB_SINGLE_SUBST_FORMAT_2 -#define OT_LAYOUT_GSUB_SINGLE_SUBST_FORMAT_2 +#ifndef OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH +#define OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH #include "Common.hh" #include "hb-ot-layout-gsubgpos.hh" @@ -120,4 +120,4 @@ struct SingleSubstFormat2 } } -#endif +#endif /* OT_LAYOUT_GSUB_SINGLESUBSTFORMAT2_HH */ diff --git a/src/check-c-linkage-decls.py b/src/check-c-linkage-decls.py index b7532a7e9..49cd29628 100755 --- a/src/check-c-linkage-decls.py +++ b/src/check-c-linkage-decls.py @@ -4,11 +4,19 @@ import sys, os os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) +def removeprefix(s, prefix): + if s.startswith(prefix): + return s[len(prefix):] + else: + return s[:] + HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \ [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')] -HBSOURCES = [os.path.basename (x) for x in os.getenv ('HBSOURCES', '').split ()] or \ - [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))] - +HBSOURCES = [ + removeprefix(x, 'src%s' % os.path.sep) for x in os.getenv ('HBSOURCES', '').split () +] or [ + x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +] stat = 0 for x in HBHEADERS: diff --git a/src/check-header-guards.py b/src/check-header-guards.py index 0ad42cd84..b45ffe1ad 100755 --- a/src/check-header-guards.py +++ b/src/check-header-guards.py @@ -4,19 +4,30 @@ import sys, os, re os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) +def removeprefix(s, prefix): + if s.startswith(prefix): + return s[len(prefix):] + else: + return s[:] + + HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \ [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')] -HBSOURCES = [os.path.basename (x) for x in os.getenv ('HBSOURCES', '').split ()] or \ - [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))] +HBSOURCES = [ + removeprefix(x, 'src%s' % os.path.sep) for x in os.getenv ('HBSOURCES', '').split () +] or [ + x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +] + stat = 0 for x in HBHEADERS + HBSOURCES: if not x.endswith ('h') or x == 'hb-gobject-structs.h': continue - tag = x.upper ().replace ('.', '_').replace ('-', '_') + tag = x.upper ().replace ('.', '_').replace ('-', '_').replace(os.path.sep, '_').replace('/', '_') with open (x, 'r', encoding='utf-8') as f: content = f.read () if len (re.findall (tag + r'\b', content)) != 3: - print ('Ouch, header file %s does not have correct preprocessor guards' % x) + print ('Ouch, header file %s does not have correct preprocessor guards. Expected: %s' % (x, tag)) stat = 1 sys.exit (stat) diff --git a/src/check-includes.py b/src/check-includes.py index 88eaa2eaa..ed201aa3e 100755 --- a/src/check-includes.py +++ b/src/check-includes.py @@ -4,10 +4,21 @@ import sys, os, re os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) +def removeprefix(s, prefix): + if s.startswith(prefix): + return s[len(prefix):] + else: + return s[:] + HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \ [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')] -HBSOURCES = [os.path.basename (x) for x in os.getenv ('HBSOURCES', '').split ()] or \ - [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))] + +HBSOURCES = [ + removeprefix(x, 'src%s' % os.path.sep) for x in os.getenv ('HBSOURCES', '').split () +] or [ + x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +] + stat = 0 @@ -25,7 +36,7 @@ for x in HBSOURCES: with open (x, 'r', encoding='utf-8') as f: content = f.read () includes = re.findall (r'#.*include.*', content) if includes: - if not len (re.findall (r'"hb.*\.hh"', includes[0])): + if not len (re.findall (r'".*\.hh"', includes[0])): print ('failure on %s' % x) stat = 1