chiark / gitweb /
Revert "If given --verbose, don't print the whole error log again"
[fdroidserver.git] / fdroidserver / build.py
index a4561a9fe903a36fc0df6fc25e69f4471fbd50aa..0136f379a00b81c78750e65aef6b9ebfd584238d 100644 (file)
@@ -21,6 +21,7 @@
 import sys
 import os
 import shutil
+import glob
 import subprocess
 import re
 import tarfile
@@ -34,7 +35,7 @@ import logging
 
 import common
 import metadata
-from common import BuildException, VCSException, FDroidPopen, SilentPopen
+from common import FDroidException, BuildException, VCSException, FDroidPopen, SilentPopen
 
 try:
     import paramiko
@@ -430,7 +431,7 @@ def adapt_gradle(build_dir):
     for root, dirs, files in os.walk(build_dir):
         if 'build.gradle' in files:
             path = os.path.join(root, 'build.gradle')
-            logging.info("Adapting build.gradle at %s" % path)
+            logging.debug("Adapting build.gradle at %s" % path)
 
             FDroidPopen(['sed', '-i',
                          r's@buildToolsVersion\([ =]*\)["\'][0-9\.]*["\']@buildToolsVersion\1"'
@@ -490,10 +491,10 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         raise BuildException("Error cleaning %s:%s" %
                              (app['id'], thisbuild['version']), p.output)
 
-    logging.info("Getting rid of Gradle wrapper binaries...")
     for root, dirs, files in os.walk(build_dir):
         # Don't remove possibly necessary 'gradle' dirs if 'gradlew' is not there
         if 'gradlew' in files:
+            logging.debug("Getting rid of Gradle wrapper stuff in %s" % root)
             os.remove(os.path.join(root, 'gradlew'))
             if 'gradlew.bat' in files:
                 os.remove(os.path.join(root, 'gradlew.bat'))
@@ -734,23 +735,19 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         src = 'python-for-android/dist/default/bin/{0}-{1}-release.apk'.format(
             bconfig.get('app', 'title'), bconfig.get('app', 'version'))
     elif thisbuild['type'] == 'gradle':
-        basename = app['id']
-        dd = build_dir
-        if thisbuild['subdir']:
-            dd = os.path.join(dd, thisbuild['subdir'])
-            basename = os.path.basename(thisbuild['subdir'])
-        if '@' in thisbuild['gradle']:
-            dd = os.path.join(dd, thisbuild['gradle'].split('@')[1])
-            basename = app['id']
-        if len(flavours) == 1 and flavours[0] == '':
-            name = '-'.join([basename, 'release', 'unsigned'])
-        else:
-            name = '-'.join([basename, '-'.join(flavours), 'release', 'unsigned'])
-        dd = os.path.normpath(dd)
+
         if thisbuild['gradlepluginver'] >= LooseVersion('0.11'):
-            src = os.path.join(dd, 'build', 'outputs', 'apk', name + '.apk')
+            apks_dir = os.path.join(root_dir, 'build', 'outputs', 'apk')
         else:
-            src = os.path.join(dd, 'build', 'apk', name + '.apk')
+            apks_dir = os.path.join(root_dir, 'build', 'apk')
+
+        apks = glob.glob(os.path.join(apks_dir, '*-release-unsigned.apk'))
+        if len(apks) > 1:
+            raise BuildException('More than one resulting apks found in %s' % apks_dir,
+                                 '\n'.join(apks))
+        if len(apks) < 1:
+            raise BuildException('Failed to find gradle output in %s' % apks_dir)
+        src = apks[0]
     elif thisbuild['type'] == 'ant':
         stdout_apk = '\n'.join([
             line for line in p.output.splitlines() if '.apk' in line])
@@ -767,7 +764,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
 
     # By way of a sanity check, make sure the version and version
     # code in our new apk match what we expect...
-    logging.info("Checking " + src)
+    logging.debug("Checking " + src)
     if not os.path.exists(src):
         raise BuildException("Unsigned apk is not at expected location of " + src)
 
@@ -991,7 +988,7 @@ def main():
             len(app['Repo Type']) > 0 and len(app['builds']) > 0]
 
     if len(apps) == 0:
-        raise Exception("No apps to process.")
+        raise FDroidException("No apps to process.")
 
     if options.latest:
         for app in apps:
@@ -1046,9 +1043,7 @@ def main():
                 logfile = open(os.path.join(log_dir, app['id'] + '.log'), 'a+')
                 logfile.write(str(be))
                 logfile.close()
-                reason = str(be).split('\n', 1)[0] if options.verbose else str(be)
-                logging.error("Could not build app %s due to BuildException: %s" % (
-                    app['id'], reason))
+                print("Could not build app %s due to BuildException: %s" % (app['id'], be))
                 if options.stop:
                     sys.exit(1)
                 failed_apps[app['id']] = be
@@ -1075,7 +1070,7 @@ def main():
                     txt = "Build completed at " + time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime()) + "\n\n" + wikilog
                     newpage.save(txt, summary='Build log')
                 except:
-                    logging.info("Error while attempting to publish build log")
+                    logging.error("Error while attempting to publish build log")
 
     for app in build_succeeded:
         logging.info("success: %s" % (app['id']))