Try and adapt checkupdates to gradle better

This commit is contained in:
Daniel Martí 2013-08-13 12:02:48 +02:00
parent 1e7bfc9864
commit 578e030ee6
2 changed files with 65 additions and 50 deletions

View file

@ -74,9 +74,8 @@ def check_tags(app, sdk_path):
vcs.gotorevision(tag) vcs.gotorevision(tag)
# Only process tags where the manifest exists... # Only process tags where the manifest exists...
path = common.manifest_path(build_dir, flavour) paths = common.manifest_paths(build_dir, flavour)
if path is not None: version, vercode, package = common.parse_androidmanifests(paths)
version, vercode, package = common.parse_androidmanifest(path)
print "Manifest exists. Found version %s" % version print "Manifest exists. Found version %s" % version
if package and package == app['id'] and version and vercode: if package and package == app['id'] and version and vercode:
if int(vercode) > int(hcode): if int(vercode) > int(hcode):
@ -149,11 +148,9 @@ def check_repomanifest(app, sdk_path, branch=None):
if not os.path.isdir(build_dir): if not os.path.isdir(build_dir):
return (None, "Subdir '" + app['builds'][-1]['subdir'] + "'is not a valid directory") return (None, "Subdir '" + app['builds'][-1]['subdir'] + "'is not a valid directory")
path = common.manifest_path(build_dir, flavour) paths = common.manifest_paths(build_dir, flavour)
if path is None:
return (None, "No manifest could be found")
version, vercode, package = common.parse_androidmanifest(path) version, vercode, package = common.parse_androidmanifest(paths)
if not package: if not package:
return (None, "Couldn't find package ID") return (None, "Couldn't find package ID")
if package != app['id']: if package != app['id']:

View file

@ -875,26 +875,19 @@ def retrieve_string(app_dir, string_id):
return s.replace("\\'","'") return s.replace("\\'","'")
return '' return ''
# Find the AM.xml - try to use new gradle manifest paths # Return list of existing AM.xml files that will be used to find the highest
# TODO: Gradle can use multiple manifests. Return a list of the existing ones # vercode
# and later iterate through them to find the highest vercode. def manifest_paths(app_dir, flavour):
def manifest_path(app_dir, flavour):
possible_manifests = [ os.path.join(app_dir, 'AndroidManifest.xml'),
os.path.join(app_dir, 'src', 'main', 'AndroidManifest.xml'),
os.path.join(app_dir, 'build.gradle') ]
root_manifest = os.path.join(app_dir, 'AndroidManifest.xml')
if flavour is not None: if flavour is not None:
flavour_manifest = os.path.join(app_dir, 'src', flavour, 'AndroidManifest.xml') possible_manifests.append(
if os.path.isfile(flavour_manifest): os.path.join(app_dir, 'src', flavour, 'AndroidManifest.xml'))
return flavour_manifest
main_manifest = os.path.join(app_dir, 'src', 'main', 'AndroidManifest.xml') return [path for path in possible_manifests if os.path.isfile(path)]
print main_manifest
if os.path.isfile(main_manifest):
return main_manifest
if os.path.isfile(root_manifest):
return root_manifest
return None
# Retrieve the package name # Retrieve the package name
@ -921,31 +914,56 @@ def fetch_real_name(app_dir):
# Extract some information from the AndroidManifest.xml at the given path. # Extract some information from the AndroidManifest.xml at the given path.
# Returns (version, vercode, package), any or all of which might be None. # Returns (version, vercode, package), any or all of which might be None.
# All values returned are strings. # All values returned are strings.
def parse_androidmanifest(manifest): def parse_androidmanifests(paths):
vcsearch = re.compile(r'.*android:versionCode="([0-9]+?)".*').search vcsearch = re.compile(r'.*android:versionCode="([0-9]+?)".*').search
vnsearch = re.compile(r'.*android:versionName="([^"]+?)".*').search vnsearch = re.compile(r'.*android:versionName="([^"]+?)".*').search
psearch = re.compile(r'.*package="([^"]+)".*').search psearch = re.compile(r'.*package="([^"]+)".*').search
vnsearch_xml = re.compile(r'.*"(app_|)version">([^<]+?)<.*').search
vcsearch_g = re.compile(r'.*versionCode[ ]+?([0-9]+?).*').search
vnsearch_g = re.compile(r'.*versionName[ ]+?"([^"]+?)".*').search
psearch_g = re.compile(r'.*packageName[ ]+?"([^"]+)".*').search
max_version = None
max_vercode = None
max_package = None
for path in paths:
gradle = path.endswith("build.gradle")
version = None version = None
vercode = None vercode = None
package = None package = None
for line in file(manifest):
for line in file(path):
if not package: if not package:
if gradle:
matches = psearch_g(line)
else:
matches = psearch(line) matches = psearch(line)
if matches: if matches:
package = matches.group(1) package = matches.group(1)
if not version: if not version:
if gradle:
matches = vnsearch_g(line)
else:
matches = vnsearch(line) matches = vnsearch(line)
if matches: if matches:
version = matches.group(1) version = matches.group(1)
if not vercode: if not vercode:
if gradle:
matches = vcsearch_g(line)
else:
matches = vcsearch(line) matches = vcsearch(line)
if matches: if matches:
vercode = matches.group(1) vercode = matches.group(1)
#if version.startswith('@string/'):
#version = retrieve_string(app_dir, version[8:]) if max_vercode is None or (vercode is not None and vercode > max_vercode):
return (version, vercode, package) max_version = version
max_vercode = vercode
max_package = package
return (max_version, max_vercode, max_package)
class BuildException(Exception): class BuildException(Exception):
def __init__(self, value, stdout = None, stderr = None): def __init__(self, value, stdout = None, stderr = None):