Bug 1249166 - Pre: Set JAVA_HOME in |mach gradle|. r=me
authorNick Alexander <nalexander@mozilla.com>
Thu, 18 Feb 2016 09:06:39 -0800
changeset 285532 7e9b0b20ccfa364efa31ea58edca8ad9d9d33a97
parent 285531 53864eca4327bae591fc060033708aca47b6773d
child 285533 b93cdb44b64b2bf8267698669b5548fc9ab613ec
push id72403
push usercbook@mozilla.com
push dateThu, 25 Feb 2016 10:59:17 +0000
treeherdermozilla-inbound@3b913f81cb98 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1249166 - Pre: Set JAVA_HOME in |mach gradle|. r=me MozReview-Commit-ID: 4qQz5ZZJqik
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -233,17 +233,19 @@ task syncPreprocessedCode(type: Sync, de
 // The localization system uses the moz.build preprocessor to interpolate a .dtd
 // file of XML entity definitions into an XML file of elements referencing those
 // entities.  (Each locale produces its own .dtd file, backstopped by the en-US
 // .dtd file in tree.)  Android Studio (and IntelliJ) don't handle these inline
 // entities smoothly.  This filter merely expands the entities in place, making
-// them appear properly throughout the IDE.
+// them appear properly throughout the IDE.  Be aware that this assumes that the
+// JVM's file.encoding is utf-8.  See comments in
+// mobile/android/mach_commands.py.
 class ExpandXMLEntitiesFilter extends FilterReader {
     ExpandXMLEntitiesFilter(Reader input) {
         // Extremely inefficient, but whatever.
         super(new StringReader(groovy.xml.XmlUtil.serialize(new XmlParser(false, false, true).parse(input))))
 task syncPreprocessedResources(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
--- a/mobile/android/mach_commands.py
+++ b/mobile/android/mach_commands.py
@@ -52,27 +52,36 @@ class MachCommands(MachCommandBase):
     @Command('gradle', category='devenv',
         description='Run gradle.',
     @CommandArgument('args', nargs=argparse.REMAINDER)
     def gradle(self, args):
         # Avoid logging the command
+        # In automation, JAVA_HOME is set via mozconfig, which needs
+        # to be specially handled in each mach command. This turns
+        # $JAVA_HOME/bin/java into $JAVA_HOME.
+        java_home = os.path.dirname(os.path.dirname(self.substs['JAVA']))
         # We force the Gradle JVM to run with the UTF-8 encoding, since we
         # filter strings.xml, which is really UTF-8; the ellipsis character is
         # replaced with ??? in some encodings (including ASCII).  It's not yet
         # possible to filter with encodings in Gradle
         # (https://github.com/gradle/gradle/pull/520) and it's challenging to
         # do our filtering with Gradle's Ant support.  Moreover, all of the
         # Android tools expect UTF-8: see
         # http://tools.android.com/knownissues/encoding.  See
         # http://stackoverflow.com/a/21267635 for discussion of this approach.
         return self.run_process([self.substs['GRADLE']] + args,
-            append_env={'GRADLE_OPTS': '-Dfile.encoding=utf-8'},
+            append_env={
+                'GRADLE_OPTS': '-Dfile.encoding=utf-8',
+                'JAVA_HOME': java_home,
+            },
             pass_thru=True, # Allow user to run gradle interactively.
             ensure_exit_code=False, # Don't throw on non-zero exit code.
     @Command('gradle-install', category='devenv',
     def gradle_install(self):