about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2023-09-21 17:24:05 -0400
committerDJ Delorie <dj@redhat.com>2023-10-09 17:42:25 -0400
commitd846c2838942297c9644f2f38bdad0fb88f42245 (patch)
treefa4d4e31ce2d922648e4565f99717d9d336ab1c2 /scripts
parenta3c50bf46a1ca6d9d2b7d879176d345abf95a9de (diff)
downloadglibc-d846c2838942297c9644f2f38bdad0fb88f42245.tar.gz
glibc-d846c2838942297c9644f2f38bdad0fb88f42245.tar.xz
glibc-d846c2838942297c9644f2f38bdad0fb88f42245.zip
build-many-glibcs: Check for required system tools
Notes for future devs:

* Add tools as you find they're needed, with version 0,0
* Bump version when you find an old tool that doesn't work
* Don't add a version just because you know it works

Co-authored-by: Lukasz Majewski <lukma@denx.de>
Co-authored-by: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-many-glibcs.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 57a5c48b16..edea52bbae 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -56,6 +56,26 @@ import sys
 import time
 import urllib.request
 
+# This is a list of system utilities that are expected to be available
+# to this script, and, if a non-zero version is included, the minimum
+# version required to work with this sccript.
+def get_list_of_required_tools():
+    global REQUIRED_TOOLS
+    REQUIRED_TOOLS = {
+        'awk'      : (get_version_awk,   (0,0,0)),
+        'bison'    : (get_version,       (0,0)),
+        'flex'     : (get_version,       (0,0,0)),
+        'git'      : (get_version,       (1,8,3)),
+        'make'     : (get_version,       (4,0)),
+        'makeinfo' : (get_version,       (0,0)),
+        'patch'    : (get_version,       (0,0,0)),
+        'sed'      : (get_version,       (0,0)),
+        'tar'      : (get_version,       (0,0,0)),
+        'gzip'     : (get_version,       (0,0)),
+        'bzip2'    : (get_version_bzip2, (0,0,0)),
+        'xz'       : (get_version,       (0,0,0)),
+    }
+
 try:
     subprocess.run
 except:
@@ -1871,8 +1891,84 @@ def get_parser():
     return parser
 
 
+def get_version_common(progname,line,word,delchars,arg1):
+    try:
+        out = subprocess.run([progname, arg1],
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.DEVNULL,
+                             stdin=subprocess.DEVNULL,
+                             check=True, universal_newlines=True)
+        v = out.stdout.splitlines()[line].split()[word]
+        if delchars:
+            v = v.replace(delchars,'')
+        return [int(x) for x in v.split('.')]
+    except:
+        return 'missing';
+
+def get_version_common_stderr(progname,line,word,delchars,arg1):
+    try:
+        out = subprocess.run([progname, arg1],
+                             stdout=subprocess.DEVNULL,
+                             stderr=subprocess.PIPE,
+                             stdin=subprocess.DEVNULL,
+                             check=True, universal_newlines=True)
+        v = out.stderr.splitlines()[line].split()[word]
+        if delchars:
+            v = v.replace(delchars,'')
+        return [int(x) for x in v.split('.')]
+    except:
+        return 'missing';
+
+def get_version(progname):
+    return get_version_common (progname, 0, -1, None, '--version');
+
+def get_version_awk(progname):
+    return get_version_common (progname, 0, 2, ',', '--version');
+
+def get_version_bzip2(progname):
+    return get_version_common_stderr (progname, 0, 6, ',', '-h');
+
+def check_version(ver, req):
+    for v, r in zip(ver, req):
+        if v > r:
+            return True
+        if v < r:
+            return False
+    return True
+
+def version_str(ver):
+    return '.'.join([str (x) for x in ver])
+
+def check_for_required_tools():
+    get_list_of_required_tools()
+    count_old_tools = 0
+    count_missing_tools = 0
+    
+    for k, v in REQUIRED_TOOLS.items():
+        version = v[0](k)
+        if version == 'missing':
+            ok = 'missing'
+        else:
+            ok = 'ok' if check_version (version, v[1]) else 'old'
+        if ok == 'old':
+            if count_old_tools == 0:
+                print("One or more required tools are too old:")
+            count_old_tools = count_old_tools + 1
+            print('{:9}: {:3} (obtained=\"{}\" required=\"{}\")'.format(k, ok,
+                    version_str(version), version_str(v[1])))
+        if ok == 'missing':
+            if count_missing_tools == 0:
+                print("One or more required tools are missing:")
+            count_missing_tools = count_missing_tools + 1
+            print('{:9}: {:3} (required=\"{}\")'.format(k, ok,
+                    version_str(v[1])))
+    
+    if count_old_tools > 0 or count_missing_tools > 0:
+        exit (1);
+    
 def main(argv):
     """The main entry point."""
+    check_for_required_tools();
     parser = get_parser()
     opts = parser.parse_args(argv)
     topdir = os.path.abspath(opts.topdir)