Skip to content

Commit

Permalink
new rule to inject version name and code in the AndroidManifest.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Apr 14, 2015
1 parent 3c74b8f commit ac48512
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
29 changes: 21 additions & 8 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import re
### rules (no deps)

genrule(
name = 'fetch_deps',
srcs = [
'tools/fetch_buck_dependencies.py',
],
cmd = 'tools/fetch_buck_dependencies.py extlibs > $OUT',
out = '../../extlibs/dependencies.log',
name = 'fetch_deps',
srcs = [
'tools/fetch_buck_dependencies.py',
],
cmd = 'tools/fetch_buck_dependencies.py extlibs > $OUT',
out = '../../extlibs/dependencies.log',
)

### Helper functions
Expand Down Expand Up @@ -51,6 +51,19 @@ def get_build_config_values(filename):
values.append('String %s = "%s"' % (key, value))
return values

### Inject versionCode and versionName in the AndroidManifest.xml file

genrule(
name = 'processed_manifest',
srcs = [
'tools/inject_version_in_manifest.py',
'WordPress/src/main/AndroidManifest.xml',
'WordPress/build.gradle'
],
cmd = 'tools/inject_version_in_manifest.py WordPress/src/main/AndroidManifest.xml WordPress/build.gradle > $OUT',
out = 'AndroidManifest.xml',
)

### Define jar dependencies

r_android_library(
Expand Down Expand Up @@ -327,9 +340,9 @@ r_android_library(

android_binary(
name = 'wpandroid',
manifest = 'WordPress/src/main/AndroidManifest.xml',
target = 'Google Inc.:Google APIs:21',
manifest = ':processed_manifest',
keystore = ':debug_keystore',
package_type = 'debug',
deps = [
':fetch_deps',
':main-lib',
Expand Down
33 changes: 33 additions & 0 deletions tools/inject_version_in_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import sys
import xml.etree.ElementTree as ET
import xml.dom.minidom

def parse_inject_manifest(filename, versionCode, versionName):
manifest = xml.dom.minidom.parse(filename)
manifest.documentElement.setAttribute("android:versionCode", versionCode)
manifest.documentElement.setAttribute("android:versionName", versionName)
return manifest.toprettyxml(" ", "")

def get_version_from_build_gradle(filename):
versionCode = ''
versionName = ''
for sline in (line.strip() for line in open('WordPress/build.gradle').readlines()):
if sline.startswith("versionName"):
versionName = sline.split()[1].replace('"', '')
if sline.startswith("versionCode"):
versionCode = sline.split()[1]
return versionCode, versionName

def main():
if len(sys.argv) != 3:
print("Read versionCode and versionName in a build.gradle and inject it in a AndroidManifest.xml")
print("Usage: %s AndroidManifest.xml build.gradle" % sys.argv[0])
print("Example: %s AndroidManifest.xml build.gradle" % sys.argv[0])
sys.exit(1)
versionCode, versionName = get_version_from_build_gradle(sys.argv[2])
print(parse_inject_manifest(sys.argv[1], versionCode, versionName))

if __name__ == "__main__":
main()

0 comments on commit ac48512

Please sign in to comment.