Don't abort on build exceptions.

This commit is contained in:
prcrst 2012-01-02 15:09:20 +01:00 committed by Ciaran Gultnieks
parent 4ce764c676
commit dee53ffb72

728
build.py
View file

@ -30,6 +30,8 @@ from xml.dom.minidom import Document
from optparse import OptionParser from optparse import OptionParser
import common import common
from common import BuildException
from common import VCSException
#Read configuration... #Read configuration...
execfile('config.py') execfile('config.py')
@ -76,415 +78,401 @@ for app in apps:
for thisbuild in app['builds']: for thisbuild in app['builds']:
try:
dest = os.path.join(output_dir, app['id'] + '_' +
thisbuild['vercode'] + '.apk')
dest_unsigned = os.path.join(tmp_dir, app['id'] + '_' +
thisbuild['vercode'] + '_unsigned.apk')
dest = os.path.join(output_dir, app['id'] + '_' + if os.path.exists(dest):
thisbuild['vercode'] + '.apk') print "..version " + thisbuild['version'] + " already exists"
dest_unsigned = os.path.join(tmp_dir, app['id'] + '_' + elif thisbuild['commit'].startswith('!'):
thisbuild['vercode'] + '_unsigned.apk') print ("..skipping version " + thisbuild['version'] + " - " +
thisbuild['commit'][1:])
if os.path.exists(dest):
print "..version " + thisbuild['version'] + " already exists"
elif thisbuild['commit'].startswith('!'):
print ("..skipping version " + thisbuild['version'] + " - " +
thisbuild['commit'][1:])
else:
print "..building version " + thisbuild['version']
if not refreshed_source:
vcs.refreshlocal()
refreshed_source = True
# Optionally, the actual app source can be in a subdirectory...
if thisbuild.has_key('subdir'):
root_dir = os.path.join(build_dir, thisbuild['subdir'])
else: else:
root_dir = build_dir print "..building version " + thisbuild['version']
# Get a working copy of the right revision... if not refreshed_source:
if options.verbose: vcs.refreshlocal()
print "Resetting repository to " + thisbuild['commit'] refreshed_source = True
vcs.reset(thisbuild['commit'])
# Initialise submodules if requred... # Optionally, the actual app source can be in a subdirectory...
if thisbuild.get('submodules', 'no') == 'yes': if thisbuild.has_key('subdir'):
vcs.initsubmodules() root_dir = os.path.join(build_dir, thisbuild['subdir'])
else:
root_dir = build_dir
# Generate (or update) the ant build file, build.xml... # Get a working copy of the right revision...
if (thisbuild.get('update', 'yes') == 'yes' and if options.verbose:
not thisbuild.has_key('maven')): print "Resetting repository to " + thisbuild['commit']
parms = [os.path.join(sdk_path, 'tools', 'android'), vcs.reset(thisbuild['commit'])
'update', 'project', '-p', '.']
parms.append('--subprojects')
if thisbuild.has_key('target'):
parms.append('-t')
parms.append(thisbuild['target'])
if subprocess.call(parms, cwd=root_dir) != 0:
print "Failed to update project"
sys.exit(1)
# If the app has ant set up to sign the release, we need to switch # Initialise submodules if requred...
# that off, because we want the unsigned apk... if thisbuild.get('submodules', 'no') == 'yes':
for propfile in ('build.properties', 'default.properties'): vcs.initsubmodules()
if os.path.exists(os.path.join(root_dir, propfile)):
if subprocess.call(['sed','-i','s/^key.store/#/',
propfile], cwd=root_dir) !=0:
print "Failed to amend %s" % propfile
sys.exit(1)
# Update the local.properties file... # Generate (or update) the ant build file, build.xml...
locprops = os.path.join(root_dir, 'local.properties') if (thisbuild.get('update', 'yes') == 'yes' and
if os.path.exists(locprops): not thisbuild.has_key('maven')):
f = open(locprops, 'r') parms = [os.path.join(sdk_path, 'tools', 'android'),
props = f.read() 'update', 'project', '-p', '.']
f.close() parms.append('--subprojects')
# Fix old-fashioned 'sdk-location' by copying if thisbuild.has_key('target'):
# from sdk.dir, if necessary... parms.append('-t')
if thisbuild.get('oldsdkloc', 'no') == "yes": parms.append(thisbuild['target'])
sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props, if subprocess.call(parms, cwd=root_dir) != 0:
re.S|re.M).group(1) raise BuildException("Failed to update project")
props += "\nsdk-location=" + sdkloc + "\n"
# Add ndk location...
props+= "\nndk.dir=" + ndk_path + "\n"
# Add java.encoding if necessary...
if thisbuild.has_key('encoding'):
props += "\njava.encoding=" + thisbuild['encoding'] + "\n"
f = open(locprops, 'w')
f.write(props)
f.close()
# Insert version code and number into the manifest if necessary... # If the app has ant set up to sign the release, we need to switch
if thisbuild.has_key('insertversion'): # that off, because we want the unsigned apk...
if subprocess.call(['sed','-i','s/' + thisbuild['insertversion'] + for propfile in ('build.properties', 'default.properties'):
'/' + thisbuild['version'] +'/g', if os.path.exists(os.path.join(root_dir, propfile)):
'AndroidManifest.xml'], cwd=root_dir) !=0: if subprocess.call(['sed','-i','s/^key.store/#/',
print "Failed to amend manifest" propfile], cwd=root_dir) !=0:
sys.exit(1) raise BuildException("Failed to amend %s" % propfile)
if thisbuild.has_key('insertvercode'):
if subprocess.call(['sed','-i','s/' + thisbuild['insertvercode'] +
'/' + thisbuild['vercode'] +'/g',
'AndroidManifest.xml'], cwd=root_dir) !=0:
print "Failed to amend manifest"
sys.exit(1)
# Delete unwanted file... # Update the local.properties file...
if thisbuild.has_key('rm'): locprops = os.path.join(root_dir, 'local.properties')
os.remove(os.path.join(build_dir, thisbuild['rm'])) if os.path.exists(locprops):
f = open(locprops, 'r')
props = f.read()
f.close()
# Fix old-fashioned 'sdk-location' by copying
# from sdk.dir, if necessary...
if thisbuild.get('oldsdkloc', 'no') == "yes":
sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props,
re.S|re.M).group(1)
props += "\nsdk-location=" + sdkloc + "\n"
# Add ndk location...
props+= "\nndk.dir=" + ndk_path + "\n"
# Add java.encoding if necessary...
if thisbuild.has_key('encoding'):
props += "\njava.encoding=" + thisbuild['encoding'] + "\n"
f = open(locprops, 'w')
f.write(props)
f.close()
# Fix apostrophes translation files if necessary... # Insert version code and number into the manifest if necessary...
if thisbuild.get('fixapos', 'no') == 'yes': if thisbuild.has_key('insertversion'):
for root, dirs, files in os.walk(os.path.join(root_dir,'res')): if subprocess.call(['sed','-i','s/' + thisbuild['insertversion'] +
for filename in files: '/' + thisbuild['version'] +'/g',
if filename.endswith('.xml'): 'AndroidManifest.xml'], cwd=root_dir) !=0:
if subprocess.call(['sed','-i','s@' + raise BuildException("Failed to amend manifest")
r"\([^\\]\)'@\1\\'" + if thisbuild.has_key('insertvercode'):
'@g', if subprocess.call(['sed','-i','s/' + thisbuild['insertvercode'] +
os.path.join(root, filename)]) != 0: '/' + thisbuild['vercode'] +'/g',
print "Failed to amend " + filename 'AndroidManifest.xml'], cwd=root_dir) !=0:
sys.exit(1) raise BuildException("Failed to amend manifest")
# Fix translation files if necessary... # Delete unwanted file...
if thisbuild.get('fixtrans', 'no') == 'yes': if thisbuild.has_key('rm'):
for root, dirs, files in os.walk(os.path.join(root_dir,'res')): os.remove(os.path.join(build_dir, thisbuild['rm']))
for filename in files:
if filename.endswith('.xml'): # Fix apostrophes translation files if necessary...
f = open(os.path.join(root, filename)) if thisbuild.get('fixapos', 'no') == 'yes':
changed = False for root, dirs, files in os.walk(os.path.join(root_dir,'res')):
outlines = [] for filename in files:
for line in f: if filename.endswith('.xml'):
num = 1 if subprocess.call(['sed','-i','s@' +
index = 0 r"\([^\\]\)'@\1\\'" +
oldline = line '@g',
while True: os.path.join(root, filename)]) != 0:
index = line.find("%", index) raise BuildException("Failed to amend " + filename)
if index == -1:
break # Fix translation files if necessary...
next = line[index+1:index+2] if thisbuild.get('fixtrans', 'no') == 'yes':
if next == "s" or next == "d": for root, dirs, files in os.walk(os.path.join(root_dir,'res')):
line = (line[:index+1] + for filename in files:
str(num) + "$" + if filename.endswith('.xml'):
line[index+1:]) f = open(os.path.join(root, filename))
num += 1 changed = False
index += 3 outlines = []
else: for line in f:
index += 1 num = 1
# We only want to insert the positional arguments index = 0
# when there is more than one argument... oldline = line
if oldline != line: while True:
if num > 2: index = line.find("%", index)
changed = True if index == -1:
else: break
line = oldline next = line[index+1:index+2]
outlines.append(line) if next == "s" or next == "d":
f.close() line = (line[:index+1] +
if changed: str(num) + "$" +
f = open(os.path.join(root, filename), 'w') line[index+1:])
f.writelines(outlines) num += 1
index += 3
else:
index += 1
# We only want to insert the positional arguments
# when there is more than one argument...
if oldline != line:
if num > 2:
changed = True
else:
line = oldline
outlines.append(line)
f.close() f.close()
if changed:
f = open(os.path.join(root, filename), 'w')
f.writelines(outlines)
f.close()
# Run a pre-build command if one is required... # Run a pre-build command if one is required...
if thisbuild.has_key('prebuild'): if thisbuild.has_key('prebuild'):
if subprocess.call(thisbuild['prebuild'], if subprocess.call(thisbuild['prebuild'],
cwd=root_dir, shell=True) != 0: cwd=root_dir, shell=True) != 0:
print "Error running pre-build command" raise BuildException("Error running pre-build command")
sys.exit(1)
# Apply patches if any # Apply patches if any
if 'patch' in thisbuild: if 'patch' in thisbuild:
for patch in thisbuild['patch'].split(';'): for patch in thisbuild['patch'].split(';'):
print "Applying " + patch print "Applying " + patch
patch_path = os.path.join('metadata', app['id'], patch) patch_path = os.path.join('metadata', app['id'], patch)
if subprocess.call(['patch', '-p1', if subprocess.call(['patch', '-p1',
'-i', os.path.abspath(patch_path)], cwd=build_dir) != 0: '-i', os.path.abspath(patch_path)], cwd=build_dir) != 0:
print "Failed to apply patch %s" % patch_path raise BuildException("Failed to apply patch %s" % patch_path)
sys.exit(1)
# Special case init functions for funambol... # Special case init functions for funambol...
if thisbuild.get('initfun', 'no') == "yes": if thisbuild.get('initfun', 'no') == "yes":
if subprocess.call(['sed','-i','s@' + if subprocess.call(['sed','-i','s@' +
'<taskdef resource="net/sf/antcontrib/antcontrib.properties" />' + '<taskdef resource="net/sf/antcontrib/antcontrib.properties" />' +
'@' + '@' +
'<taskdef resource="net/sf/antcontrib/antcontrib.properties">' + '<taskdef resource="net/sf/antcontrib/antcontrib.properties">' +
'<classpath>' + '<classpath>' +
'<pathelement location="/usr/share/java/ant-contrib.jar"/>' + '<pathelement location="/usr/share/java/ant-contrib.jar"/>' +
'</classpath>' + '</classpath>' +
'</taskdef>' + '</taskdef>' +
'@g', '@g',
'build.xml'], cwd=root_dir) !=0: 'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml" raise BuildException("Failed to amend build.xml")
sys.exit(1)
if subprocess.call(['sed','-i','s@' + if subprocess.call(['sed','-i','s@' +
'\${user.home}/funambol/build/android/build.properties' + '\${user.home}/funambol/build/android/build.properties' +
'@' + '@' +
'build.properties' + 'build.properties' +
'@g', '@g',
'build.xml'], cwd=root_dir) !=0: 'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml" raise BuildException("Failed to amend build.xml")
sys.exit(1)
buildxml = os.path.join(root_dir, 'build.xml') buildxml = os.path.join(root_dir, 'build.xml')
f = open(buildxml, 'r') f = open(buildxml, 'r')
xml = f.read() xml = f.read()
f.close() f.close()
xmlout = "" xmlout = ""
mode = 0 mode = 0
for line in xml.splitlines(): for line in xml.splitlines():
if mode == 0: if mode == 0:
if line.find("jarsigner") != -1: if line.find("jarsigner") != -1:
mode = 1 mode = 1
else:
xmlout += line + "\n"
else: else:
xmlout += line + "\n" if line.find("/exec") != -1:
mode += 1
if mode == 3:
mode =0
f = open(buildxml, 'w')
f.write(xmlout)
f.close()
if subprocess.call(['sed','-i','s@' +
'platforms/android-2.0' +
'@' +
'platforms/android-8' +
'@g',
'build.xml'], cwd=root_dir) !=0:
raise BuildException("Failed to amend build.xml")
shutil.copyfile(
os.path.join(root_dir, "build.properties.example"),
os.path.join(root_dir, "build.properties"))
if subprocess.call(['sed','-i','s@' +
'javacchome=.*'+
'@' +
'javacchome=' + javacc_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
raise BuildException("Failed to amend build.properties")
if subprocess.call(['sed','-i','s@' +
'sdk-folder=.*'+
'@' +
'sdk-folder=' + sdk_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
raise BuildException("Failed to amend build.properties")
if subprocess.call(['sed','-i','s@' +
'android.sdk.version.*'+
'@' +
'android.sdk.version=2.0' +
'@g',
'build.properties'], cwd=root_dir) !=0:
raise BuildException("Failed to amend build.properties")
# Build the source tarball right before we build the release...
tarname = app['id'] + '_' + thisbuild['vercode'] + '_src'
tarball = tarfile.open(os.path.join(output_dir,
tarname + '.tar.gz'), "w:gz")
tarball.add(build_dir, tarname)
tarball.close()
# Build native stuff if required...
if thisbuild.get('buildjni', 'no') == 'yes':
ndkbuild = os.path.join(ndk_path, "ndk-build")
p = subprocess.Popen([ndkbuild], cwd=root_dir,
stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode != 0:
print output
raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']))
elif options.verbose:
print output
# Build the release...
if thisbuild.has_key('maven'):
p = subprocess.Popen(['mvn', 'clean', 'install',
'-Dandroid.sdk.path=' + sdk_path],
cwd=root_dir, stdout=subprocess.PIPE)
else:
if thisbuild.has_key('antcommand'):
antcommand = thisbuild['antcommand']
else: else:
if line.find("/exec") != -1: antcommand = 'release'
mode += 1 p = subprocess.Popen(['ant', antcommand], cwd=root_dir,
if mode == 3: stdout=subprocess.PIPE)
mode =0
f = open(buildxml, 'w')
f.write(xmlout)
f.close()
if subprocess.call(['sed','-i','s@' +
'platforms/android-2.0' +
'@' +
'platforms/android-8' +
'@g',
'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml"
sys.exit(1)
shutil.copyfile(
os.path.join(root_dir, "build.properties.example"),
os.path.join(root_dir, "build.properties"))
if subprocess.call(['sed','-i','s@' +
'javacchome=.*'+
'@' +
'javacchome=' + javacc_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
if subprocess.call(['sed','-i','s@' +
'sdk-folder=.*'+
'@' +
'sdk-folder=' + sdk_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
if subprocess.call(['sed','-i','s@' +
'android.sdk.version.*'+
'@' +
'android.sdk.version=2.0' +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
# Build the source tarball right before we build the release...
tarname = app['id'] + '_' + thisbuild['vercode'] + '_src'
tarball = tarfile.open(os.path.join(output_dir,
tarname + '.tar.gz'), "w:gz")
tarball.add(build_dir, tarname)
tarball.close()
# Build native stuff if required...
if thisbuild.get('buildjni', 'no') == 'yes':
ndkbuild = os.path.join(ndk_path, "ndk-build")
p = subprocess.Popen([ndkbuild], cwd=root_dir,
stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
print output print output
print "NDK build failed for %s:%s" % (app['id'], thisbuild['version']) raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']))
sys.exit(1)
elif options.verbose: elif options.verbose:
print output print output
print "Build successful"
# Build the release... # Find the apk name in the output...
if thisbuild.has_key('maven'): if thisbuild.has_key('bindir'):
p = subprocess.Popen(['mvn', 'clean', 'install', bindir = os.path.join(build_dir, thisbuild['bindir'])
'-Dandroid.sdk.path=' + sdk_path],
cwd=root_dir, stdout=subprocess.PIPE)
else:
if thisbuild.has_key('antcommand'):
antcommand = thisbuild['antcommand']
else: else:
antcommand = 'release' bindir = os.path.join(root_dir, 'bin')
p = subprocess.Popen(['ant', antcommand], cwd=root_dir, if thisbuild.get('initfun', 'no') == "yes":
stdout=subprocess.PIPE) # Special case (again!) for funambol...
output = p.communicate()[0] src = ("funambol-android-sync-client-" +
if p.returncode != 0: thisbuild['version'] + "-unsigned.apk")
print output src = os.path.join(bindir, src)
print "Build failed for %s:%s" % (app['id'], thisbuild['version']) elif thisbuild.has_key('maven'):
sys.exit(1) src = re.match(r".*^\[INFO\] Installing /.*/([^/]*)\.apk",
elif options.verbose: output, re.S|re.M).group(1)
print output src = os.path.join(bindir, src) + '.apk'
print "Build successful"
# Find the apk name in the output...
if thisbuild.has_key('bindir'):
bindir = os.path.join(build_dir, thisbuild['bindir'])
else:
bindir = os.path.join(root_dir, 'bin')
if thisbuild.get('initfun', 'no') == "yes":
# Special case (again!) for funambol...
src = ("funambol-android-sync-client-" +
thisbuild['version'] + "-unsigned.apk")
src = os.path.join(bindir, src)
elif thisbuild.has_key('maven'):
src = re.match(r".*^\[INFO\] Installing /.*/([^/]*)\.apk",
output, re.S|re.M).group(1)
src = os.path.join(bindir, src) + '.apk'
#[INFO] Installing /home/ciaran/fdroidserver/tmp/mainline/application/target/callerid-1.0-SNAPSHOT.apk #[INFO] Installing /home/ciaran/fdroidserver/tmp/mainline/application/target/callerid-1.0-SNAPSHOT.apk
else: else:
src = re.match(r".*^.*Creating (\S+) for release.*$.*", output, src = re.match(r".*^.*Creating (\S+) for release.*$.*", output,
re.S|re.M).group(1) re.S|re.M).group(1)
src = os.path.join(bindir, src) src = os.path.join(bindir, src)
# By way of a sanity check, make sure the version and version # By way of a sanity check, make sure the version and version
# code in our new apk match what we expect... # code in our new apk match what we expect...
print "Checking " + src print "Checking " + src
p = subprocess.Popen([os.path.join(sdk_path, 'platform-tools', p = subprocess.Popen([os.path.join(sdk_path, 'platform-tools',
'aapt'), 'aapt'),
'dump', 'badging', src], 'dump', 'badging', src],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
if thisbuild.get('novcheck', 'no') == "yes": if thisbuild.get('novcheck', 'no') == "yes":
vercode = thisbuild['vercode'] vercode = thisbuild['vercode']
version = thisbuild['version'] version = thisbuild['version']
else: else:
vercode = None vercode = None
version = None version = None
for line in output.splitlines(): for line in output.splitlines():
if line.startswith("package:"): if line.startswith("package:"):
pat = re.compile(".*versionCode='([0-9]*)'.*") pat = re.compile(".*versionCode='([0-9]*)'.*")
vercode = re.match(pat, line).group(1) vercode = re.match(pat, line).group(1)
pat = re.compile(".*versionName='([^']*)'.*") pat = re.compile(".*versionName='([^']*)'.*")
version = re.match(pat, line).group(1) version = re.match(pat, line).group(1)
if version == None or vercode == None: if version == None or vercode == None:
print "Could not find version information in build in output" raise BuildException("Could not find version information in build in output")
sys.exit(1)
# Some apps (e.g. Timeriffic) have had the bonkers idea of # Some apps (e.g. Timeriffic) have had the bonkers idea of
# including the entire changelog in the version number. Remove # including the entire changelog in the version number. Remove
# it so we can compare. (TODO: might be better to remove it # it so we can compare. (TODO: might be better to remove it
# before we compile, in fact) # before we compile, in fact)
index = version.find(" //") index = version.find(" //")
if index != -1: if index != -1:
version = version[:index] version = version[:index]
if (version != thisbuild['version'] or if (version != thisbuild['version'] or
vercode != thisbuild['vercode']): vercode != thisbuild['vercode']):
print "Unexpected version/version code in output" raise BuildException(("Unexpected version/version code in output"
print "APK:" + version + " / " + str(vercode) "APK: %s / %s"
print ("Expected: " + thisbuild['version'] + " / " + "Expected: %s / %s")
str(thisbuild['vercode'])) ) % (version, str(vercode), thisbuild['version'], str(thisbuild['vercode']))
sys.exit(1)
# Copy the unsigned apk to our temp directory for further # Copy the unsigned apk to our temp directory for further
# processing... # processing...
shutil.copyfile(src, dest_unsigned) shutil.copyfile(src, dest_unsigned)
# Figure out the key alias name we'll use. Only the first 8 # Figure out the key alias name we'll use. Only the first 8
# characters are significant, so we'll use the first 8 from # characters are significant, so we'll use the first 8 from
# the MD5 of the app's ID and hope there are no collisions. # the MD5 of the app's ID and hope there are no collisions.
# If a collision does occur later, we're going to have to # If a collision does occur later, we're going to have to
# come up with a new alogrithm, AND rename all existing keys # come up with a new alogrithm, AND rename all existing keys
# in the keystore! # in the keystore!
if keyaliases.has_key(app['id']): if keyaliases.has_key(app['id']):
# For this particular app, the key alias is overridden... # For this particular app, the key alias is overridden...
keyalias = keyaliases[app['id']] keyalias = keyaliases[app['id']]
else: else:
m = md5.new() m = md5.new()
m.update(app['id']) m.update(app['id'])
keyalias = m.hexdigest()[:8] keyalias = m.hexdigest()[:8]
print "Key alias: " + keyalias print "Key alias: " + keyalias
# See if we already have a key for this application, and # See if we already have a key for this application, and
# if not generate one... # if not generate one...
p = subprocess.Popen(['keytool', '-list', p = subprocess.Popen(['keytool', '-list',
'-alias', keyalias, '-keystore', keystore, '-alias', keyalias, '-keystore', keystore,
'-storepass', keystorepass], stdout=subprocess.PIPE) '-storepass', keystorepass], stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
if p.returncode !=0: if p.returncode !=0:
print "Key does not exist - generating..." print "Key does not exist - generating..."
p = subprocess.Popen(['keytool', '-genkey', p = subprocess.Popen(['keytool', '-genkey',
'-keystore', keystore, '-alias', keyalias, '-keystore', keystore, '-alias', keyalias,
'-keyalg', 'RSA', '-keysize', '2048', '-keyalg', 'RSA', '-keysize', '2048',
'-validity', '10000', '-validity', '10000',
'-storepass', keystorepass, '-keypass', keypass,
'-dname', keydname], stdout=subprocess.PIPE)
output = p.communicate()[0]
print output
if p.returncode != 0:
raise BuildException("Failed to generate key")
# Sign the application...
p = subprocess.Popen(['jarsigner', '-keystore', keystore,
'-storepass', keystorepass, '-keypass', keypass, '-storepass', keystorepass, '-keypass', keypass,
'-dname', keydname], stdout=subprocess.PIPE) dest_unsigned, keyalias], stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
print output print output
if p.returncode != 0: if p.returncode != 0:
print "Failed to generate key" raise BuildException("Failed to sign application")
sys.exit(1)
# Sign the application... # Zipalign it...
p = subprocess.Popen(['jarsigner', '-keystore', keystore, p = subprocess.Popen([os.path.join(sdk_path,'tools','zipalign'),
'-storepass', keystorepass, '-keypass', keypass, '-v', '4', dest_unsigned, dest],
dest_unsigned, keyalias], stdout=subprocess.PIPE) stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
print output print output
if p.returncode != 0: if p.returncode != 0:
print "Failed to sign application" raise BuildException("Failed to align application")
sys.exit(1) os.remove(dest_unsigned)
except BuildException as be:
# Zipalign it... print "Could not build app %s due to BuildException: %s" % (app['id'], be)
p = subprocess.Popen([os.path.join(sdk_path,'tools','zipalign'), except VCSException as vcse:
'-v', '4', dest_unsigned, dest], print "VCS error while building app %s: %s" % (app['id'], vcse)
stdout=subprocess.PIPE) except Exception as e:
output = p.communicate()[0] print "Could not build app %s due to unknown error: %s" % (app['id'], e)
print output
if p.returncode != 0:
print "Failed to align application"
sys.exit(1)
os.remove(dest_unsigned)
print "Finished." print "Finished."