From a546013756ae7c145661a311f7f1074bcf733a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 27 Oct 2013 23:43:38 +0100 Subject: [PATCH] Clean gradle signing configs all at once --- fdroidserver/build.py | 2 -- fdroidserver/common.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 21b27e9a..e272815c 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -336,8 +336,6 @@ def adapt_gradle(path, verbose): subprocess.call(['sed', '-i', 's@com.android.tools.build:gradle:[0-9\.\+]*@com.android.tools.build:gradle:'+gradle_plugin+'@g', path]) - subprocess.call(['sed', '-i', '/signingConfig /d', path]) - def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, install, force, verbose, onserver): """Do a build locally.""" diff --git a/fdroidserver/common.py b/fdroidserver/common.py index c5ef55c0..4687d0cd 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1290,6 +1290,12 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, sdk_path, else: root_dir = build_dir + if 'gradle' in build: + if '@' in build['gradle']: + gradle_dir = os.path.join(root_dir, build['gradle'].split('@')[1]) + else: + gradle_dir = root_dir + # Get a working copy of the right revision... print "Getting source for revision " + build['commit'] vcs.gotorevision(build['commit']) @@ -1379,6 +1385,11 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, sdk_path, if subprocess.call(['sed','-i','s/^key.store/#/', propfile], cwd=root_dir) !=0: raise BuildException("Failed to amend %s" % propfile) + for root, dirs, files in os.walk(gradle_dir): + for f in files: + if f == 'build.gradle': + clean_gradle_keys(os.path.join(root, f), verbose) + break # Update the local.properties file... locprops = os.path.join(root_dir, 'local.properties') @@ -1898,3 +1909,25 @@ def FDroidPopen(commands, cwd, p.communicate() result.returncode = p.returncode return result + +def clean_gradle_keys(path, verbose): + if verbose: + print "Cleaning build.gradle of keysigning configs at %s" % path + + lines = None + with open(path, "r") as o: + lines = o.readlines() + + opened = 0 + with open(path, "w") as o: + for line in lines: + if 'signingConfigs ' in line: + opened = 1 + elif opened > 0: + if '{' in line: + opened += 1 + elif '}' in line: + opened -=1 + elif 'signingConfig' not in line: + o.write(line) +