From 77c24e8a0eb9bf588bf596319f97e6eb7b42ebd3 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 6 May 2025 13:17:13 +0300 Subject: [PATCH] [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'], )