CIPD package for Bazel.

Bug: skia:11111
Change-Id: I2a79aea9d679efe22138cf8c1f00b9c4449e805a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371498
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
Auto-Submit: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/infra/bots/assets/bazel/VERSION b/infra/bots/assets/bazel/VERSION
new file mode 100644
index 0000000..d8263ee
--- /dev/null
+++ b/infra/bots/assets/bazel/VERSION
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/infra/bots/assets/bazel/common.py b/infra/bots/assets/bazel/common.py
new file mode 100755
index 0000000..caa0ad8
--- /dev/null
+++ b/infra/bots/assets/bazel/common.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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/bazel/create.py b/infra/bots/assets/bazel/create.py
new file mode 100755
index 0000000..49bd607
--- /dev/null
+++ b/infra/bots/assets/bazel/create.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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 common # fixes python import path
+import argparse
+import subprocess
+import sys
+import utils
+
+
+URL = 'https://github.com/bazelbuild/bazel/releases/download/4.0.0/bazel-4.0.0-installer-linux-x86_64.sh'
+INSTALLER_SCRIPT = URL.split('/')[-1]
+
+
+def create_asset(target_dir):
+  """Create the asset."""
+  with utils.tmp_dir():
+    subprocess.call(['wget', URL])
+    subprocess.call(['sh', INSTALLER_SCRIPT, '--prefix=' + target_dir])
+
+
+def main():
+  if 'linux' not in sys.platform:
+    print >> sys.stderr, 'This script only runs on Linux.'
+    sys.exit(1)
+  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/bazel/create_and_upload.py b/infra/bots/assets/bazel/create_and_upload.py
new file mode 100755
index 0000000..de56a80
--- /dev/null
+++ b/infra/bots/assets/bazel/create_and_upload.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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/bazel/download.py b/infra/bots/assets/bazel/download.py
new file mode 100755
index 0000000..ca999e0
--- /dev/null
+++ b/infra/bots/assets/bazel/download.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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/bazel/upload.py b/infra/bots/assets/bazel/upload.py
new file mode 100755
index 0000000..bdfbda7
--- /dev/null
+++ b/infra/bots/assets/bazel/upload.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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')