Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: mojo/tools/upload_binaries.py

Issue 971083002: Create an apptesting framework for dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update upload_binaries.py to add the apptest.dartzip artifact. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/tools/mopy/test_util.py ('k') | services/dart/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 glob 7 import glob
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 import mopy.gn as gn 15 import mopy.gn as gn
16 from mopy.config import Config 16 from mopy.config import Config
17 from mopy.paths import Paths 17 from mopy.paths import Paths
18 from mopy.version import Version 18 from mopy.version import Version
19 19
20 BLACKLISTED_APPS = [ 20 BLACKLISTED_APPS = [
21 # The network service apps are not produced out of the Mojo repo, but may 21 # The network service apps are not produced out of the Mojo repo, but may
22 # be present in the build dir. 22 # be present in the build dir.
23 "network_service.mojo", 23 "network_service.mojo",
24 "network_service_apptests.mojo", 24 "network_service_apptests.mojo",
25 ] 25 ]
26 26
27 WHILTELISTED_FILES = [
28 # These are files other than *.mojo files which are part of our binary
29 # artifact scheme.
30 "obj/mojo/dart/apptest/apptest.dartzip",
31 ]
32
33
27 def target(config): 34 def target(config):
28 return config.target_os + "-" + config.target_cpu 35 return config.target_os + "-" + config.target_cpu
29 36
37
30 def find_apps_to_upload(build_dir): 38 def find_apps_to_upload(build_dir):
31 apps = [] 39 apps = []
32 for path in glob.glob(build_dir + "/*"): 40 for path in glob.glob(build_dir + "/*"):
33 if not os.path.isfile(path): 41 if not os.path.isfile(path):
34 continue 42 continue
35 _, ext = os.path.splitext(path) 43 _, ext = os.path.splitext(path)
36 if ext != '.mojo': 44 if ext != '.mojo':
37 continue 45 continue
38 if os.path.basename(path) in BLACKLISTED_APPS: 46 if os.path.basename(path) in BLACKLISTED_APPS:
39 continue 47 continue
40 apps.append(path) 48 apps.append(path)
41 return apps 49 return apps
42 50
51
52 def find_whitelisted_files(build_dir):
53 existing_files = []
54 for path in WHILTELISTED_FILES:
55 joined_path = os.path.join(build_dir, path)
56 if os.path.isfile(joined_path):
57 existing_files.append(joined_path)
58 return existing_files
59
60
43 def upload(config, source, dest, dry_run): 61 def upload(config, source, dest, dry_run):
44 paths = Paths(config) 62 paths = Paths(config)
45 sys.path.insert(0, os.path.join(paths.src_root, "tools")) 63 sys.path.insert(0, os.path.join(paths.src_root, "tools"))
46 # pylint: disable=F0401 64 # pylint: disable=F0401
47 import find_depot_tools 65 import find_depot_tools
48 66
49 depot_tools_path = find_depot_tools.add_depot_tools_to_path() 67 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
50 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") 68 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
51 69
52 if dry_run: 70 if dry_run:
53 print str([gsutil_exe, "cp", source, dest]) 71 print str([gsutil_exe, "cp", source, dest])
54 else: 72 else:
55 subprocess.check_call([gsutil_exe, "cp", source, dest]) 73 subprocess.check_call([gsutil_exe, "cp", source, dest])
56 74
75
57 def upload_shell(config, dry_run, verbose): 76 def upload_shell(config, dry_run, verbose):
58 paths = Paths(config) 77 paths = Paths(config)
59 zipfile_name = target(config) 78 zipfile_name = target(config)
60 version = Version().version 79 version = Version().version
61 80
62 # Upload the binary. 81 # Upload the binary.
63 # TODO(blundell): Change this to be in the same structure as the LATEST files, 82 # TODO(blundell): Change this to be in the same structure as the LATEST files,
64 # e.g., gs://mojo/shell/linux-x64/<version>/shell.zip. 83 # e.g., gs://mojo/shell/linux-x64/<version>/shell.zip.
65 dest = "gs://mojo/shell/" + version + "/" + zipfile_name + ".zip" 84 dest = "gs://mojo/shell/" + version + "/" + zipfile_name + ".zip"
66 with tempfile.NamedTemporaryFile() as zip_file: 85 with tempfile.NamedTemporaryFile() as zip_file:
(...skipping 11 matching lines...) Expand all
78 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path)) 97 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path))
79 if verbose: 98 if verbose:
80 print "zipping %s" % shell_path 99 print "zipping %s" % shell_path
81 z.writestr(zipinfo, shell_binary.read()) 100 z.writestr(zipinfo, shell_binary.read())
82 upload(config, zip_file.name, dest, dry_run) 101 upload(config, zip_file.name, dest, dry_run)
83 102
84 # Update the LATEST file to contain the version of the new binary. 103 # Update the LATEST file to contain the version of the new binary.
85 latest_file = "gs://mojo/shell/%s/LATEST" % target(config) 104 latest_file = "gs://mojo/shell/%s/LATEST" % target(config)
86 write_file_to_gs(version, latest_file, config, dry_run) 105 write_file_to_gs(version, latest_file, config, dry_run)
87 106
107
88 def upload_app(app_binary_path, config, dry_run): 108 def upload_app(app_binary_path, config, dry_run):
89 app_binary_name = os.path.basename(app_binary_path) 109 app_binary_name = os.path.basename(app_binary_path)
90 app_name, _ = os.path.splitext(app_binary_name) 110 app_name, _ = os.path.splitext(app_binary_name)
91 version = Version().version 111 version = Version().version
92 app_location_in_gs = ("mojo/services/" + target(config) + "/" + version + 112 app_location_in_gs = ("mojo/services/" + target(config) + "/" + version +
93 "/" + app_binary_name) 113 "/" + app_binary_name)
94 gsutil_app_location = "gs://" + app_location_in_gs 114 gsutil_app_location = "gs://" + app_location_in_gs
95 https_app_location = "https://storage.googleapis.com/" + app_location_in_gs 115 https_app_location = "https://storage.googleapis.com/" + app_location_in_gs
96 116
97 # Upload the new binary. 117 # Upload the new binary.
98 upload(config, app_binary_path, gsutil_app_location, dry_run) 118 upload(config, app_binary_path, gsutil_app_location, dry_run)
99 119
100 # Update the app's location file to point to the new binary. 120 # Update the app's location file to point to the new binary.
101 app_location_file = ("gs://mojo/services/" + target(config) + "/" + 121 app_location_file = ("gs://mojo/services/" + target(config) + "/" +
102 app_name + "_location") 122 app_name + "_location")
103 write_file_to_gs(https_app_location, app_location_file, config, dry_run) 123 write_file_to_gs(https_app_location, app_location_file, config, dry_run)
104 124
125
126 def upload_file(file_path, config, dry_run):
127 file_binary_name = os.path.basename(file_path)
128 version = Version().version
129 file_location_in_gs = ("mojo/services/" + target(config) + "/" + version +
130 "/" + file_binary_name)
131 gsutil_file_location = "gs://" + file_location_in_gs
tonyg 2015/03/05 00:03:23 Would be nice to factor out a helper for building
132
133 # Upload the new binary.
134 upload(config, file_path, gsutil_file_location, dry_run)
135
136
105 def write_file_to_gs(file_contents, dest, config, dry_run): 137 def write_file_to_gs(file_contents, dest, config, dry_run):
106 with tempfile.NamedTemporaryFile() as temp_version_file: 138 with tempfile.NamedTemporaryFile() as temp_version_file:
107 temp_version_file.write(file_contents) 139 temp_version_file.write(file_contents)
108 temp_version_file.flush() 140 temp_version_file.flush()
109 upload(config, temp_version_file.name, dest, dry_run) 141 upload(config, temp_version_file.name, dest, dry_run)
110 142
143
111 def main(): 144 def main():
112 parser = argparse.ArgumentParser(description="Upload binaries for apps and " 145 parser = argparse.ArgumentParser(description="Upload binaries for apps and "
113 "the Mojo shell to google storage (by default on Linux, but this can be " 146 "the Mojo shell to google storage (by default on Linux, but this can be "
114 "changed via options).") 147 "changed via options).")
115 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ 148 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+
116 "upload", action="store_true") 149 "upload", action="store_true")
117 parser.add_argument("-v", "--verbose", help="Verbose mode", 150 parser.add_argument("-v", "--verbose", help="Verbose mode",
118 action="store_true") 151 action="store_true")
119 parser.add_argument("--android", 152 parser.add_argument("--android",
120 action="store_true", 153 action="store_true",
121 help="Upload the shell and apps for Android") 154 help="Upload the shell and apps for Android")
122 args = parser.parse_args() 155 args = parser.parse_args()
123 156
124 target_os = Config.OS_LINUX 157 target_os = Config.OS_LINUX
125 if args.android: 158 if args.android:
126 target_os = Config.OS_ANDROID 159 target_os = Config.OS_ANDROID
127 config = Config(target_os=target_os, is_debug=False) 160 config = Config(target_os=target_os, is_debug=False)
128 upload_shell(config, args.dry_run, args.verbose) 161 upload_shell(config, args.dry_run, args.verbose)
129 162
130 apps_to_upload = find_apps_to_upload( 163 build_directory = gn.BuildDirectoryForConfig(config, Paths(config).src_root)
131 gn.BuildDirectoryForConfig(config, Paths(config).src_root)) 164 apps_to_upload = find_apps_to_upload(build_directory)
132 for app in apps_to_upload: 165 for app in apps_to_upload:
133 upload_app(app, config, args.dry_run) 166 upload_app(app, config, args.dry_run)
134 167
168 files_to_upload = find_whitelisted_files(build_directory)
169 for file_to_upload in files_to_upload:
170 upload_file(file_to_upload, config, args.dry_run)
171
135 return 0 172 return 0
136 173
137 if __name__ == "__main__": 174 if __name__ == "__main__":
138 sys.exit(main()) 175 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/tools/mopy/test_util.py ('k') | services/dart/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698