servo: Merge #3568 - Add Android build config to mach/servobuild (from mbrubeck:mach-android); r=metajack
authorMatt Brubeck <mbrubeck@limpet.net>
Fri, 03 Oct 2014 15:45:28 -0600
changeset 381693 50838308eb91832c509d10a1a5686fa4c589a41c
parent 381692 a459d2b9d14cd761d5875f85951fcfa9d9f65381
child 381694 6ec5d910cd6d724379a66d45130c64e459901295
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmetajack
servo: Merge #3568 - Add Android build config to mach/servobuild (from mbrubeck:mach-android); r=metajack This allows setting Android toolchain paths in `.servobuild`, and also adds a `--android` option that sets the correct default target and causes `mach build` to also build the APK. Source-Repo: https://github.com/servo/servo Source-Revision: bf7beb4837246aa53f611492b1ff0986f221a47e
servo/README.md
servo/python/servo/build_commands.py
servo/python/servo/command_base.py
servo/servobuild.example
--- a/servo/README.md
+++ b/servo/README.md
@@ -82,22 +82,31 @@ cd servo
 ./mach run tests/html/about-mozilla.html
 ```
 
 ### Building for Android target
 
 ``` sh
 git clone https://github.com/servo/servo
 cd servo
-ANDROID_TOOLCHAIN=/path/to/toolchain ANDROID_NDK=/path/to/ndk PATH=$PATH:/path/to/toolchain/bin ./mach build --target arm-linux-androideabi
+ANDROID_TOOLCHAIN=/path/to/toolchain ANDROID_NDK=/path/to/ndk PATH=$PATH:/path/to/toolchain/bin ./mach build --android
 cd ports/android
 ANDROID_NDK=/path/to/ndk ANDROID_SDK=/path/to/sdk make
 ANDROID_SDK=/path/to/sdk make install
 ```
 
+Rather than setting the `ANDROID_*` environment variables every time, you can
+also create a `.servobuild` file and then edit it to contain the correct paths
+to the Android SDK/NDK tools:
+
+```
+cp servobuild.example .servobuild
+# edit .servobuild
+```
+
 ## Running
 
 ### Commandline Arguments
 
 - `-p INTERVAL` turns on the profiler and dumps info to the console every
   `INTERVAL` seconds
 - `-s SIZE` sets the tile size for rendering; defaults to 512
 - `-z` disables all graphical output; useful for running JS / layout tests
--- a/servo/python/servo/build_commands.py
+++ b/servo/python/servo/build_commands.py
@@ -22,36 +22,50 @@ class MachCommands(CommandBase):
                      default=None,
                      help='Cross compile for given target platform')
     @CommandArgument('--release', '-r',
                      action='store_true',
                      help='Build in release mode')
     @CommandArgument('--jobs', '-j',
                      default=None,
                      help='Number of jobs to run in parallel')
+    @CommandArgument('--android',
+                     default=None,
+                     action='store_true',
+                     help='Build for Android')
     @CommandArgument('--verbose', '-v',
                      action='store_true',
                      help='Print verbose output')
-    def build(self, target, release=False, jobs=None, verbose=False):
+    def build(self, target=None, release=False, jobs=None, android=None,
+              verbose=False):
         self.ensure_bootstrapped()
 
+        if android is None:
+            android = self.config["build"]["android"]
+
         opts = []
         if release:
             opts += ["--release"]
         if target:
             opts += ["--target", target]
+        elif android:
+            opts += ["--target", "arm-linux-androideabi"]
         if jobs is not None:
             opts += ["-j", jobs]
         if verbose:
             opts += ["-v"]
 
         build_start = time()
         status = subprocess.call(
             ["cargo", "build"] + opts,
             env=self.build_env())
+        if android:
+            status = status or subprocess.call(
+                ["make", "-C", "ports/android"],
+                env=self.build_env())
         elapsed = time() - build_start
 
         print("Build completed in %0.2fs" % elapsed)
         return status
 
     @Command('build-cef',
              description='Build the Chromium Embedding Framework library',
              category='build')
--- a/servo/python/servo/command_base.py
+++ b/servo/python/servo/command_base.py
@@ -68,16 +68,24 @@ class CommandBase(object):
         self.config["tools"].setdefault("cargo-root", "")
         if not self.config["tools"]["system-rust"]:
             self.config["tools"]["rust-root"] = path.join(
                 context.topdir, "rust", *self.rust_snapshot_path().split("/"))
         if not self.config["tools"]["system-cargo"]:
             self.config["tools"]["cargo-root"] = path.join(
                 context.topdir, "cargo")
 
+        self.config.setdefault("build", {})
+        self.config["build"].setdefault("android", False)
+
+        self.config.setdefault("android", {})
+        self.config["android"].setdefault("sdk", "")
+        self.config["android"].setdefault("ndk", "")
+        self.config["android"].setdefault("toolchain", "")
+
     _rust_snapshot_path = None
 
     def rust_snapshot_path(self):
         if self._rust_snapshot_path is None:
             filename = path.join(self.context.topdir, "rust-snapshot-hash")
             snapshot_hash = open(filename).read().strip()
             self._rust_snapshot_path = "%s-%s" % (snapshot_hash, host_triple())
         return self._rust_snapshot_path
@@ -106,16 +114,24 @@ class CommandBase(object):
                                             os.pathsep,
                                             env.get("DYLD_LIBRARY_PATH", ""))
             else:
                 env["LD_LIBRARY_PATH"] = "%s%s%s" % \
                                          (os.pathsep.join(extra_lib),
                                           os.pathsep,
                                           env.get("LD_LIBRARY_PATH", ""))
 
+        # Paths to Android build tools:
+        if self.config["android"]["sdk"]:
+            env["ANDROID_SDK"] = self.config["android"]["sdk"]
+        if self.config["android"]["ndk"]:
+            env["ANDROID_NDK"] = self.config["android"]["ndk"]
+        if self.config["android"]["toolchain"]:
+            env["ANDROID_TOOLCHAIN"] = self.config["android"]["toolchain"]
+
         return env
 
     def ensure_bootstrapped(self):
         if self.context.bootstrapped:
             return
 
         submodules = subprocess.check_output(["git", "submodule", "status"])
         for line in submodules.split('\n'):
--- a/servo/servobuild.example
+++ b/servo/servobuild.example
@@ -4,13 +4,17 @@
 # rust-root is specified, will make sure that rust-root is in the path
 # when building. Similarly for Cargo. This takes care of PATH as well as
 # [DY]LD_LIBRARY_PATH.
 system-rust = false
 rust-root = "/path/to/rust"
 system-cargo = false
 cargo-root = "/path/to/cargo"
 
+[build]
+# Set "android = true" or use `mach build --android` to build the Android app.
+android = false
+
 # Android information
 [android]
 sdk = "/opt/android-sdk"
 ndk = "/opt/android-ndk"
 toolchain = "/opt/android-toolchain"