Add a Windows Android NDK asset.
authorMike Klein <mtklein@chromium.org>
Tue, 1 Nov 2016 18:03:04 +0000 (14:03 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 2 Nov 2016 13:16:08 +0000 (13:16 +0000)
We can build for Android from Windows now.  I intend to add a bot to keep it that way, just like Build-Mac-Clang-arm64-Debug-GN_Android does for Mac.  The Windows Android builder will need this NDK.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4280

DOCS_PREVIEW= https://skia.org/?cl=4280

Change-Id: Ifaeeb9b81822a410bdf79b39c7e66d0765f78e0b
Reviewed-on: https://skia-review.googlesource.com/4280
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>

infra/bots/assets/android_ndk_windows/VERSION [new file with mode: 0644]
infra/bots/assets/android_ndk_windows/common.py [new file with mode: 0755]
infra/bots/assets/android_ndk_windows/create.py [new file with mode: 0755]
infra/bots/assets/android_ndk_windows/create_and_upload.py [new file with mode: 0755]
infra/bots/assets/android_ndk_windows/download.py [new file with mode: 0755]
infra/bots/assets/android_ndk_windows/upload.py [new file with mode: 0755]
site/user/quick/gn.md

diff --git a/infra/bots/assets/android_ndk_windows/VERSION b/infra/bots/assets/android_ndk_windows/VERSION
new file mode 100644 (file)
index 0000000..c227083
--- /dev/null
@@ -0,0 +1 @@
+0
\ No newline at end of file
diff --git a/infra/bots/assets/android_ndk_windows/common.py b/infra/bots/assets/android_ndk_windows/common.py
new file mode 100755 (executable)
index 0000000..4920c9b
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Common vars used by scripts in this directory."""
+
+
+import os
+import sys
+
+FILE_DIR = os.path.dirname(os.path.abspath(__file__))
+INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
+
+sys.path.insert(0, INFRA_BOTS_DIR)
+from assets import assets
+
+ASSET_NAME = os.path.basename(FILE_DIR)
+
+
+def run(cmd):
+  """Run a command, eg. "upload" or "download". """
+  assets.main([cmd, ASSET_NAME] + sys.argv[1:])
diff --git a/infra/bots/assets/android_ndk_windows/create.py b/infra/bots/assets/android_ndk_windows/create.py
new file mode 100755 (executable)
index 0000000..e79b2ed
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset."""
+
+
+import argparse
+import glob
+import os.path
+import shutil
+import subprocess
+
+NDK_VER = "android-ndk-r13"
+NDK_URL = \
+    "https://dl.google.com/android/repository/%s-windows-x86_64.zip" % NDK_VER
+
+def create_asset(target_dir):
+  """Create the asset."""
+  subprocess.check_call(["curl", NDK_URL, "-o", "ndk.zip"])
+  subprocess.check_call(["unzip", "ndk.zip", "-d", target_dir])
+  for f in glob.glob(os.path.join(target_dir, NDK_VER, "*")):
+    shutil.move(f, target_dir)
+  subprocess.check_call(["rm", "ndk.zip"])
+
+
+def main():
+  parser = argparse.ArgumentParser()
+  parser.add_argument('--target_dir', '-t', required=True)
+  args = parser.parse_args()
+  create_asset(args.target_dir)
+
+
+if __name__ == '__main__':
+  main()
diff --git a/infra/bots/assets/android_ndk_windows/create_and_upload.py b/infra/bots/assets/android_ndk_windows/create_and_upload.py
new file mode 100755 (executable)
index 0000000..1356447
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset and upload it."""
+
+
+import argparse
+import common
+import os
+import subprocess
+import sys
+import utils
+
+
+def main():
+  parser = argparse.ArgumentParser()
+  parser.add_argument('--gsutil')
+  args = parser.parse_args()
+
+  with utils.tmp_dir():
+    cwd = os.getcwd()
+    create_script = os.path.join(common.FILE_DIR, 'create.py')
+    upload_script = os.path.join(common.FILE_DIR, 'upload.py')
+
+    try:
+      subprocess.check_call(['python', create_script, '-t', cwd])
+      cmd = ['python', upload_script, '-t', cwd]
+      if args.gsutil:
+        cmd.extend(['--gsutil', args.gsutil])
+      subprocess.check_call(cmd)
+    except subprocess.CalledProcessError:
+      # Trap exceptions to avoid printing two stacktraces.
+      sys.exit(1)
+
+
+if __name__ == '__main__':
+  main()
diff --git a/infra/bots/assets/android_ndk_windows/download.py b/infra/bots/assets/android_ndk_windows/download.py
new file mode 100755 (executable)
index 0000000..96cc87d
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Download the current version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+  common.run('download')
diff --git a/infra/bots/assets/android_ndk_windows/upload.py b/infra/bots/assets/android_ndk_windows/upload.py
new file mode 100755 (executable)
index 0000000..ba7fc8b
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Upload a new version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+  common.run('upload')
index b948332..e429754 100644 (file)
@@ -66,6 +66,7 @@ can use one of these commands to fetch the NDK our bots use:
 
     python infra/bots/assets/android_ndk_linux/download.py  -t /tmp/ndk
     python infra/bots/assets/android_ndk_darwin/download.py -t /tmp/ndk
+    python infra/bots/assets/android_ndk_windows/download.py -t C:/ndk
 
 When generating your GN build files, pass the path to your `ndk` and your
 desired `target_cpu`: