OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Creates a directory with with the unpacked contents of the remoting webapp. | 6 """Creates a directory with with the unpacked contents of the remoting webapp. |
7 | 7 |
8 The directory will contain a copy-of or a link-to to all remoting webapp | 8 The directory will contain a copy-of or a link-to to all remoting webapp |
9 resources. This includes HTML/JS and any plugin binaries. The script also | 9 resources. This includes HTML/JS and any plugin binaries. The script also |
10 massages resulting files appropriately with host plugin data. Finally, | 10 massages resulting files appropriately with host plugin data. Finally, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) | 49 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) |
50 for (root, dirs, files) in os.walk(directory): | 50 for (root, dirs, files) in os.walk(directory): |
51 for f in files: | 51 for f in files: |
52 full_path = os.path.join(root, f) | 52 full_path = os.path.join(root, f) |
53 rel_path = os.path.relpath(full_path, directory) | 53 rel_path = os.path.relpath(full_path, directory) |
54 zip.write(full_path, os.path.join(zipfile_base, rel_path)) | 54 zip.write(full_path, os.path.join(zipfile_base, rel_path)) |
55 zip.close() | 55 zip.close() |
56 | 56 |
57 | 57 |
58 def buildWebApp(buildtype, version, mimetype, destination, zip_path, plugin, | 58 def buildWebApp(buildtype, version, mimetype, destination, zip_path, plugin, |
59 files, locales): | 59 files, locales, patches): |
60 """Does the main work of building the webapp directory and zipfile. | 60 """Does the main work of building the webapp directory and zipfile. |
61 | 61 |
62 Args: | 62 Args: |
63 buildtype: the type of build ("Official" or "Dev") | 63 buildtype: the type of build ("Official" or "Dev") |
64 mimetype: A string with mimetype of plugin. | 64 mimetype: A string with mimetype of plugin. |
65 destination: A string with path to directory where the webapp will be | 65 destination: A string with path to directory where the webapp will be |
66 written. | 66 written. |
67 zipfile: A string with path to the zipfile to create containing the | 67 zipfile: A string with path to the zipfile to create containing the |
68 contents of |destination|. | 68 contents of |destination|. |
69 plugin: A string with path to the binary plugin for this webapp. | 69 plugin: A string with path to the binary plugin for this webapp. |
70 files: An array of strings listing the paths for resources to include | 70 files: An array of strings listing the paths for resources to include |
71 in this webapp. | 71 in this webapp. |
72 locales: An array of strings listing locales, which are copied, along | 72 locales: An array of strings listing locales, which are copied, along |
73 with their directory structure from the _locales directory down. | 73 with their directory structure from the _locales directory down. |
| 74 patches: An array of strings listing patch files to be applied to the |
| 75 webapp directory. Paths in the patch file should be relative to |
| 76 the remoting/webapp directory, for example a/main.html. Since |
| 77 'git diff -p' works relative to the src/ directory, patches |
| 78 obtained this way will need to be edited. |
74 """ | 79 """ |
75 # Ensure a fresh directory. | 80 # Ensure a fresh directory. |
76 try: | 81 try: |
77 shutil.rmtree(destination) | 82 shutil.rmtree(destination) |
78 except OSError: | 83 except OSError: |
79 if os.path.exists(destination): | 84 if os.path.exists(destination): |
80 raise | 85 raise |
81 else: | 86 else: |
82 pass | 87 pass |
83 os.mkdir(destination, 0775) | 88 os.mkdir(destination, 0775) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if os.path.isdir(plugin): | 157 if os.path.isdir(plugin): |
153 # On Mac we have a directory. | 158 # On Mac we have a directory. |
154 shutil.copytree(plugin, newPluginPath) | 159 shutil.copytree(plugin, newPluginPath) |
155 else: | 160 else: |
156 shutil.copy2(plugin, newPluginPath) | 161 shutil.copy2(plugin, newPluginPath) |
157 | 162 |
158 # Strip the linux build. | 163 # Strip the linux build. |
159 if ((platform.system() == 'Linux') and (buildtype == 'Official')): | 164 if ((platform.system() == 'Linux') and (buildtype == 'Official')): |
160 subprocess.call(["strip", newPluginPath]) | 165 subprocess.call(["strip", newPluginPath]) |
161 | 166 |
| 167 # Patch the files, if necessary. Do this before updating any placeholders |
| 168 # in case any of the diff contexts refer to the placeholders. |
| 169 for patch in patches: |
| 170 patchfile = os.path.join(os.getcwd(), patch) |
| 171 if subprocess.call(['patch', '-d', destination, '-i', patchfile, |
| 172 '-p1']) != 0: |
| 173 print 'Patch ' + patch + ' failed to apply.' |
| 174 return 1 |
| 175 |
162 # Set the version number in the manifest version. | 176 # Set the version number in the manifest version. |
163 findAndReplace(os.path.join(destination, 'manifest.json'), | 177 findAndReplace(os.path.join(destination, 'manifest.json'), |
164 'FULL_APP_VERSION', | 178 'FULL_APP_VERSION', |
165 version) | 179 version) |
166 | 180 |
167 # Set the correct mimetype. | 181 # Set the correct mimetype. |
168 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 182 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
169 'HOST_PLUGIN_MIMETYPE', | 183 'HOST_PLUGIN_MIMETYPE', |
170 mimetype) | 184 mimetype) |
171 | 185 |
(...skipping 23 matching lines...) Expand all Loading... |
195 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 209 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
196 "'API_CLIENT_ID'", | 210 "'API_CLIENT_ID'", |
197 "'" + apiClientId + "'") | 211 "'" + apiClientId + "'") |
198 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 212 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
199 "'API_CLIENT_SECRET'", | 213 "'API_CLIENT_SECRET'", |
200 "'" + apiClientSecret + "'") | 214 "'" + apiClientSecret + "'") |
201 | 215 |
202 # Make the zipfile. | 216 # Make the zipfile. |
203 createZip(zip_path, destination) | 217 createZip(zip_path, destination) |
204 | 218 |
| 219 return 0 |
| 220 |
205 | 221 |
206 def main(): | 222 def main(): |
207 if len(sys.argv) < 7: | 223 if len(sys.argv) < 7: |
208 print ('Usage: build-webapp.py ' | 224 print ('Usage: build-webapp.py ' |
209 '<build-type> <version> <mime-type> <dst> <zip-path> <plugin> ' | 225 '<build-type> <version> <mime-type> <dst> <zip-path> <plugin> ' |
210 '<other files...> --locales <locales...>') | 226 '<other files...> [--patches <patches...>] ' |
| 227 '[--locales <locales...>]') |
211 return 1 | 228 return 1 |
212 | 229 |
213 reading_locales = False | 230 arg_type = '' |
214 files = [] | 231 files = [] |
215 locales = [] | 232 locales = [] |
| 233 patches = [] |
216 for arg in sys.argv[7:]: | 234 for arg in sys.argv[7:]: |
217 if arg == "--locales": | 235 if arg == '--locales' or arg == '--patches': |
218 reading_locales = True; | 236 arg_type = arg |
219 elif reading_locales: | 237 elif arg_type == '--locales': |
220 locales.append(arg) | 238 locales.append(arg) |
| 239 elif arg_type == '--patches': |
| 240 patches.append(arg) |
221 else: | 241 else: |
222 files.append(arg) | 242 files.append(arg) |
223 | 243 |
224 buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], | 244 return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], |
225 sys.argv[6], files, locales) | 245 sys.argv[5], sys.argv[6], files, locales, patches) |
226 return 0 | |
227 | 246 |
228 | 247 |
229 if __name__ == '__main__': | 248 if __name__ == '__main__': |
230 sys.exit(main()) | 249 sys.exit(main()) |
OLD | NEW |