chiark / gitweb /
Move more logging.info stuff to debug
[fdroidserver.git] / fdroidserver / build.py
index ee14fa651a3f3f0125ca1e40268374e0ff02c70e..6a2aac282fa37f986a80b6a09db45157cbddefb7 100644 (file)
@@ -84,7 +84,7 @@ def vagrant(params, cwd=None, printout=False):
                is the stdout (and stderr) from vagrant
     """
     p = FDroidPopen(['vagrant'] + params, cwd=cwd)
-    return (p.returncode, p.stdout)
+    return (p.returncode, p.output)
 
 
 def get_vagrant_sshinfo():
@@ -136,7 +136,7 @@ def get_clean_vm(reset=False):
             p = FDroidPopen(['VBoxManage', 'snapshot',
                              get_builder_vm_id(), 'list',
                              '--details'], cwd='builder')
-            if 'fdroidclean' in p.stdout:
+            if 'fdroidclean' in p.output:
                 logging.info("...snapshot exists - resetting build server to "
                              "clean state")
                 retcode, output = vagrant(['status'], cwd='builder')
@@ -163,7 +163,7 @@ def get_clean_vm(reset=False):
                     logging.info("...failed to reset to snapshot")
             else:
                 logging.info("...snapshot doesn't exist - "
-                             "VBoxManage snapshot list:\n" + p.stdout)
+                             "VBoxManage snapshot list:\n" + p.output)
 
     # If we can't use the existing machine for any reason, make a
     # new one from scratch.
@@ -227,7 +227,7 @@ def get_clean_vm(reset=False):
         p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(),
                          'list', '--details'],
                         cwd='builder')
-        if 'fdroidclean' not in p.stdout:
+        if 'fdroidclean' not in p.output:
             raise BuildException("Failed to take snapshot.")
 
     return sshinfo
@@ -473,17 +473,11 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         logging.info("Cleaning Gradle project...")
         cmd = [config['gradle'], 'clean']
 
-        if '@' in thisbuild['gradle']:
-            gradle_dir = os.path.join(root_dir, thisbuild['gradle'].split('@', 1)[1])
-            gradle_dir = os.path.normpath(gradle_dir)
-        else:
-            gradle_dir = root_dir
-
         adapt_gradle(build_dir)
         for name, number, libpath in srclibpaths:
             adapt_gradle(libpath)
 
-        p = FDroidPopen(cmd, cwd=gradle_dir)
+        p = FDroidPopen(cmd, cwd=root_dir)
 
     elif thisbuild['type'] == 'kivy':
         pass
@@ -494,12 +488,12 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
 
     if p is not None and p.returncode != 0:
         raise BuildException("Error cleaning %s:%s" %
-                             (app['id'], thisbuild['version']), p.stdout)
+                             (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'))
@@ -560,7 +554,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
 
         if p.returncode != 0:
             raise BuildException("Error running build command for %s:%s" %
-                                 (app['id'], thisbuild['version']), p.stdout)
+                                 (app['id'], thisbuild['version']), p.output)
 
     # Build native stuff if required...
     if thisbuild['buildjni'] and thisbuild['buildjni'] != ['no']:
@@ -588,7 +582,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
                 del manifest_text
             p = FDroidPopen(cmd, cwd=os.path.join(root_dir, d))
             if p.returncode != 0:
-                raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout)
+                raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']), p.output)
 
     p = None
     # Build the release...
@@ -685,13 +679,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
 
     elif thisbuild['type'] == 'gradle':
         logging.info("Building Gradle project...")
-        if '@' in thisbuild['gradle']:
-            flavours = thisbuild['gradle'].split('@')[0].split(',')
-            gradle_dir = thisbuild['gradle'].split('@')[1]
-            gradle_dir = os.path.join(root_dir, gradle_dir)
-        else:
-            flavours = thisbuild['gradle'].split(',')
-            gradle_dir = root_dir
+        flavours = thisbuild['gradle'].split(',')
 
         if len(flavours) == 1 and flavours[0] in ['main', 'yes', '']:
             flavours[0] = ''
@@ -707,11 +695,10 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         commands += ['assemble' + flavours_cmd + 'Release']
 
         # Avoid having to use lintOptions.abortOnError false
-        # TODO: Do flavours or project names change this task name?
-        if LooseVersion('0.8') <= thisbuild['gradlepluginver'] < LooseVersion('0.11'):
+        if thisbuild['gradlepluginver'] >= LooseVersion('0.8'):
             commands += ['-x', 'lintVital' + flavours_cmd + 'Release']
 
-        p = FDroidPopen(commands, cwd=gradle_dir)
+        p = FDroidPopen(commands, cwd=root_dir)
 
     elif thisbuild['type'] == 'ant':
         logging.info("Building Ant project...")
@@ -725,12 +712,12 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         bindir = os.path.join(root_dir, 'bin')
 
     if p is not None and p.returncode != 0:
-        raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout)
+        raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), p.output)
     logging.info("Successfully built version " + thisbuild['version'] + ' of ' + app['id'])
 
     if thisbuild['type'] == 'maven':
         stdout_apk = '\n'.join([
-            line for line in p.stdout.splitlines() if any(a in line for a in ('.apk', '.ap_'))])
+            line for line in p.output.splitlines() if any(a in line for a in ('.apk', '.ap_'))])
         m = re.match(r".*^\[INFO\] .*apkbuilder.*/([^/]*)\.apk",
                      stdout_apk, re.S | re.M)
         if not m:
@@ -766,7 +753,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
             src = os.path.join(dd, 'build', 'apk', name + '.apk')
     elif thisbuild['type'] == 'ant':
         stdout_apk = '\n'.join([
-            line for line in p.stdout.splitlines() if '.apk' in line])
+            line for line in p.output.splitlines() if '.apk' in line])
         src = re.match(r".*^.*Creating (.+) for release.*$.*", stdout_apk,
                        re.S | re.M).group(1)
         src = os.path.join(bindir, src)
@@ -784,15 +771,13 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
     if not os.path.exists(src):
         raise BuildException("Unsigned apk is not at expected location of " + src)
 
-    p = SilentPopen([os.path.join(config['sdk_path'], 'build-tools',
-                                  config['build_tools'], 'aapt'),
-                     'dump', 'badging', src])
+    p = SilentPopen([config['aapt'], 'dump', 'badging', src])
 
     vercode = None
     version = None
     foundid = None
     nativecode = None
-    for line in p.stdout.splitlines():
+    for line in p.output.splitlines():
         if line.startswith("package:"):
             pat = re.compile(".*name='([a-zA-Z0-9._]*)'.*")
             m = pat.match(line)
@@ -816,7 +801,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
         nativecode = None if not nativecode else nativecode
 
     if thisbuild['buildjni'] and thisbuild['buildjni'] != ['no']:
-        if nativecode is not None:
+        if nativecode is None:
             raise BuildException("Native code should have been built but none was packaged")
     if thisbuild['novcheck']:
         vercode = thisbuild['vercode']
@@ -1062,20 +1047,23 @@ def main():
                 logfile.write(str(be))
                 logfile.close()
                 reason = str(be).split('\n', 1)[0] if options.verbose else str(be)
-                print("Could not build app %s due to BuildException: %s" % (
+                logging.error("Could not build app %s due to BuildException: %s" % (
                     app['id'], reason))
                 if options.stop:
                     sys.exit(1)
                 failed_apps[app['id']] = be
                 wikilog = be.get_wikitext()
             except VCSException as vcse:
-                print("VCS error while building app %s: %s" % (app['id'], vcse))
+                reason = str(vcse).split('\n', 1)[0] if options.verbose else str(vcse)
+                logging.error("VCS error while building app %s: %s" % (
+                    app['id'], reason))
                 if options.stop:
                     sys.exit(1)
                 failed_apps[app['id']] = vcse
                 wikilog = str(vcse)
             except Exception as e:
-                print("Could not build app %s due to unknown error: %s" % (app['id'], traceback.format_exc()))
+                logging.error("Could not build app %s due to unknown error: %s" % (
+                    app['id'], traceback.format_exc()))
                 if options.stop:
                     sys.exit(1)
                 failed_apps[app['id']] = e