| 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 """Build script to generate a new sdk_tools bundle. | 6 """Build script to generate a new sdk_tools bundle. |
| 7 | 7 |
| 8 This script packages the files necessary to generate the SDK updater -- the | 8 This script packages the files necessary to generate the SDK updater -- the |
| 9 tool users run to download new bundles, update existing bundles, etc. | 9 tool users run to download new bundles, update existing bundles, etc. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import buildbot_common | 12 import buildbot_common |
| 13 import build_utils | 13 import build_utils |
| 14 import glob |
| 14 import optparse | 15 import optparse |
| 15 import os | 16 import os |
| 16 import sys | 17 import sys |
| 17 | 18 |
| 18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 19 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 19 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) | 20 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) |
| 20 SDK_DIR = os.path.dirname(SDK_SRC_DIR) | 21 SDK_DIR = os.path.dirname(SDK_SRC_DIR) |
| 21 SRC_DIR = os.path.dirname(SDK_DIR) | 22 SRC_DIR = os.path.dirname(SDK_DIR) |
| 22 NACL_DIR = os.path.join(SRC_DIR, 'native_client') | 23 NACL_DIR = os.path.join(SRC_DIR, 'native_client') |
| 23 CYGTAR = os.path.join(NACL_DIR, 'build', 'cygtar.py') | 24 CYGTAR = os.path.join(NACL_DIR, 'build', 'cygtar.py') |
| 24 | 25 |
| 25 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) | 26 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) |
| 26 | 27 |
| 27 import oshelpers | 28 import oshelpers |
| 28 | 29 |
| 29 | 30 |
| 30 UPDATER_FILES = [ | 31 UPDATER_FILES = [ |
| 31 # launch scripts | 32 # launch scripts |
| 32 ('build_tools/naclsdk', 'nacl_sdk/naclsdk'), | 33 ('build_tools/naclsdk', 'nacl_sdk/naclsdk'), |
| 33 ('build_tools/naclsdk.bat', 'nacl_sdk/naclsdk.bat'), | 34 ('build_tools/naclsdk.bat', 'nacl_sdk/naclsdk.bat'), |
| 34 | 35 |
| 35 # base manifest | 36 # base manifest |
| 36 ('build_tools/json/naclsdk_manifest0.json', | 37 ('build_tools/json/naclsdk_manifest0.json', |
| 37 'nacl_sdk/sdk_cache/naclsdk_manifest2.json'), | 38 'nacl_sdk/sdk_cache/naclsdk_manifest2.json'), |
| 38 | 39 |
| 39 # SDK tools | 40 # SDK tools |
| 40 ('build_tools/sdk_tools/cacerts.txt', 'nacl_sdk/sdk_tools/cacerts.txt'), | 41 ('build_tools/sdk_tools/cacerts.txt', 'nacl_sdk/sdk_tools/cacerts.txt'), |
| 41 ('build_tools/sdk_tools/sdk_update.py', 'nacl_sdk/sdk_tools/sdk_update.py'), | 42 ('build_tools/sdk_tools/*.py', 'nacl_sdk/sdk_tools/'), |
| 42 ('build_tools/sdk_tools/sdk_update_common.py', | 43 ('build_tools/sdk_tools/command/*.py', 'nacl_sdk/sdk_tools/command/'), |
| 43 'nacl_sdk/sdk_tools/sdk_update_common.py'), | 44 ('build_tools/sdk_tools/third_party/*.py', 'nacl_sdk/sdk_tools/third_party/'), |
| 44 ('build_tools/sdk_tools/sdk_update_main.py', | 45 ('build_tools/sdk_tools/third_party/fancy_urllib/*.py', |
| 45 'nacl_sdk/sdk_tools/sdk_update_main.py'), | 46 'nacl_sdk/sdk_tools/third_party/fancy_urllib/'), |
| 46 ('build_tools/manifest_util.py', 'nacl_sdk/sdk_tools/manifest_util.py'), | |
| 47 ('build_tools/sdk_tools/third_party/__init__.py', | |
| 48 'nacl_sdk/sdk_tools/third_party/__init__.py'), | |
| 49 ('build_tools/sdk_tools/third_party/fancy_urllib/__init__.py', | |
| 50 'nacl_sdk/sdk_tools/third_party/fancy_urllib/__init__.py'), | |
| 51 ('build_tools/sdk_tools/third_party/fancy_urllib/README', | 47 ('build_tools/sdk_tools/third_party/fancy_urllib/README', |
| 52 'nacl_sdk/sdk_tools/third_party/fancy_urllib/README'), | 48 'nacl_sdk/sdk_tools/third_party/fancy_urllib/README'), |
| 49 ('build_tools/manifest_util.py', 'nacl_sdk/sdk_tools/manifest_util.py'), |
| 53 ('LICENSE', 'nacl_sdk/sdk_tools/LICENSE'), | 50 ('LICENSE', 'nacl_sdk/sdk_tools/LICENSE'), |
| 54 (CYGTAR, 'nacl_sdk/sdk_tools/cygtar.py'), | 51 (CYGTAR, 'nacl_sdk/sdk_tools/cygtar.py'), |
| 55 ] | 52 ] |
| 56 | 53 |
| 57 | 54 |
| 58 def MakeUpdaterFilesAbsolute(out_dir): | 55 def MakeUpdaterFilesAbsolute(out_dir): |
| 59 """Return the result of changing all relative paths in UPDATER_FILES to | 56 """Return the result of changing all relative paths in UPDATER_FILES to |
| 60 absolute paths. | 57 absolute paths. |
| 61 | 58 |
| 62 Args: | 59 Args: |
| 63 out_dir: The output directory. | 60 out_dir: The output directory. |
| 64 Returns: | 61 Returns: |
| 65 A list of 2-tuples. The first element in each tuple is the source path and | 62 A list of 2-tuples. The first element in each tuple is the source path and |
| 66 the second is the destination path. | 63 the second is the destination path. |
| 67 """ | 64 """ |
| 68 assert os.path.isabs(out_dir) | 65 assert os.path.isabs(out_dir) |
| 69 | 66 |
| 70 result = [] | 67 result = [] |
| 71 for in_file, out_file in UPDATER_FILES: | 68 for in_file, out_file in UPDATER_FILES: |
| 72 if not os.path.isabs(in_file): | 69 if not os.path.isabs(in_file): |
| 73 in_file = os.path.join(SDK_SRC_DIR, in_file) | 70 in_file = os.path.join(SDK_SRC_DIR, in_file) |
| 74 out_file = os.path.join(out_dir, out_file) | 71 out_file = os.path.join(out_dir, out_file) |
| 75 result.append((in_file, out_file)) | 72 result.append((in_file, out_file)) |
| 76 return result | 73 return result |
| 77 | 74 |
| 78 | 75 |
| 76 def GlobFiles(files): |
| 77 """Expand wildcards for 2-tuples of sources/destinations. |
| 78 |
| 79 This function also will convert destinations from directories into filenames. |
| 80 For example: |
| 81 ('foo/*.py', 'bar/') => [('foo/a.py', 'bar/a.py'), ('foo/b.py', 'bar/b.py')] |
| 82 |
| 83 Args: |
| 84 files: A list of 2-tuples of (source, dest) paths. |
| 85 Returns: |
| 86 A new list of 2-tuples, after the sources have been wildcard-expanded, and |
| 87 the destinations have been changed from directories to filenames. |
| 88 """ |
| 89 result = [] |
| 90 for in_file_glob, out_file in files: |
| 91 if out_file.endswith('/'): |
| 92 for in_file in glob.glob(in_file_glob): |
| 93 result.append((in_file, |
| 94 os.path.join(out_file, os.path.basename(in_file)))) |
| 95 else: |
| 96 result.append((in_file_glob, out_file)) |
| 97 return result |
| 98 |
| 99 |
| 79 def CopyFiles(files): | 100 def CopyFiles(files): |
| 80 """Given a list of 2-tuples (source, dest), copy each source file to a dest | 101 """Given a list of 2-tuples (source, dest), copy each source file to a dest |
| 81 file. | 102 file. |
| 82 | 103 |
| 83 Args: | 104 Args: |
| 84 files: A list of 2-tuples.""" | 105 files: A list of 2-tuples.""" |
| 85 for in_file, out_file in files: | 106 for in_file, out_file in files: |
| 86 buildbot_common.MakeDir(os.path.dirname(out_file)) | 107 buildbot_common.MakeDir(os.path.dirname(out_file)) |
| 87 buildbot_common.CopyFile(in_file, out_file) | 108 buildbot_common.CopyFile(in_file, out_file) |
| 88 | 109 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 revision_number: The revision number of this updater, as an integer. Or | 143 revision_number: The revision number of this updater, as an integer. Or |
| 123 None, to use the current Chrome revision.""" | 144 None, to use the current Chrome revision.""" |
| 124 buildbot_common.BuildStep('Create Updater') | 145 buildbot_common.BuildStep('Create Updater') |
| 125 | 146 |
| 126 out_dir = os.path.abspath(out_dir) | 147 out_dir = os.path.abspath(out_dir) |
| 127 | 148 |
| 128 # Build SDK directory | 149 # Build SDK directory |
| 129 buildbot_common.RemoveDir(os.path.join(out_dir, 'nacl_sdk')) | 150 buildbot_common.RemoveDir(os.path.join(out_dir, 'nacl_sdk')) |
| 130 | 151 |
| 131 updater_files = MakeUpdaterFilesAbsolute(out_dir) | 152 updater_files = MakeUpdaterFilesAbsolute(out_dir) |
| 153 updater_files = GlobFiles(updater_files) |
| 132 | 154 |
| 133 CopyFiles(updater_files) | 155 CopyFiles(updater_files) |
| 134 UpdateRevisionNumber(out_dir, revision_number) | 156 UpdateRevisionNumber(out_dir, revision_number) |
| 135 | 157 |
| 136 out_files = [os.path.relpath(out_file, out_dir) | 158 out_files = [os.path.relpath(out_file, out_dir) |
| 137 for _, out_file in updater_files] | 159 for _, out_file in updater_files] |
| 138 | 160 |
| 139 # Make zip | 161 # Make zip |
| 140 buildbot_common.RemoveFile(os.path.join(out_dir, 'nacl_sdk.zip')) | 162 buildbot_common.RemoveFile(os.path.join(out_dir, 'nacl_sdk.zip')) |
| 141 buildbot_common.Run([sys.executable, oshelpers.__file__, 'zip', | 163 buildbot_common.Run([sys.executable, oshelpers.__file__, 'zip', |
| (...skipping 19 matching lines...) Expand all Loading... |
| 161 dest='revision', default=None) | 183 dest='revision', default=None) |
| 162 options, args = parser.parse_args(args[1:]) | 184 options, args = parser.parse_args(args[1:]) |
| 163 | 185 |
| 164 if options.revision: | 186 if options.revision: |
| 165 options.revision = int(options.revision) | 187 options.revision = int(options.revision) |
| 166 BuildUpdater(options.out_dir, options.revision) | 188 BuildUpdater(options.out_dir, options.revision) |
| 167 | 189 |
| 168 | 190 |
| 169 if __name__ == '__main__': | 191 if __name__ == '__main__': |
| 170 sys.exit(main(sys.argv)) | 192 sys.exit(main(sys.argv)) |
| OLD | NEW |