tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

check-c-linkage-decls.py (1289B)


      1 #!/usr/bin/env python3
      2 
      3 import os
      4 import sys
      5 
      6 srcdir = sys.argv[1]
      7 base_srcdir = sys.argv[2]
      8 builddir = sys.argv[3]
      9 
     10 os.chdir(srcdir)
     11 
     12 
     13 def removeprefix(s):
     14    abs_path = os.path.join(base_srcdir, s)
     15    return os.path.relpath(abs_path, srcdir)
     16 
     17 
     18 HBHEADERS = [os.path.basename(x) for x in os.getenv("HBHEADERS", "").split()] or [
     19    x for x in os.listdir(".") if x.startswith("hb") and x.endswith(".h")
     20 ]
     21 HBHEADERS = [x for x in HBHEADERS if x.endswith(".h")]
     22 HBSOURCES = [removeprefix(x) for x in os.getenv("HBSOURCES", "").split()] or [
     23    x for x in os.listdir(".") if x.startswith("hb") and x.endswith((".cc", ".hh"))
     24 ]
     25 stat = 0
     26 
     27 for x in HBHEADERS:
     28    print(f"Checking {x}")
     29    with open(x, "r", encoding="utf-8") as f:
     30        content = f.read()
     31    if ("HB_BEGIN_DECLS" not in content) or ("HB_END_DECLS" not in content):
     32        print(
     33            "Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should"
     34            % x
     35        )
     36        stat = 1
     37 
     38 for x in HBSOURCES:
     39    print(f"Checking {x}")
     40    with open(x, "r", encoding="utf-8") as f:
     41        content = f.read()
     42    if ("HB_BEGIN_DECLS" in content) or ("HB_END_DECLS" in content):
     43        print("Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn't" % x)
     44        stat = 1
     45 
     46 sys.exit(stat)