| OLD | NEW | 
|    1 #!/usr/bin/env python |    1 #!/usr/bin/env python | 
|    2 # Copyright 2014 The Chromium Authors. All rights reserved. |    2 # Copyright 2014 The Chromium Authors. All rights reserved. | 
|    3 # Use of this source code is governed by a BSD-style license that can be |    3 # Use of this source code is governed by a BSD-style license that can be | 
|    4 # found in the LICENSE file. |    4 # found in the LICENSE file. | 
|    5  |    5  | 
|    6 import argparse |    6 import argparse | 
|    7 import imp |    7 import imp | 
|    8 import os |    8 import os | 
|    9 import subprocess |    9 import subprocess | 
|   10 import sys |   10 import sys | 
|   11 import tempfile |   11 import tempfile | 
|   12 import time |   12 import time | 
|   13 import zipfile |   13 import zipfile | 
|   14  |   14  | 
 |   15 if not sys.platform.startswith("linux"): | 
 |   16   print "Only support linux for now" | 
 |   17   sys.exit(1) | 
 |   18  | 
|   15 root_path = os.path.realpath( |   19 root_path = os.path.realpath( | 
|   16     os.path.join( |   20     os.path.join( | 
|   17         os.path.dirname( |   21         os.path.dirname( | 
|   18             os.path.realpath(__file__)), |   22             os.path.realpath(__file__)), | 
|   19         os.pardir, |   23         os.pardir, | 
|   20         os.pardir, |   24         os.pardir, | 
|   21         os.pardir)) |   25         os.pardir)) | 
|   22 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) |   26 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) | 
|   23 version = version.strip() |   27 version = version.strip() | 
|   24  |   28  | 
|   25 if not sys.platform.startswith("linux"): |  | 
|   26   print "Only support linux for now" |  | 
|   27   sys.exit(1) |  | 
|   28  |  | 
|   29 platform = "linux-x64"  # TODO: Parameterize |  | 
|   30 binary_dest = "gs://mojo/network/" + version + "/" + platform + ".zip" |  | 
|   31  |  | 
|   32 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py") |   29 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py") | 
|   33 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path) |   30 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path) | 
|   34  |   31  | 
|   35 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |   32 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 
|   36 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") |   33 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | 
|   37  |   34  | 
|   38  |   35  | 
|   39 def gsutil_cp(source, dest, dry_run): |   36 def gsutil_cp(source, dest, dry_run): | 
|   40   if dry_run: |   37   if dry_run: | 
|   41     print "gsutil cp %s %s" % (source, dest) |   38     print "gsutil cp %s %s" % (source, dest) | 
|   42   else: |   39   else: | 
|   43     subprocess.check_call([gsutil_exe, "cp", source, dest]) |   40     subprocess.check_call([gsutil_exe, "cp", source, dest]) | 
|   44  |   41  | 
|   45  |   42  | 
|   46 def upload_binary(binary_path, dry_run): |   43 def upload_mojoms(dry_run): | 
 |   44   absolute_mojom_directory_path = os.path.join( | 
 |   45       os.path.dirname(os.path.realpath(__file__)), | 
 |   46       "public", | 
 |   47       "interfaces") | 
 |   48   dest = "gs://mojo/network/" + version + "/" + "mojoms.zip" | 
 |   49   with tempfile.NamedTemporaryFile() as mojom_zip_file: | 
 |   50     with zipfile.ZipFile(mojom_zip_file, 'w') as z: | 
 |   51       for root, _, files in os.walk(absolute_mojom_directory_path): | 
 |   52         for filename in files: | 
 |   53           absolute_file_path = os.path.join(root, filename) | 
 |   54           relative_file_path = os.path.relpath(absolute_file_path, root) | 
 |   55           z.write(absolute_file_path, relative_file_path) | 
 |   56     gsutil_cp(mojom_zip_file.name, dest, dry_run) | 
 |   57  | 
 |   58  | 
 |   59 def upload_binary(binary_path, platform, dry_run): | 
|   47   absolute_binary_path = os.path.join(root_path, binary_path) |   60   absolute_binary_path = os.path.join(root_path, binary_path) | 
 |   61   binary_dest = "gs://mojo/network/" + version + "/" + platform + ".zip" | 
|   48   with tempfile.NamedTemporaryFile() as binary_zip_file: |   62   with tempfile.NamedTemporaryFile() as binary_zip_file: | 
|   49     with zipfile.ZipFile(binary_zip_file, 'w') as z: |   63     with zipfile.ZipFile(binary_zip_file, 'w') as z: | 
|   50       with open(absolute_binary_path) as service_binary: |   64       with open(absolute_binary_path) as service_binary: | 
|   51         zipinfo = zipfile.ZipInfo("libnetwork_service.so") |   65         zipinfo = zipfile.ZipInfo("network_service.mojo") | 
|   52         zipinfo.external_attr = 0o777 << 16 |   66         zipinfo.external_attr = 0o777 << 16 | 
|   53         zipinfo.compress_type = zipfile.ZIP_DEFLATED |   67         zipinfo.compress_type = zipfile.ZIP_DEFLATED | 
|   54         zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) |   68         zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | 
|   55         z.writestr(zipinfo, service_binary.read()) |   69         z.writestr(zipinfo, service_binary.read()) | 
|   56   gsutil_cp(binary_zip_file.name, binary_dest, dry_run) |   70     gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | 
|   57  |   71  | 
|   58  |   72  | 
|   59 def main(): |   73 def main(): | 
|   60   parser = argparse.ArgumentParser( |   74   parser = argparse.ArgumentParser( | 
|   61       description="Upload network service binary to Google storage") |   75       description="Upload network service mojoms and binaries to Google " + | 
 |   76                   "storage") | 
|   62   parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") |   77   parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | 
|   63   parser.add_argument( |   78   parser.add_argument( | 
|   64       "binary_path", |   79       "--linux-x64-binary-path", | 
|   65       help="Path to network service binary relative to the repo root, e.g. " + |   80       help="Path to the linux-x64 network service binary relative to the " + | 
|   66       "out/Release/libnetwork_service.so") |   81            "repo root, e.g. out/Release/network_service.mojo") | 
 |   82   parser.add_argument( | 
 |   83       "--android-arm-binary-path", | 
 |   84       help="Path to the android-arm network service binary relative to the " + | 
 |   85            "repo root, e.g. out/android_Release/network_service.mojo") | 
 |   86  | 
|   67   args = parser.parse_args() |   87   args = parser.parse_args() | 
|   68   upload_binary(args.binary_path, args.dry_run) |   88   upload_mojoms(args.dry_run) | 
|   69   print "Uploaded artifacts for %s %s" % (version, "linux-x64") |   89   if args.linux_x64_binary_path: | 
 |   90     upload_binary(args.linux_x64_binary_path, "linux-x64", args.dry_run) | 
 |   91   if args.android_arm_binary_path: | 
 |   92     upload_binary(args.android_arm_binary_path, "android-arm", args.dry_run) | 
 |   93  | 
 |   94   if not args.dry_run: | 
 |   95     print "Uploaded artifacts for version %s" % (version, ) | 
 |   96   else: | 
 |   97     print "No artifacts uploaded (dry run)" | 
|   70   return 0 |   98   return 0 | 
|   71  |   99  | 
|   72 if __name__ == '__main__': |  100 if __name__ == '__main__': | 
|   73   sys.exit(main()) |  101   sys.exit(main()) | 
| OLD | NEW |