From 04f74859490e5b3d374030c126ae1a3956a88f18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Fri, 8 Nov 2013 21:53:34 +0100 Subject: [PATCH] Don't allow values other than 'yes' or 'no' on boolean fields, integrity fixes --- fdroidserver/build.py | 29 ++++++++++--------- fdroidserver/common.py | 64 +++++++++++++++--------------------------- 2 files changed, 38 insertions(+), 55 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 6af132ed..b969cff4 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -347,22 +347,22 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d # We need to clean via the build tool in case the binary dirs are # different from the default ones p = None - if 'maven' in thisbuild: + if thisbuild.get('maven', 'no') != 'no': print "Cleaning Maven project..." cmd = [config['mvn3'], 'clean', '-Dandroid.sdk.path=' + config['sdk_path']] if '@' in thisbuild['maven']: - maven_dir = os.path.join(root_dir, thisbuild['maven'].split('@')[1]) + maven_dir = os.path.join(root_dir, thisbuild['maven'].split('@',1)[1]) else: maven_dir = root_dir p = FDroidPopen(cmd, cwd=maven_dir) - elif 'gradle' in thisbuild: + elif thisbuild.get('gradle', 'no') != 'no': print "Cleaning Gradle project..." cmd = [config['gradle'], 'clean'] if '@' in thisbuild['gradle']: - gradle_dir = os.path.join(root_dir, thisbuild['gradle'].split('@')[1]) + gradle_dir = os.path.join(root_dir, thisbuild['gradle'].split('@',1)[1]) else: gradle_dir = root_dir @@ -454,11 +454,11 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d p = None # Build the release... - if 'maven' in thisbuild: + if thisbuild.get('maven', 'no') != 'no': print "Building Maven project..." if '@' in thisbuild['maven']: - maven_dir = os.path.join(root_dir, thisbuild['maven'].split('@')[1]) + maven_dir = os.path.join(root_dir, thisbuild['maven'].split('@',1)[1]) else: maven_dir = root_dir @@ -482,7 +482,9 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d p = FDroidPopen(mvncmd, cwd=maven_dir) - elif 'gradle' in thisbuild: + bindir = os.path.join(root_dir, 'target') + + elif thisbuild.get('gradle', 'no') != 'no': print "Building Gradle project..." if '@' in thisbuild['gradle']: flavour = thisbuild['gradle'].split('@')[0] @@ -534,6 +536,8 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d cmd += ['release'] p = FDroidPopen(cmd, cwd=root_dir) + bindir = os.path.join(root_dir, 'bin') + if p.returncode != 0: raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout, p.stderr) print "Successfully built version " + thisbuild['version'] + ' of ' + app['id'] @@ -544,11 +548,8 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d # Find the apk name in the output... if 'bindir' in thisbuild: bindir = os.path.join(build_dir, thisbuild['bindir']) - elif 'maven' in thisbuild: - bindir = os.path.join(root_dir, 'target') - else: - bindir = os.path.join(root_dir, 'bin') - if 'maven' in thisbuild: + + if thisbuild.get('maven', 'no') != 'no': stdout_apk = '\n'.join([ line for line in p.stdout.splitlines() if any(a in line for a in ('.apk','.ap_'))]) m = re.match(r".*^\[INFO\] .*apkbuilder.*/([^/]*)\.apk", @@ -563,7 +564,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d raise BuildException('Failed to find output') src = m.group(1) src = os.path.join(bindir, src) + '.apk' - elif 'gradle' in thisbuild: + elif thisbuild.get('gradle', 'no') != 'no': dd = build_dir if 'subdir' in thisbuild: dd = os.path.join(dd, thisbuild['subdir']) @@ -606,7 +607,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d vercode = re.match(pat, line).group(1) pat = re.compile(".*versionName='([^']*)'.*") version = re.match(pat, line).group(1) - if thisbuild.get('novcheck', 'no') == "yes": + if thisbuild['novcheck']: vercode = thisbuild['vercode'] version = thisbuild['version'] if not version or not vercode: diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 6bc3b41e..dbf7db6c 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -523,6 +523,7 @@ def parse_metadata(metafile): for p in parts[3:]: pk, pv = p.split('=', 1) thisbuild[pk.strip()] = pv + return thisbuild def add_comments(key): @@ -532,6 +533,7 @@ def parse_metadata(metafile): thisinfo['comments'].append((key, comment)) del curcomments[:] + thisinfo = {} if metafile: if not isinstance(metafile, file): @@ -684,6 +686,20 @@ def parse_metadata(metafile): mode = 0 add_comments(None) + # These can only contain 'yes' or 'no' + for key in ('submodules', 'oldsdkloc', 'forceversion', 'forcevercode', 'fixtrans', 'fixapos', 'novcheck'): + for build in thisinfo['builds']: + if key not in build: + build[key] = False + continue + if build[key] == 'yes': + build[key] = True + elif build[key] == 'no': + build[key] = False + else: + raise MetaDataException("Invalid value %s assigned to boolean build flag %s" + % (build[key], key)) + # Mode at end of file should always be 0... if mode == 1: raise MetaDataException(field + " not terminated in " + metafile.name) @@ -1359,7 +1375,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= raise BuildException('Missing subdir ' + root_dir) # Initialise submodules if requred... - if build.get('submodules', 'no') == 'yes': + if build['submodules']: if options.verbose: print "Initialising submodules..." vcs.initsubmodules() @@ -1449,7 +1465,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= props += '\n' # Fix old-fashioned 'sdk-location' by copying # from sdk.dir, if necessary... - if build.get('oldsdkloc', 'no') == "yes": + if build['oldsdkloc']: sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props, re.S|re.M).group(1) props += "sdk-location=%s\n" % sdkloc @@ -1467,7 +1483,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= f.close() flavour = None - if 'gradle' in build: + if build.get('gradle', 'no') != 'no': flavour = build['gradle'].split('@')[0] if flavour in ['main', 'yes', '']: flavour = None @@ -1482,7 +1498,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= raise BuildException("Failed to remove debuggable flags") # Insert version code and number into the manifest if necessary... - if 'forceversion' in build: + if build['forceversion']: print "Changing the version name..." for path in manifest_paths(root_dir, flavour): if not os.path.isfile(path): @@ -1497,7 +1513,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= 's/versionName[ ]*=[ ]*"[^"]*"/versionName = "' + build['version'] + '"/g', path]) != 0: raise BuildException("Failed to amend build.gradle") - if 'forcevercode' in build: + if build['forcevercode']: print "Changing the version code..." for path in manifest_paths(root_dir, flavour): if not os.path.isfile(path): @@ -1524,7 +1540,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= subprocess.call('rm -rf ' + dest, shell=True) # Fix apostrophes translation files if necessary... - if build.get('fixapos', 'no') == 'yes': + if build['fixapos']: for root, dirs, files in os.walk(os.path.join(root_dir, 'res')): for filename in files: if filename.endswith('.xml'): @@ -1535,7 +1551,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= raise BuildException("Failed to amend " + filename) # Fix translation files if necessary... - if build.get('fixtrans', 'no') == 'yes': + if build['fixtrans']: for root, dirs, files in os.walk(os.path.join(root_dir, 'res')): for filename in files: if filename.endswith('.xml'): @@ -1624,40 +1640,6 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver= if p.returncode != 0: raise BuildException("Error running prebuild command for %s:%s" % (app['id'], build['version']), p.stdout, p.stderr) - print "Applying generic clean-ups..." - - if build.get('anal-tics', 'no') == 'yes': - fp = os.path.join(root_dir, 'src', 'com', 'google', 'android', 'apps', 'analytics') - os.makedirs(fp) - with open(os.path.join(fp, 'GoogleAnalyticsTracker.java'), 'w') as f: - f.write(""" - package com.google.android.apps.analytics; - public class GoogleAnalyticsTracker { - private static GoogleAnalyticsTracker instance; - private GoogleAnalyticsTracker() { - } - public static GoogleAnalyticsTracker getInstance() { - if(instance == null) - instance = new GoogleAnalyticsTracker(); - return instance; - } - public void start(String i,int think ,Object not) { - } - public void dispatch() { - } - public void stop() { - } - public void setProductVersion(String uh, String hu) { - } - public void trackEvent(String that,String just,String aint,int happening) { - } - public void trackPageView(String nope) { - } - public void setCustomVar(int mind,String your,String own,int business) { - } - } - """) - return (root_dir, srclibpaths) -- 2.30.2