chiark / gitweb /
check aapt version to make sure its new enough #236
authorHans-Christoph Steiner <hans@eds.org>
Tue, 15 Nov 2016 13:56:11 +0000 (14:56 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 5 Dec 2016 19:16:12 +0000 (20:16 +0100)
Since `fdroid update` parses the output of aapt, and since aapt's output
format changes in non-compatible ways, test to make sure that the version
of aapt is new enough to prevent mystery stacktraces.  This only prints a
warning since in many cases, the old version will work just fine.

fdroidserver/common.py

index de683c801e93a5298f0d6982001aab0da443f5c1..d1c12d5c33d09051c5166fba00010a93c79d8e0d 100644 (file)
@@ -36,8 +36,8 @@ import socket
 import base64
 import xml.etree.ElementTree as XMLElementTree
 
+from distutils.version import LooseVersion
 from queue import Queue
-
 from zipfile import ZipFile
 
 import fdroidserver.metadata
@@ -291,15 +291,37 @@ def find_sdk_tools_cmd(cmd):
             tooldirs.append(sdk_platform_tools)
     tooldirs.append('/usr/bin')
     for d in tooldirs:
-        if os.path.isfile(os.path.join(d, cmd)):
-            return os.path.join(d, cmd)
+        path = os.path.join(d, cmd)
+        if os.path.isfile(path):
+            if cmd == 'aapt':
+                test_aapt_version(path)
+            return path
     # did not find the command, exit with error message
     ensure_build_tools_exists(config)
 
 
+def test_aapt_version(aapt):
+    '''Check whether the version of aapt is new enough'''
+    output = subprocess.check_output([aapt, 'version'], universal_newlines=True)
+    if output is None or output == '':
+        logging.error(aapt + ' failed to execute!')
+    else:
+        m = re.match(r'.*v([0-9]+)\.([0-9]+)[.-]?([0-9.-]*)', output)
+        if m:
+            major = m.group(1)
+            minor = m.group(2)
+            bugfix = m.group(3)
+            # the Debian package has the version string like "v0.2-23.0.2"
+            if '.' not in bugfix and LooseVersion('.'.join((major, minor, bugfix))) < LooseVersion('0.2.2166767'):
+                logging.warning(aapt + ' is too old, fdroid requires build-tools-23.0.0 or newer!')
+        else:
+            logging.warning('Unknown version of aapt, might cause problems: ' + output)
+
+
 def test_sdk_exists(thisconfig):
     if 'sdk_path' not in thisconfig:
         if 'aapt' in thisconfig and os.path.isfile(thisconfig['aapt']):
+            test_aapt_version(thisconfig['aapt'])
             return True
         else:
             logging.error("'sdk_path' not set in config.py!")
@@ -1684,6 +1706,8 @@ def SdkToolsPopen(commands, cwd=None, output=True):
     if abscmd is None:
         logging.critical("Could not find '%s' on your system" % cmd)
         sys.exit(1)
+    if cmd == 'aapt':
+        test_aapt_version(config['aapt'])
     return FDroidPopen([abscmd] + commands[1:],
                        cwd=cwd, output=output)