chiark / gitweb /
Fix JAVA_HOME environment variable handling
[fdroidserver.git] / fdroidserver / common.py
index 03a8743d2686efd73b807be1361b741e4ebcd237..229c6e4d69cfbd462aba80f90df38d05b11d9a85 100644 (file)
@@ -58,7 +58,8 @@ default_config = {
         'r9b': None,
         'r10e': "$ANDROID_NDK",
     },
-    'build_tools': "23.0.3",
+    'build_tools': "24.0.0",
+    'force_build_tools': False,
     'java_paths': None,
     'ant': "ant",
     'mvn3': "mvn",
@@ -134,7 +135,7 @@ def fill_config_defaults(thisconfig):
         pathlist += glob.glob('/System/Library/Java/JavaVirtualMachines/1.[6-9].0.jdk')
         pathlist += glob.glob('/Library/Java/JavaVirtualMachines/*jdk*[6-9]*')
         if os.getenv('JAVA_HOME') is not None:
-            pathlist += os.getenv('JAVA_HOME')
+            pathlist.append(os.getenv('JAVA_HOME'))
         if os.getenv('PROGRAMFILES') is not None:
             pathlist += glob.glob(os.path.join(os.getenv('PROGRAMFILES'), 'Java', 'jdk1.[6-9].*'))
         for d in sorted(pathlist):
@@ -1371,7 +1372,11 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
             props += "sdk.dir=%s\n" % config['sdk_path']
             props += "sdk-location=%s\n" % config['sdk_path']
         ndk_path = build.ndk_path()
-        if ndk_path:
+        # if for any reason the path isn't valid or the directory
+        # doesn't exist, some versions of Gradle will error with a
+        # cryptic message (even if the NDK is not even necessary).
+        # https://gitlab.com/fdroid/fdroidserver/issues/171
+        if ndk_path and os.path.exists(ndk_path):
             # Add ndk location
             props += "ndk.dir=%s\n" % ndk_path
             props += "ndk-location=%s\n" % ndk_path
@@ -1569,9 +1574,11 @@ class KnownApks:
 
     # Record an apk (if it's new, otherwise does nothing)
     # Returns the date it was added.
-    def recordapk(self, apk, app):
+    def recordapk(self, apk, app, default_date=None):
         if apk not in self.apks:
-            self.apks[apk] = (app, time.gmtime(time.time()))
+            if default_date is None:
+                default_date = time.gmtime(time.time())
+            self.apks[apk] = (app, default_date)
             self.changed = True
         _, added = self.apks[apk]
         return added
@@ -1793,7 +1800,8 @@ def set_FDroidPopen_env(build=None):
     set up the environment variables for the build environment
 
     There is only a weak standard, the variables used by gradle, so also set
-    up the most commonly used environment variables for SDK and NDK
+    up the most commonly used environment variables for SDK and NDK.  Also, if
+    there is no locale set, this will set the locale (e.g. LANG) to en_US.UTF-8.
     '''
     global env, orig_path
 
@@ -1805,16 +1813,21 @@ def set_FDroidPopen_env(build=None):
         for k, v in config['java_paths'].items():
             env['JAVA%s_HOME' % k] = v
 
-    # Set up environment vars that depend on each build, only set the
-    # NDK env vars if the NDK is not already in the PATH
+    missinglocale = True
+    for k, v in env.items():
+        if k == 'LANG' and v != 'C':
+            missinglocale = False
+        elif k == 'LC_ALL':
+            missinglocale = False
+    if missinglocale:
+        env['LANG'] = 'en_US.UTF-8'
+
     if build is not None:
         path = build.ndk_path()
         paths = orig_path.split(os.pathsep)
-        if path in paths:
-            return
-        paths.append(path)
-        env['PATH'] = os.pathsep.join(paths)
-
+        if path not in paths:
+            paths = [path] + paths
+            env['PATH'] = os.pathsep.join(paths)
         for n in ['ANDROID_NDK', 'NDK', 'ANDROID_NDK_HOME']:
             env[n] = build.ndk_path()
 
@@ -1852,7 +1865,7 @@ def place_srclib(root_dir, number, libpath):
         if not placed:
             o.write('android.library.reference.%d=%s\n' % (number, relpath))
 
-apk_sigfile = re.compile(r'META-INF/[0-9A-Za-z]+\.(SF|RSA)')
+apk_sigfile = re.compile(r'META-INF/[0-9A-Za-z]+\.(SF|RSA|DSA|EC)')
 
 
 def verify_apks(signed_apk, unsigned_apk, tmp_dir):