From d403529211eb1659ec3de3260ed30a64a301f59e Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 May 2025 12:33:33 +0300 Subject: [PATCH 1/3] [check-*.py] Format --- src/check-c-linkage-decls.py | 50 ++++++------ src/check-externs.py | 26 +++--- src/check-header-guards.py | 51 +++++++----- src/check-includes.py | 73 +++++++++-------- src/check-libstdc++.py | 50 ++++++------ src/check-static-inits.py | 53 +++++++------ src/check-symbols.py | 149 +++++++++++++++++++++++------------ 7 files changed, 272 insertions(+), 180 deletions(-) diff --git a/src/check-c-linkage-decls.py b/src/check-c-linkage-decls.py index 27f5639e7..84830184a 100755 --- a/src/check-c-linkage-decls.py +++ b/src/check-c-linkage-decls.py @@ -1,37 +1,43 @@ #!/usr/bin/env python3 -import sys, os +import os +import sys -srcdir = os.getenv ('srcdir', os.path.dirname (__file__)) -base_srcdir = os.getenv ('base_srcdir', srcdir) +srcdir = os.getenv("srcdir", os.path.dirname(__file__)) +base_srcdir = os.getenv("base_srcdir", srcdir) + +os.chdir(srcdir) -os.chdir (srcdir) def removeprefix(s): - abs_path = os.path.join(base_srcdir, s) - return os.path.relpath(abs_path, srcdir) + abs_path = os.path.join(base_srcdir, s) + return os.path.relpath(abs_path, srcdir) -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')] -HBHEADERS = [x for x in HBHEADERS if x.endswith ('.h')] -HBSOURCES = [ - removeprefix(x) for x in os.getenv ('HBSOURCES', '').split () -] or [ - x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +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") +] +HBHEADERS = [x for x in HBHEADERS if x.endswith(".h")] +HBSOURCES = [removeprefix(x) 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: - with open (x, 'r', encoding='utf-8') as f: content = f.read () - if ('HB_BEGIN_DECLS' not in content) or ('HB_END_DECLS' not in content): - print ('Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should' % x) - stat = 1 + with open(x, "r", encoding="utf-8") as f: + content = f.read() + if ("HB_BEGIN_DECLS" not in content) or ("HB_END_DECLS" not in content): + print( + "Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should" + % x + ) + stat = 1 for x in HBSOURCES: - with open (x, 'r', encoding='utf-8') as f: content = f.read () - if ('HB_BEGIN_DECLS' in content) or ('HB_END_DECLS' in content): - print ('Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn\'t' % x) - stat = 1 + with open(x, "r", encoding="utf-8") as f: + content = f.read() + if ("HB_BEGIN_DECLS" in content) or ("HB_END_DECLS" in content): + print("Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn't" % x) + stat = 1 -sys.exit (stat) +sys.exit(stat) diff --git a/src/check-externs.py b/src/check-externs.py index a64d2e5b4..78d373572 100755 --- a/src/check-externs.py +++ b/src/check-externs.py @@ -1,20 +1,24 @@ #!/usr/bin/env python3 -import sys, os, re +import os +import re +import sys -os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) +os.chdir(os.getenv("srcdir", os.path.dirname(__file__))) -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')] +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") +] stat = 0 -print ('Checking that all public symbols are exported with HB_EXTERN') +print("Checking that all public symbols are exported with HB_EXTERN") for x in HBHEADERS: - with open (x, 'r', encoding='utf-8') as f: content = f.read () - for s in re.findall (r'\n.+\nhb_.+\n', content): - if not s.startswith ('\nHB_EXTERN '): - print ('failure on:', s) - stat = 1 + with open(x, "r", encoding="utf-8") as f: + content = f.read() + for s in re.findall(r"\n.+\nhb_.+\n", content): + if not s.startswith("\nHB_EXTERN "): + print("failure on:", s) + stat = 1 -sys.exit (stat) +sys.exit(stat) diff --git a/src/check-header-guards.py b/src/check-header-guards.py index 35ae6bef6..ed02d5686 100755 --- a/src/check-header-guards.py +++ b/src/check-header-guards.py @@ -1,34 +1,47 @@ #!/usr/bin/env python3 -import sys, os, re +import os +import re +import sys -srcdir = os.getenv ('srcdir', os.path.dirname (__file__)) -base_srcdir = os.getenv ('base_srcdir', srcdir) +srcdir = os.getenv("srcdir", os.path.dirname(__file__)) +base_srcdir = os.getenv("base_srcdir", srcdir) + +os.chdir(srcdir) -os.chdir (srcdir) def removeprefix(s): - abs_path = os.path.join(base_srcdir, s) - return os.path.relpath(abs_path, srcdir) + abs_path = os.path.join(base_srcdir, s) + return os.path.relpath(abs_path, srcdir) -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 = [ - removeprefix(x) for x in os.getenv ('HBSOURCES', '').split () -] or [ - x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +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 = [removeprefix(x) 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 ('-', '_').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. Expected: %s' % (x, tag)) - stat = 1 + if not x.endswith("h") or x == "hb-gobject-structs.h": + continue + 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. Expected: %s" + % (x, tag) + ) + stat = 1 -sys.exit (stat) +sys.exit(stat) diff --git a/src/check-includes.py b/src/check-includes.py index fc95874b1..4a04d49c1 100755 --- a/src/check-includes.py +++ b/src/check-includes.py @@ -1,51 +1,60 @@ #!/usr/bin/env python3 -import sys, os, re +import os +import re +import sys -srcdir = os.getenv ('srcdir', os.path.dirname (__file__)) -base_srcdir = os.getenv ('base_srcdir', srcdir) +srcdir = os.getenv("srcdir", os.path.dirname(__file__)) +base_srcdir = os.getenv("base_srcdir", srcdir) + +os.chdir(srcdir) -os.chdir (srcdir) def removeprefix(s): - abs_path = os.path.join(base_srcdir, s) - return os.path.relpath(abs_path, srcdir) + abs_path = os.path.join(base_srcdir, s) + return os.path.relpath(abs_path, srcdir) -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 = [ - removeprefix(x) for x in os.getenv ('HBSOURCES', '').split () -] or [ - x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh')) +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 = [removeprefix(x) 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 -print ('Checking that public header files #include "hb-common.h" or "hb.h" first (or none)') +print( + 'Checking that public header files #include "hb-common.h" or "hb.h" first (or none)' +) for x in HBHEADERS: - if x == 'hb.h' or x == 'hb-common.h': continue - with open (x, 'r', encoding='utf-8') as f: content = f.read () - first = re.findall (r'#.*include.*', content)[0] - if first not in ['#include "hb.h"', '#include "hb-common.h"']: - print ('failure on %s' % x) - stat = 1 + if x == "hb.h" or x == "hb-common.h": + continue + with open(x, "r", encoding="utf-8") as f: + content = f.read() + first = re.findall(r"#.*include.*", content)[0] + if first not in ['#include "hb.h"', '#include "hb-common.h"']: + print("failure on %s" % x) + stat = 1 -print ('Checking that source files #include a private header first (or none)') +print("Checking that source files #include a private header first (or none)") 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'".*\.hh"', includes[0])): - print ('failure on %s' % x) - stat = 1 + 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'".*\.hh"', includes[0])): + print("failure on %s" % x) + stat = 1 -print ('Checking that there is no #include ') +print("Checking that there is no #include ") for x in HBHEADERS + HBSOURCES: - with open (x, 'r', encoding='utf-8') as f: content = f.read () - if re.findall ('#.*include.*<.*hb', content): - print ('failure on %s' % x) - stat = 1 + with open(x, "r", encoding="utf-8") as f: + content = f.read() + if re.findall("#.*include.*<.*hb", content): + print("failure on %s" % x) + stat = 1 -sys.exit (stat) +sys.exit(stat) diff --git a/src/check-libstdc++.py b/src/check-libstdc++.py index e70d5f80b..a0c5c3e8a 100755 --- a/src/check-libstdc++.py +++ b/src/check-libstdc++.py @@ -1,39 +1,43 @@ #!/usr/bin/env python3 -import sys, os, shutil, subprocess +import os +import shutil +import subprocess +import sys -os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) +os.chdir(os.getenv("srcdir", os.path.dirname(__file__))) -libs = os.getenv ('libs', '.libs') +libs = os.getenv("libs", ".libs") -ldd = os.getenv ('LDD', shutil.which ('ldd')) +ldd = os.getenv("LDD", shutil.which("ldd")) if not ldd: - otool = os.getenv ('OTOOL', shutil.which ('otool')) - if otool: - ldd = otool + ' -L' - else: - print ('check-libstdc++.py: \'ldd\' not found; skipping test') - sys.exit (77) + otool = os.getenv("OTOOL", shutil.which("otool")) + if otool: + ldd = otool + " -L" + else: + print("check-libstdc++.py: 'ldd' not found; skipping test") + sys.exit(77) stat = 0 tested = False # harfbuzz-icu links to libstdc++ because icu does. -for soname in ['harfbuzz', 'harfbuzz-subset', 'harfbuzz-gobject', 'harfbuzz-cairo']: - for suffix in ['so', 'dylib']: - so = os.path.join (libs, 'lib%s.%s' % (soname, suffix)) - if not os.path.exists (so): continue +for soname in ["harfbuzz", "harfbuzz-subset", "harfbuzz-gobject", "harfbuzz-cairo"]: + for suffix in ["so", "dylib"]: + so = os.path.join(libs, "lib%s.%s" % (soname, suffix)) + if not os.path.exists(so): + continue - print ('Checking that we are not linking to libstdc++ or libc++ in %s' % so) - ldd_result = subprocess.check_output (ldd.split() + [so]) - if (b'libstdc++' in ldd_result) or (b'libc++' in ldd_result): - print ('Ouch, %s is linked to libstdc++ or libc++' % so) - stat = 1 + print("Checking that we are not linking to libstdc++ or libc++ in %s" % so) + ldd_result = subprocess.check_output(ldd.split() + [so]) + if (b"libstdc++" in ldd_result) or (b"libc++" in ldd_result): + print("Ouch, %s is linked to libstdc++ or libc++" % so) + stat = 1 - tested = True + tested = True if not tested: - print ('check-libstdc++.py: libharfbuzz shared library not found; skipping test') - sys.exit (77) + print("check-libstdc++.py: libharfbuzz shared library not found; skipping test") + sys.exit(77) -sys.exit (stat) +sys.exit(stat) diff --git a/src/check-static-inits.py b/src/check-static-inits.py index 2acd04602..46ef031db 100755 --- a/src/check-static-inits.py +++ b/src/check-static-inits.py @@ -1,51 +1,60 @@ #!/usr/bin/env python3 -import sys, os, shutil, subprocess, glob, re +import glob +import os +import re +import shutil +import subprocess +import sys -builddir = os.getenv ('builddir', os.path.dirname (__file__)) -libs = os.getenv ('libs', '.libs') +builddir = os.getenv("builddir", os.path.dirname(__file__)) +libs = os.getenv("libs", ".libs") -objdump = os.getenv ('OBJDUMP', shutil.which ('objdump')) +objdump = os.getenv("OBJDUMP", shutil.which("objdump")) if not objdump: - print ('check-static-inits.py: \'ldd\' not found; skipping test') - sys.exit (77) + print("check-static-inits.py: 'ldd' not found; skipping test") + sys.exit(77) if sys.version_info < (3, 5): - print ('check-static-inits.py: needs python 3.5 for recursive support in glob') - sys.exit (77) + print("check-static-inits.py: needs python 3.5 for recursive support in glob") + sys.exit(77) -OBJS = glob.glob (os.path.join (builddir, libs, '**', '*hb*.o'), recursive=True) +OBJS = glob.glob(os.path.join(builddir, libs, "**", "*hb*.o"), recursive=True) if not OBJS: - print ('check-static-inits.py: object files not found; skipping test') - sys.exit (77) + print("check-static-inits.py: object files not found; skipping test") + sys.exit(77) stat = 0 tested = 0 -result = subprocess.run(objdump.split () + ['-t'] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +result = subprocess.run( + objdump.split() + ["-t"] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE +) if result.returncode: - if result.stderr.find (b'not recognized') != -1: + if result.stderr.find(b"not recognized") != -1: # https://github.com/harfbuzz/harfbuzz/issues/3019 - print ('objdump %s returned "not recognized", skipping') + print('objdump %s returned "not recognized", skipping') else: - print ('objdump returned error:\n%s' % (result.stderr.decode ('utf-8'))) + print("objdump returned error:\n%s" % (result.stderr.decode("utf-8"))) stat = 2 else: tested = 1 -result = result.stdout.decode ('utf-8') +result = result.stdout.decode("utf-8") # Checking that no object file has static initializers -for l in re.findall (r'^.*\.[cd]tors.*$', result, re.MULTILINE): - if not re.match (r'.*\b0+\b', l): - print ('Ouch, library has static initializers/finalizers') +for l in re.findall(r"^.*\.[cd]tors.*$", result, re.MULTILINE): + if not re.match(r".*\b0+\b", l): + print("Ouch, library has static initializers/finalizers") stat = 1 # Checking that no object file has lazy static C++ constructors/destructors or other such stuff -if ('__cxa_' in result) and ('__ubsan_handle' not in result): - print ('Ouch, library has lazy static C++ constructors/destructors or other such stuff') +if ("__cxa_" in result) and ("__ubsan_handle" not in result): + print( + "Ouch, library has lazy static C++ constructors/destructors or other such stuff" + ) stat = 1 -sys.exit (stat if tested else 77) +sys.exit(stat if tested else 77) diff --git a/src/check-symbols.py b/src/check-symbols.py index b9a469fbb..38a68bf8f 100755 --- a/src/check-symbols.py +++ b/src/check-symbols.py @@ -1,77 +1,124 @@ #!/usr/bin/env python3 -import sys, os, shutil, subprocess, re, difflib +import difflib +import os +import re +import shutil +import subprocess +import sys -os.environ['LC_ALL'] = 'C' # otherwise 'nm' prints in wrong order +os.environ["LC_ALL"] = "C" # otherwise 'nm' prints in wrong order -builddir = os.getenv ('builddir', os.path.dirname (__file__)) -libs = os.getenv ('libs', '.libs') +builddir = os.getenv("builddir", os.path.dirname(__file__)) +libs = os.getenv("libs", ".libs") -IGNORED_SYMBOLS = ['_fini', '_init', '_fdata', '_ftext', '_fbss', - '__bss_start', '__bss_start__', '__bss_end__', '_edata', '_end', '_bss_end__', - '__end__', '__gcov_.*', 'llvm_.*', 'flush_fn_list', 'writeout_fn_list', 'mangle_path', - 'lprofDirMode', 'reset_fn_list'] +IGNORED_SYMBOLS = [ + "_fini", + "_init", + "_fdata", + "_ftext", + "_fbss", + "__bss_start", + "__bss_start__", + "__bss_end__", + "_edata", + "_end", + "_bss_end__", + "__end__", + "__gcov_.*", + "llvm_.*", + "flush_fn_list", + "writeout_fn_list", + "mangle_path", + "lprofDirMode", + "reset_fn_list", +] # Rust IGNORED_SYMBOLS += [ - 'rust_eh_personality', - '_ZN3std9panicking11EMPTY_PANIC.*', # 'std::panicking::EMPTY_PANIC::.*' - '_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*', # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*' - '_ZN3std3sys4args4unix3imp15ARGV_INIT_ARRAY.*', # std::sys::args::unix::imp::ARGV_INIT_ARRAY::.* - '_ZN17compiler_builtins.*', # 'compiler_builtins::.*' + "rust_eh_personality", + "_ZN3std9panicking11EMPTY_PANIC.*", # 'std::panicking::EMPTY_PANIC::.*' + "_ZN3std3sys3pal4unix4args3imp15ARGV_INIT_ARRAY.*", # 'std::sys::pal::unix::args::imp::ARGV_INIT_ARRAY::.*' + "_ZN3std3sys4args4unix3imp15ARGV_INIT_ARRAY.*", # std::sys::args::unix::imp::ARGV_INIT_ARRAY::.* + "_ZN17compiler_builtins.*", # 'compiler_builtins::.*' ] -IGNORED_SYMBOLS = '|'.join (IGNORED_SYMBOLS) +IGNORED_SYMBOLS = "|".join(IGNORED_SYMBOLS) -nm = os.getenv ('NM', shutil.which ('nm')) +nm = os.getenv("NM", shutil.which("nm")) if not nm: - print ('check-symbols.py: \'nm\' not found; skipping test') - sys.exit (77) + print("check-symbols.py: 'nm' not found; skipping test") + sys.exit(77) tested = False stat = 0 -for soname in ['harfbuzz', 'harfbuzz-subset', 'harfbuzz-icu', 'harfbuzz-gobject', 'harfbuzz-cairo']: - for suffix in ['so', 'dylib']: - so = os.path.join (builddir, libs, 'lib%s.%s' % (soname, suffix)) - if not os.path.exists (so): continue +for soname in [ + "harfbuzz", + "harfbuzz-subset", + "harfbuzz-icu", + "harfbuzz-gobject", + "harfbuzz-cairo", +]: + for suffix in ["so", "dylib"]: + so = os.path.join(builddir, libs, "lib%s.%s" % (soname, suffix)) + if not os.path.exists(so): + continue - # On macOS, C symbols are prefixed with _ - symprefix = '_' if suffix == 'dylib' else '' + # On macOS, C symbols are prefixed with _ + symprefix = "_" if suffix == "dylib" else "" - EXPORTED_SYMBOLS = [s.split ()[2] - for s in re.findall (r'^.+ [BCDGIRSTu] .+$', subprocess.check_output (nm.split() + [so]).decode ('utf-8'), re.MULTILINE) - if not re.match (r'.* %s(%s)\b' % (symprefix, IGNORED_SYMBOLS), s)] + EXPORTED_SYMBOLS = [ + s.split()[2] + for s in re.findall( + r"^.+ [BCDGIRSTu] .+$", + subprocess.check_output(nm.split() + [so]).decode("utf-8"), + re.MULTILINE, + ) + if not re.match(r".* %s(%s)\b" % (symprefix, IGNORED_SYMBOLS), s) + ] - prefix = (symprefix + os.path.basename (so)).replace ('libharfbuzz', 'hb').replace ('-', '_').split ('.')[0] + prefix = ( + (symprefix + os.path.basename(so)) + .replace("libharfbuzz", "hb") + .replace("-", "_") + .split(".")[0] + ) - print ('Checking that %s does not expose internal symbols' % so) - suspicious_symbols = [x for x in EXPORTED_SYMBOLS if not re.match (r'^%s(_|$)' % prefix, x)] - if suspicious_symbols: - print ('Ouch, internal symbols exposed:', suspicious_symbols) - stat = 1 + print("Checking that %s does not expose internal symbols" % so) + suspicious_symbols = [ + x for x in EXPORTED_SYMBOLS if not re.match(r"^%s(_|$)" % prefix, x) + ] + if suspicious_symbols: + print("Ouch, internal symbols exposed:", suspicious_symbols) + stat = 1 - def_path = os.path.join (builddir, soname + '.def') - if not os.path.exists (def_path): - print ('\'%s\' not found; skipping' % def_path) - else: - print ('Checking that %s has the same symbol list as %s' % (so, def_path)) - with open (def_path, 'r', encoding='utf-8') as f: def_file = f.read () - diff_result = list (difflib.context_diff ( - def_file.splitlines (), - ['EXPORTS'] + [re.sub ('^%shb' % symprefix, 'hb', x) for x in EXPORTED_SYMBOLS] + - # cheat: copy the last line from the def file! - [def_file.splitlines ()[-1]] - )) + def_path = os.path.join(builddir, soname + ".def") + if not os.path.exists(def_path): + print("'%s' not found; skipping" % def_path) + else: + print("Checking that %s has the same symbol list as %s" % (so, def_path)) + with open(def_path, "r", encoding="utf-8") as f: + def_file = f.read() + diff_result = list( + difflib.context_diff( + def_file.splitlines(), + ["EXPORTS"] + + [re.sub("^%shb" % symprefix, "hb", x) for x in EXPORTED_SYMBOLS] + + + # cheat: copy the last line from the def file! + [def_file.splitlines()[-1]], + ) + ) - if diff_result: - print ('\n'.join (diff_result)) - stat = 1 + if diff_result: + print("\n".join(diff_result)) + stat = 1 - tested = True + tested = True if not tested: - print ('check-symbols.py: no shared libraries found; skipping test') - sys.exit (77) + print("check-symbols.py: no shared libraries found; skipping test") + sys.exit(77) -sys.exit (stat) +sys.exit(stat) From a5d4e7ba0dd28bc34c7778bb889bf4f13bfe0fdf Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 May 2025 12:49:57 +0300 Subject: [PATCH 2/3] [check-static-inits.py] Cleanup --- src/check-static-inits.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/check-static-inits.py b/src/check-static-inits.py index 46ef031db..7cb22e910 100755 --- a/src/check-static-inits.py +++ b/src/check-static-inits.py @@ -25,7 +25,7 @@ if not OBJS: sys.exit(77) stat = 0 -tested = 0 +tested = False result = subprocess.run( objdump.split() + ["-t"] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE @@ -34,18 +34,18 @@ result = subprocess.run( if result.returncode: if result.stderr.find(b"not recognized") != -1: # https://github.com/harfbuzz/harfbuzz/issues/3019 - print('objdump %s returned "not recognized", skipping') + print('objdump returned "not recognized", skipping') else: print("objdump returned error:\n%s" % (result.stderr.decode("utf-8"))) stat = 2 else: - tested = 1 + tested = True result = result.stdout.decode("utf-8") # Checking that no object file has static initializers -for l in re.findall(r"^.*\.[cd]tors.*$", result, re.MULTILINE): - if not re.match(r".*\b0+\b", l): +for lib in re.findall(r"^.*\.[cd]tors.*$", result, re.MULTILINE): + if not re.match(r".*\b0+\b", lib): print("Ouch, library has static initializers/finalizers") stat = 1 From 77c24e8a0eb9bf588bf596319f97e6eb7b42ebd3 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 May 2025 13:17:13 +0300 Subject: [PATCH 3/3] [check-*.py] Remove autotoolism Instead of passing source dir and build dir to as envvars, pass them directly as script arguments. The scripts also were supposed to be able to run outsize of the build scripts, but this was broken since the fallback when the envvars were not set was wrong. The HBSOURCES and HBHEADERS are still passed as envvars since they are long lists and might hit command line length limitation on some systems. --- src/check-c-linkage-decls.py | 7 +++++-- src/check-externs.py | 7 ++++++- src/check-header-guards.py | 6 ++++-- src/check-includes.py | 8 ++++++-- src/check-libstdc++.py | 8 +++++--- src/check-static-inits.py | 10 +++++++--- src/check-symbols.py | 7 ++++--- src/meson.build | 9 +++++---- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/check-c-linkage-decls.py b/src/check-c-linkage-decls.py index 84830184a..9c5260304 100755 --- a/src/check-c-linkage-decls.py +++ b/src/check-c-linkage-decls.py @@ -3,8 +3,9 @@ import os import sys -srcdir = os.getenv("srcdir", os.path.dirname(__file__)) -base_srcdir = os.getenv("base_srcdir", srcdir) +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] os.chdir(srcdir) @@ -24,6 +25,7 @@ HBSOURCES = [removeprefix(x) for x in os.getenv("HBSOURCES", "").split()] or [ stat = 0 for x in HBHEADERS: + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() if ("HB_BEGIN_DECLS" not in content) or ("HB_END_DECLS" not in content): @@ -34,6 +36,7 @@ for x in HBHEADERS: stat = 1 for x in HBSOURCES: + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() if ("HB_BEGIN_DECLS" in content) or ("HB_END_DECLS" in content): diff --git a/src/check-externs.py b/src/check-externs.py index 78d373572..3e5023ade 100755 --- a/src/check-externs.py +++ b/src/check-externs.py @@ -4,7 +4,11 @@ import os import re import sys -os.chdir(os.getenv("srcdir", os.path.dirname(__file__))) +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] + +os.chdir(srcdir) 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") @@ -14,6 +18,7 @@ stat = 0 print("Checking that all public symbols are exported with HB_EXTERN") for x in HBHEADERS: + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() for s in re.findall(r"\n.+\nhb_.+\n", content): diff --git a/src/check-header-guards.py b/src/check-header-guards.py index ed02d5686..1f36950bf 100755 --- a/src/check-header-guards.py +++ b/src/check-header-guards.py @@ -4,8 +4,9 @@ import os import re import sys -srcdir = os.getenv("srcdir", os.path.dirname(__file__)) -base_srcdir = os.getenv("base_srcdir", srcdir) +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] os.chdir(srcdir) @@ -28,6 +29,7 @@ stat = 0 for x in HBHEADERS + HBSOURCES: if not x.endswith("h") or x == "hb-gobject-structs.h": continue + print(f"Checking {x}") tag = ( x.upper() .replace(".", "_") diff --git a/src/check-includes.py b/src/check-includes.py index 4a04d49c1..422315171 100755 --- a/src/check-includes.py +++ b/src/check-includes.py @@ -4,8 +4,9 @@ import os import re import sys -srcdir = os.getenv("srcdir", os.path.dirname(__file__)) -base_srcdir = os.getenv("base_srcdir", srcdir) +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] os.chdir(srcdir) @@ -32,6 +33,7 @@ print( for x in HBHEADERS: if x == "hb.h" or x == "hb-common.h": continue + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() first = re.findall(r"#.*include.*", content)[0] @@ -41,6 +43,7 @@ for x in HBHEADERS: print("Checking that source files #include a private header first (or none)") for x in HBSOURCES: + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() includes = re.findall(r"#.*include.*", content) @@ -51,6 +54,7 @@ for x in HBSOURCES: print("Checking that there is no #include ") for x in HBHEADERS + HBSOURCES: + print(f"Checking {x}") with open(x, "r", encoding="utf-8") as f: content = f.read() if re.findall("#.*include.*<.*hb", content): diff --git a/src/check-libstdc++.py b/src/check-libstdc++.py index a0c5c3e8a..e90b4ce3c 100755 --- a/src/check-libstdc++.py +++ b/src/check-libstdc++.py @@ -5,9 +5,11 @@ import shutil import subprocess import sys -os.chdir(os.getenv("srcdir", os.path.dirname(__file__))) +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] -libs = os.getenv("libs", ".libs") +os.chdir(srcdir) ldd = os.getenv("LDD", shutil.which("ldd")) if not ldd: @@ -24,7 +26,7 @@ tested = False # harfbuzz-icu links to libstdc++ because icu does. for soname in ["harfbuzz", "harfbuzz-subset", "harfbuzz-gobject", "harfbuzz-cairo"]: for suffix in ["so", "dylib"]: - so = os.path.join(libs, "lib%s.%s" % (soname, suffix)) + so = os.path.join(builddir, "lib%s.%s" % (soname, suffix)) if not os.path.exists(so): continue diff --git a/src/check-static-inits.py b/src/check-static-inits.py index 7cb22e910..44d01797f 100755 --- a/src/check-static-inits.py +++ b/src/check-static-inits.py @@ -7,8 +7,9 @@ import shutil import subprocess import sys -builddir = os.getenv("builddir", os.path.dirname(__file__)) -libs = os.getenv("libs", ".libs") +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] objdump = os.getenv("OBJDUMP", shutil.which("objdump")) if not objdump: @@ -19,7 +20,7 @@ if sys.version_info < (3, 5): print("check-static-inits.py: needs python 3.5 for recursive support in glob") sys.exit(77) -OBJS = glob.glob(os.path.join(builddir, libs, "**", "*hb*.o"), recursive=True) +OBJS = glob.glob(os.path.join(builddir, "**", "*hb*.o"), recursive=True) if not OBJS: print("check-static-inits.py: object files not found; skipping test") sys.exit(77) @@ -27,6 +28,9 @@ if not OBJS: stat = 0 tested = False +print("Checking that the following object files has no static initializers/finalizers") +print("\n".join(OBJS)) + result = subprocess.run( objdump.split() + ["-t"] + OBJS, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) diff --git a/src/check-symbols.py b/src/check-symbols.py index 38a68bf8f..c18e96cf1 100755 --- a/src/check-symbols.py +++ b/src/check-symbols.py @@ -9,8 +9,9 @@ import sys os.environ["LC_ALL"] = "C" # otherwise 'nm' prints in wrong order -builddir = os.getenv("builddir", os.path.dirname(__file__)) -libs = os.getenv("libs", ".libs") +srcdir = sys.argv[1] +base_srcdir = sys.argv[2] +builddir = sys.argv[3] IGNORED_SYMBOLS = [ "_fini", @@ -61,7 +62,7 @@ for soname in [ "harfbuzz-cairo", ]: for suffix in ["so", "dylib"]: - so = os.path.join(builddir, libs, "lib%s.%s" % (soname, suffix)) + so = os.path.join(builddir, "lib%s.%s" % (soname, suffix)) if not os.path.exists(so): continue diff --git a/src/meson.build b/src/meson.build index a7d5674c9..1330a7795 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1038,10 +1038,6 @@ if get_option('tests').enabled() ] env = environment() - env.set('srcdir', meson.current_source_dir()) - env.set('base_srcdir', meson.project_source_root()) - env.set('builddir', meson.current_build_dir()) - env.set('libs', meson.current_build_dir()) # TODO: Merge this with builddir after autotools removal HBSOURCES = [] foreach f : hb_sources if meson.version().version_compare('>=1.4.0') @@ -1069,6 +1065,11 @@ if get_option('tests').enabled() foreach name : dist_check_script test(name, find_program(name + '.py'), env: env, + args: [ + meson.current_source_dir(), + meson.project_source_root(), + meson.current_build_dir(), + ], depends: name == 'check-symbols' ? defs_list : [], suite: ['src'], )