chiark / gitweb /
build: check that metadata is present before creating tmp dirs
[fdroidserver.git] / fdroidserver / build.py
index d792132d570d42dbcbd2e87a36ad2c839c32b0ca..12cc61c144d57894fda53d8be57ad9e2f62d5ea1 100644 (file)
@@ -30,7 +30,6 @@ import time
 import json
 from ConfigParser import ConfigParser
 from argparse import ArgumentParser
-from distutils.version import LooseVersion
 import logging
 
 import common
@@ -179,16 +178,15 @@ def get_clean_vm(reset=False):
 
         p = subprocess.Popen(['vagrant', '--version'],
                              stdout=subprocess.PIPE)
-        vver = p.communicate()[0]
+        vver = p.communicate()[0].strip().split(' ')[1]
+        if vver.split('.')[0] != '1' or int(vver.split('.')[1]) < 4:
+            raise BuildException("Unsupported vagrant version {0}".format(vver))
+
         with open(os.path.join('builder', 'Vagrantfile'), 'w') as vf:
-            if vver.startswith('Vagrant version 1.2'):
-                vf.write('Vagrant.configure("2") do |config|\n')
-                vf.write('config.vm.box = "buildserver"\n')
-                vf.write('end\n')
-            else:
-                vf.write('Vagrant::Config.run do |config|\n')
-                vf.write('config.vm.box = "buildserver"\n')
-                vf.write('end\n')
+            vf.write('Vagrant.configure("2") do |config|\n')
+            vf.write('config.vm.box = "buildserver"\n')
+            vf.write('config.vm.synced_folder ".", "/vagrant", disabled: true\n')
+            vf.write('end\n')
 
         logging.info("Starting new build server")
         retcode, _ = vagrant(['up'], cwd='builder')
@@ -527,11 +525,6 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir,
         if build.gradleprops:
             cmd += ['-P'+kv for kv in build.gradleprops]
 
-        for task in gradletasks:
-            parts = task.split(':')
-            parts[-1] = 'clean' + capitalize_intact(parts[-1])
-            cmd += [':'.join(parts)]
-
         cmd += ['clean']
 
         p = FDroidPopen(cmd, cwd=root_dir)
@@ -785,19 +778,26 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir,
                                bconfig.get('app', 'title'),
                                bconfig.get('app', 'version')))
     elif method == 'gradle':
+        src = None
+        for apks_dir in [
+                os.path.join(root_dir, 'build', 'outputs', 'apk'),
+                os.path.join(root_dir, 'build', 'apk'),
+                ]:
+            for apkglob in ['*-release-unsigned.apk', '*-unsigned.apk', '*.apk']:
+                apks = glob.glob(os.path.join(apks_dir, apkglob))
+
+                if len(apks) > 1:
+                    raise BuildException('More than one resulting apks found in %s' % apks_dir,
+                                         '\n'.join(apks))
+                if len(apks) == 1:
+                    src = apks[0]
+                    break
+            if src is not None:
+                break
+
+        if src is None:
+            raise BuildException('Failed to find any output apks')
 
-        if build.gradlepluginver >= LooseVersion('0.11'):
-            apks_dir = os.path.join(root_dir, 'build', 'outputs', 'apk')
-        else:
-            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 method == 'ant':
         stdout_apk = '\n'.join([
             line for line in p.output.splitlines() if '.apk' in line])
@@ -1001,6 +1001,15 @@ def main():
     global options, config
 
     options, parser = parse_commandline()
+
+    metadata_files = glob.glob('.fdroid.*[a-z]')  # ignore files ending in ~
+    if len(metadata_files) > 1:
+        raise FDroidException("Only one local metadata file allowed! Found: "
+                              + " ".join(metadata_files))
+
+    if not os.path.isdir('metadata') and len(metadata_files) == 0:
+        raise FDroidException("No app metadata found, nothing to process!")
+
     if not options.appid and not options.all:
         parser.error("option %s: If you really want to build all the apps, use --all" % "all")