| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 29 matching lines...) Expand all Loading... |
| 40 zipfile_base = os.path.splitext(os.path.basename(zip_path))[0] | 40 zipfile_base = os.path.splitext(os.path.basename(zip_path))[0] |
| 41 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) | 41 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) |
| 42 for (root, dirs, files) in os.walk(directory): | 42 for (root, dirs, files) in os.walk(directory): |
| 43 for f in files: | 43 for f in files: |
| 44 full_path = os.path.join(root, f) | 44 full_path = os.path.join(root, f) |
| 45 rel_path = os.path.relpath(full_path, directory) | 45 rel_path = os.path.relpath(full_path, directory) |
| 46 zip.write(full_path, os.path.join(zipfile_base, rel_path)) | 46 zip.write(full_path, os.path.join(zipfile_base, rel_path)) |
| 47 zip.close() | 47 zip.close() |
| 48 | 48 |
| 49 | 49 |
| 50 def buildWebApp(linux_strip, mimetype, destination, zip_path, plugin, files, | 50 def buildWebApp(buildtype, mimetype, destination, zip_path, plugin, files, |
| 51 locales): | 51 locales): |
| 52 """Does the main work of building the webapp directory and zipfile. | 52 """Does the main work of building the webapp directory and zipfile. |
| 53 | 53 |
| 54 Args: | 54 Args: |
| 55 linux_strip: should we strip the build on Linux (0 or !0). | 55 buildtype: the type of build ("Official" or "Dev") |
| 56 mimetype: A string with mimetype of plugin. | 56 mimetype: A string with mimetype of plugin. |
| 57 destination: A string with path to directory where the webapp will be | 57 destination: A string with path to directory where the webapp will be |
| 58 written. | 58 written. |
| 59 zipfile: A string with path to the zipfile to create containing the | 59 zipfile: A string with path to the zipfile to create containing the |
| 60 contents of |destination|. | 60 contents of |destination|. |
| 61 plugin: A string with path to the binary plugin for this webapp. | 61 plugin: A string with path to the binary plugin for this webapp. |
| 62 files: An array of strings listing the paths for resources to include | 62 files: An array of strings listing the paths for resources to include |
| 63 in this webapp. | 63 in this webapp. |
| 64 locales: An array of strings listing locales, which are copied, along | 64 locales: An array of strings listing locales, which are copied, along |
| 65 with their directory structure from the _locales directory down. | 65 with their directory structure from the _locales directory down. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 # Copy the plugin. | 145 # Copy the plugin. |
| 146 pluginName = os.path.basename(plugin) | 146 pluginName = os.path.basename(plugin) |
| 147 newPluginPath = os.path.join(destination, pluginName) | 147 newPluginPath = os.path.join(destination, pluginName) |
| 148 if os.path.isdir(plugin): | 148 if os.path.isdir(plugin): |
| 149 # On Mac we have a directory. | 149 # On Mac we have a directory. |
| 150 shutil.copytree(plugin, newPluginPath) | 150 shutil.copytree(plugin, newPluginPath) |
| 151 else: | 151 else: |
| 152 shutil.copy2(plugin, newPluginPath) | 152 shutil.copy2(plugin, newPluginPath) |
| 153 | 153 |
| 154 # Strip the linux build. | 154 # Strip the linux build. |
| 155 if ((platform.system() == 'Linux') and (linux_strip != '0')): | 155 if ((platform.system() == 'Linux') and (buildtype == 'Official')): |
| 156 subprocess.call(["strip", newPluginPath]) | 156 subprocess.call(["strip", newPluginPath]) |
| 157 | 157 |
| 158 # Add unique build numbers to manifest version. | 158 # Add unique build numbers to manifest version. |
| 159 # For now, this is based on the system clock (seconds since 1/1/1970), since | 159 # For now, this is based on the system clock (seconds since 1/1/1970), since |
| 160 # a previous attempt (based on build/utils/lastchange.py) was failing on Mac. | 160 # a previous attempt (based on build/utils/lastchange.py) was failing on Mac. |
| 161 # TODO(lambroslambrou): Use the SVN revision number or an incrementing build | 161 # TODO(lambroslambrou): Use the SVN revision number or an incrementing build |
| 162 # number (http://crbug.com/90110). | 162 # number (http://crbug.com/90110). |
| 163 timestamp = int(time.time()) | 163 timestamp = int(time.time()) |
| 164 # Version string must be 1-4 numbers separated by dots, with each number | 164 # Version string must be 1-4 numbers separated by dots, with each number |
| 165 # between 0 and 0xffff. | 165 # between 0 and 0xffff. |
| 166 version1 = timestamp / 0x10000 | 166 version1 = timestamp / 0x10000 |
| 167 version2 = timestamp % 0x10000 | 167 version2 = timestamp % 0x10000 |
| 168 findAndReplace(os.path.join(destination, 'manifest.json'), | 168 findAndReplace(os.path.join(destination, 'manifest.json'), |
| 169 'UNIQUE_VERSION', | 169 'UNIQUE_VERSION', |
| 170 '%d.%d' % (version1, version2)) | 170 '%d.%d' % (version1, version2)) |
| 171 | 171 |
| 172 # Now massage files with our mimetype. | 172 # Now massage files with our mimetype. |
| 173 findAndReplace(os.path.join(destination, 'plugin_settings.js'), | 173 findAndReplace(os.path.join(destination, 'plugin_settings.js'), |
| 174 'HOST_PLUGIN_MIMETYPE', | 174 'HOST_PLUGIN_MIMETYPE', |
| 175 mimetype) | 175 mimetype) |
| 176 | 176 |
| 177 # Make the zipfile. | 177 # Make the zipfile. |
| 178 createZip(zip_path, destination) | 178 createZip(zip_path, destination) |
| 179 | 179 |
| 180 | 180 |
| 181 def main(): | 181 def main(): |
| 182 if len(sys.argv) < 6: | 182 if len(sys.argv) < 6: |
| 183 print ('Usage: build-webapp.py ' | 183 print ('Usage: build-webapp.py ' |
| 184 '<linux-strip> <mime-type> <dst> <zip-path> <plugin> ' | 184 '<build-type> <mime-type> <dst> <zip-path> <plugin> ' |
| 185 '<other files...> --locales <locales...>') | 185 '<other files...> --locales <locales...>') |
| 186 sys.exit(1) | 186 sys.exit(1) |
| 187 | 187 |
| 188 reading_locales = False | 188 reading_locales = False |
| 189 files = [] | 189 files = [] |
| 190 locales = [] | 190 locales = [] |
| 191 for arg in sys.argv[6:]: | 191 for arg in sys.argv[6:]: |
| 192 if arg == "--locales": | 192 if arg == "--locales": |
| 193 reading_locales = True; | 193 reading_locales = True; |
| 194 elif reading_locales: | 194 elif reading_locales: |
| 195 locales.append(arg) | 195 locales.append(arg) |
| 196 else: | 196 else: |
| 197 files.append(arg) | 197 files.append(arg) |
| 198 | 198 |
| 199 buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], | 199 buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], |
| 200 files, locales) | 200 files, locales) |
| 201 | 201 |
| 202 | 202 |
| 203 if __name__ == '__main__': | 203 if __name__ == '__main__': |
| 204 main() | 204 main() |
| OLD | NEW |