From 5580c6913500ccd80fb03a72e6992ee0d5b42d88 Mon Sep 17 00:00:00 2001 From: mtklein Date: Fri, 26 Aug 2016 10:52:19 -0700 Subject: [PATCH] add an asset for the Linux Android NDK. I have run create_and_upload.py... cipd is uploading now. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2275093003 Review-Url: https://codereview.chromium.org/2275093003 --- infra/bots/assets/android_ndk_linux/VERSION | 1 + infra/bots/assets/android_ndk_linux/common.py | 26 ++++++++++++ infra/bots/assets/android_ndk_linux/create.py | 39 +++++++++++++++++ .../android_ndk_linux/create_and_upload.py | 42 +++++++++++++++++++ .../bots/assets/android_ndk_linux/download.py | 16 +++++++ infra/bots/assets/android_ndk_linux/upload.py | 16 +++++++ infra/bots/zip_utils.py | 6 +-- 7 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 infra/bots/assets/android_ndk_linux/VERSION create mode 100755 infra/bots/assets/android_ndk_linux/common.py create mode 100755 infra/bots/assets/android_ndk_linux/create.py create mode 100755 infra/bots/assets/android_ndk_linux/create_and_upload.py create mode 100755 infra/bots/assets/android_ndk_linux/download.py create mode 100755 infra/bots/assets/android_ndk_linux/upload.py diff --git a/infra/bots/assets/android_ndk_linux/VERSION b/infra/bots/assets/android_ndk_linux/VERSION new file mode 100644 index 0000000000..bf0d87ab1b --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/VERSION @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git a/infra/bots/assets/android_ndk_linux/common.py b/infra/bots/assets/android_ndk_linux/common.py new file mode 100755 index 0000000000..4920c9b4fb --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/common.py @@ -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_linux/create.py b/infra/bots/assets/android_ndk_linux/create.py new file mode 100755 index 0000000000..7bde83ad0f --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/create.py @@ -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-r12b" +NDK_URL = \ + "https://dl.google.com/android/repository/%s-linux-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_linux/create_and_upload.py b/infra/bots/assets/android_ndk_linux/create_and_upload.py new file mode 100755 index 0000000000..1356447477 --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/create_and_upload.py @@ -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_linux/download.py b/infra/bots/assets/android_ndk_linux/download.py new file mode 100755 index 0000000000..96cc87d43f --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/download.py @@ -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_linux/upload.py b/infra/bots/assets/android_ndk_linux/upload.py new file mode 100755 index 0000000000..ba7fc8b6a1 --- /dev/null +++ b/infra/bots/assets/android_ndk_linux/upload.py @@ -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') diff --git a/infra/bots/zip_utils.py b/infra/bots/zip_utils.py index 7f269b9e9b..ed1979d804 100644 --- a/infra/bots/zip_utils.py +++ b/infra/bots/zip_utils.py @@ -27,7 +27,7 @@ def zip(target_dir, zip_file, blacklist=None): # pylint: disable=W0622 if not os.path.isdir(target_dir): raise IOError('%s does not exist!' % target_dir) blacklist = blacklist or [] - with zipfile.ZipFile(zip_file, 'w') as z: + with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED, True) as z: for r, d, f in os.walk(target_dir, topdown=True): d[:] = filtered(d, blacklist) for filename in filtered(f, blacklist): @@ -36,7 +36,7 @@ def zip(target_dir, zip_file, blacklist=None): # pylint: disable=W0622 zi.filename = os.path.relpath(filepath, target_dir) perms = os.stat(filepath).st_mode zi.external_attr = perms << 16L - zi.compress_type = zipfile.ZIP_STORED + zi.compress_type = zipfile.ZIP_DEFLATED with open(filepath, 'rb') as f: content = f.read() z.writestr(zi, content) @@ -49,7 +49,7 @@ def unzip(zip_file, target_dir): """Unzip the given zip file into the target dir.""" if not os.path.isdir(target_dir): os.makedirs(target_dir) - with zipfile.ZipFile(zip_file, 'r') as z: + with zipfile.ZipFile(zip_file, 'r', zipfile.ZIP_DEFLATED, True) as z: for zi in z.infolist(): dst_path = os.path.join(target_dir, zi.filename) if zi.filename.endswith('/'):