From 9800ed1a1aaa3953b2484e4337b2a7b78922b020 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Mon, 15 Feb 2016 12:01:38 +0000 Subject: [PATCH] output= is now a glob path and can do gradle --- docs/fdroid.texi | 10 ++++++---- fdroidserver/build.py | 41 ++++++++++++++++++++++++---------------- fdroidserver/common.py | 4 ++-- fdroidserver/lint.py | 2 +- fdroidserver/metadata.py | 11 ++++++++++- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/docs/fdroid.texi b/docs/fdroid.texi index 96545d73..7d347070 100644 --- a/docs/fdroid.texi +++ b/docs/fdroid.texi @@ -1120,10 +1120,12 @@ For example: @code{gradleprops=enableFoo,someSetting=bar} will result in Specify an alternate set of Ant commands (target) instead of the default 'release'. It can't be given any flags, such as the path to a build.xml. -@item output=path/to/output.apk -To be used when app is built with a tool other than the ones natively -supported, like GNU Make. The given path will be where the build= set of -commands should produce the final unsigned release apk. +@item output=glob/to/output.apk +Specify a glob path where the resulting unsigned release apk from the +build should be. This can be used in combination with build methods like +@code{gradle=yes} or @code{maven=yes}, but if no build method is +specified, the build is manual. You should run your build commands, such +as @code{make}, in @code{build=}. @item novcheck=yes Don't check that the version name and code in the resulting apk are diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 12cc61c1..2d9e61bf 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -489,8 +489,8 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, # different from the default ones p = None gradletasks = [] - method = build.method() - if method == 'maven': + bmethod = build.build_method() + if bmethod == 'maven': logging.info("Cleaning Maven project...") cmd = [config['mvn3'], 'clean', '-Dandroid.sdk.path=' + config['sdk_path']] @@ -502,7 +502,7 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, p = FDroidPopen(cmd, cwd=maven_dir) - elif method == 'gradle': + elif bmethod == 'gradle': logging.info("Cleaning Gradle project...") @@ -529,10 +529,10 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, p = FDroidPopen(cmd, cwd=root_dir) - elif method == 'kivy': + elif bmethod == 'kivy': pass - elif method == 'ant': + elif bmethod == 'ant': logging.info("Cleaning Ant project...") p = FDroidPopen(['ant', 'clean'], cwd=root_dir) @@ -639,7 +639,7 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, p = None # Build the release... - if method == 'maven': + if bmethod == 'maven': logging.info("Building Maven project...") if '@' in build.maven: @@ -665,7 +665,7 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, bindir = os.path.join(root_dir, 'target') - elif method == 'kivy': + elif bmethod == 'kivy': logging.info("Building Kivy project...") spec = os.path.join(root_dir, 'buildozer.spec') @@ -726,7 +726,7 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, cmd.append('release') p = FDroidPopen(cmd, cwd=distdir) - elif method == 'gradle': + elif bmethod == 'gradle': logging.info("Building Gradle project...") cmd = [config['gradle']] @@ -737,7 +737,7 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, p = FDroidPopen(cmd, cwd=root_dir) - elif method == 'ant': + elif bmethod == 'ant': logging.info("Building Ant project...") cmd = ['ant'] if build.antcommands: @@ -752,7 +752,8 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, raise BuildException("Build failed for %s:%s" % (app.id, build.version), p.output) logging.info("Successfully built version " + build.version + ' of ' + app.id) - if method == 'maven': + omethod = build.output_method() + if omethod == 'maven': stdout_apk = '\n'.join([ line for line in p.output.splitlines() if any( a in line for a in ('.apk', '.ap_', '.jar'))]) @@ -772,12 +773,12 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, raise BuildException('Failed to find output') src = m.group(1) src = os.path.join(bindir, src) + '.apk' - elif method == 'kivy': + elif omethod == 'kivy': src = os.path.join('python-for-android', 'dist', 'default', 'bin', '{0}-{1}-release.apk'.format( bconfig.get('app', 'title'), bconfig.get('app', 'version'))) - elif method == 'gradle': + elif omethod == 'gradle': src = None for apks_dir in [ os.path.join(root_dir, 'build', 'outputs', 'apk'), @@ -798,15 +799,23 @@ def build_local(app, build, vcs, build_dir, output_dir, srclib_dir, extlib_dir, if src is None: raise BuildException('Failed to find any output apks') - elif method == 'ant': + elif omethod == 'ant': stdout_apk = '\n'.join([ 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) - elif method == 'raw': - src = os.path.join(root_dir, build.output) - src = os.path.normpath(src) + elif omethod == 'raw': + globpath = os.path.join(root_dir, build.output) + print(globpath) + globpath = os.path.normpath(globpath) + print(globpath) + apks = glob.glob(globpath) + if len(apks) > 1: + raise BuildException('Multiple apks match %s' % globpath, '\n'.join(apks)) + if len(apks) < 1: + raise BuildException('No apks match %s' % globpath) + src = os.path.normpath(apks[0]) # Make sure it's not debuggable... if common.isApkDebuggable(src, config): diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 0463db29..5a6c64ab 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1372,7 +1372,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= f.write(props) flavours = [] - if build.method() == 'gradle': + if build.build_method() == 'gradle': flavours = build.gradle if build.target: @@ -1461,7 +1461,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= (app.id, build.version), p.output) # Generate (or update) the ant build file, build.xml... - if build.method() == 'ant' and build.update != ['no']: + if build.build_method() == 'ant' and build.update != ['no']: parms = ['android', 'update', 'lib-project'] lparms = ['android', 'update', 'project'] diff --git a/fdroidserver/lint.py b/fdroidserver/lint.py index ee4381c0..8760e1db 100644 --- a/fdroidserver/lint.py +++ b/fdroidserver/lint.py @@ -305,7 +305,7 @@ def check_builds(app): ref = srclib.split('@')[1].split('/')[0] if ref.startswith(s): yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib) - if build.target and build.method() == 'gradle': + if build.target and build.build_method() == 'gradle': yield "target= has no gradle support" diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index b1924357..dc0055f2 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -331,7 +331,7 @@ class Build(): else: self.__dict__[f].append(v) - def method(self): + def build_method(self): for f in ['maven', 'gradle', 'kivy']: if self.get_flag(f): return f @@ -339,6 +339,15 @@ class Build(): return 'raw' return 'ant' + # like build_method, but prioritize output= + def output_method(self): + if self.output: + return 'raw' + for f in ['maven', 'gradle', 'kivy']: + if self.get_flag(f): + return f + return 'ant' + def ndk_path(self): version = self.ndk if not version: -- 2.30.2