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

View file

@ -30,6 +30,8 @@ from xml.dom.minidom import Document
from optparse import OptionParser
import common
from common import BuildException
from common import VCSException
#Read configuration...
execfile('config.py')
@ -76,7 +78,7 @@ for app in apps:
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'] + '_' +
@ -119,8 +121,7 @@ for app in apps:
parms.append('-t')
parms.append(thisbuild['target'])
if subprocess.call(parms, cwd=root_dir) != 0:
print "Failed to update project"
sys.exit(1)
raise BuildException("Failed to update project")
# If the app has ant set up to sign the release, we need to switch
# that off, because we want the unsigned apk...
@ -128,8 +129,7 @@ for app in apps:
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)
raise BuildException("Failed to amend %s" % propfile)
# Update the local.properties file...
locprops = os.path.join(root_dir, 'local.properties')
@ -157,14 +157,12 @@ for app in apps:
if subprocess.call(['sed','-i','s/' + thisbuild['insertversion'] +
'/' + thisbuild['version'] +'/g',
'AndroidManifest.xml'], cwd=root_dir) !=0:
print "Failed to amend manifest"
sys.exit(1)
raise BuildException("Failed to amend manifest")
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)
raise BuildException("Failed to amend manifest")
# Delete unwanted file...
if thisbuild.has_key('rm'):
@ -179,8 +177,7 @@ for app in apps:
r"\([^\\]\)'@\1\\'" +
'@g',
os.path.join(root, filename)]) != 0:
print "Failed to amend " + filename
sys.exit(1)
raise BuildException("Failed to amend " + filename)
# Fix translation files if necessary...
if thisbuild.get('fixtrans', 'no') == 'yes':
@ -225,8 +222,7 @@ for app in apps:
if thisbuild.has_key('prebuild'):
if subprocess.call(thisbuild['prebuild'],
cwd=root_dir, shell=True) != 0:
print "Error running pre-build command"
sys.exit(1)
raise BuildException("Error running pre-build command")
# Apply patches if any
if 'patch' in thisbuild:
@ -235,8 +231,7 @@ for app in apps:
patch_path = os.path.join('metadata', app['id'], patch)
if subprocess.call(['patch', '-p1',
'-i', os.path.abspath(patch_path)], cwd=build_dir) != 0:
print "Failed to apply patch %s" % patch_path
sys.exit(1)
raise BuildException("Failed to apply patch %s" % patch_path)
# Special case init functions for funambol...
if thisbuild.get('initfun', 'no') == "yes":
@ -251,8 +246,7 @@ for app in apps:
'</taskdef>' +
'@g',
'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml"
sys.exit(1)
raise BuildException("Failed to amend build.xml")
if subprocess.call(['sed','-i','s@' +
'\${user.home}/funambol/build/android/build.properties' +
@ -260,8 +254,7 @@ for app in apps:
'build.properties' +
'@g',
'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml"
sys.exit(1)
raise BuildException("Failed to amend build.xml")
buildxml = os.path.join(root_dir, 'build.xml')
f = open(buildxml, 'r')
@ -290,8 +283,7 @@ for app in apps:
'platforms/android-8' +
'@g',
'build.xml'], cwd=root_dir) !=0:
print "Failed to amend build.xml"
sys.exit(1)
raise BuildException("Failed to amend build.xml")
shutil.copyfile(
os.path.join(root_dir, "build.properties.example"),
@ -303,8 +295,7 @@ for app in apps:
'javacchome=' + javacc_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
raise BuildException("Failed to amend build.properties")
if subprocess.call(['sed','-i','s@' +
'sdk-folder=.*'+
@ -312,8 +303,7 @@ for app in apps:
'sdk-folder=' + sdk_path +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
raise BuildException("Failed to amend build.properties")
if subprocess.call(['sed','-i','s@' +
'android.sdk.version.*'+
@ -321,8 +311,7 @@ for app in apps:
'android.sdk.version=2.0' +
'@g',
'build.properties'], cwd=root_dir) !=0:
print "Failed to amend build.properties"
sys.exit(1)
raise BuildException("Failed to amend build.properties")
# Build the source tarball right before we build the release...
@ -340,8 +329,7 @@ for app in apps:
output = p.communicate()[0]
if p.returncode != 0:
print output
print "NDK build failed for %s:%s" % (app['id'], thisbuild['version'])
sys.exit(1)
raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']))
elif options.verbose:
print output
@ -360,8 +348,7 @@ for app in apps:
output = p.communicate()[0]
if p.returncode != 0:
print output
print "Build failed for %s:%s" % (app['id'], thisbuild['version'])
sys.exit(1)
raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']))
elif options.verbose:
print output
print "Build successful"
@ -407,8 +394,7 @@ for app in apps:
pat = re.compile(".*versionName='([^']*)'.*")
version = re.match(pat, line).group(1)
if version == None or vercode == None:
print "Could not find version information in build in output"
sys.exit(1)
raise BuildException("Could not find version information in build in output")
# Some apps (e.g. Timeriffic) have had the bonkers idea of
# including the entire changelog in the version number. Remove
@ -420,11 +406,10 @@ for app in apps:
if (version != thisbuild['version'] or
vercode != thisbuild['vercode']):
print "Unexpected version/version code in output"
print "APK:" + version + " / " + str(vercode)
print ("Expected: " + thisbuild['version'] + " / " +
str(thisbuild['vercode']))
sys.exit(1)
raise BuildException(("Unexpected version/version code in output"
"APK: %s / %s"
"Expected: %s / %s")
) % (version, str(vercode), thisbuild['version'], str(thisbuild['vercode']))
# Copy the unsigned apk to our temp directory for further
# processing...
@ -462,8 +447,7 @@ for app in apps:
output = p.communicate()[0]
print output
if p.returncode != 0:
print "Failed to generate key"
sys.exit(1)
raise BuildException("Failed to generate key")
# Sign the application...
p = subprocess.Popen(['jarsigner', '-keystore', keystore,
@ -472,8 +456,7 @@ for app in apps:
output = p.communicate()[0]
print output
if p.returncode != 0:
print "Failed to sign application"
sys.exit(1)
raise BuildException("Failed to sign application")
# Zipalign it...
p = subprocess.Popen([os.path.join(sdk_path,'tools','zipalign'),
@ -482,9 +465,14 @@ for app in apps:
output = p.communicate()[0]
print output
if p.returncode != 0:
print "Failed to align application"
sys.exit(1)
raise BuildException("Failed to align application")
os.remove(dest_unsigned)
except BuildException as be:
print "Could not build app %s due to BuildException: %s" % (app['id'], be)
except VCSException as vcse:
print "VCS error while building app %s: %s" % (app['id'], vcse)
except Exception as e:
print "Could not build app %s due to unknown error: %s" % (app['id'], e)
print "Finished."