Chromium Code Reviews| 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 """Takes the output of the build step and turns it into a compressed | 6 """Takes the output of the build step and turns it into a compressed |
| 7 archive ready for distribution. | 7 archive ready for distribution. |
| 8 | 8 |
| 9 This script assumes the build script has been run to compile the add-in. | 9 This script assumes the build script has been run to compile the add-in. |
| 10 It zips up all files required for the add-in installation and places the | 10 It zips up all files required for the add-in installation and places the |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 import sys | 22 import sys |
| 23 from os.path import join | 23 from os.path import join |
| 24 | 24 |
| 25 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 25 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 26 | 26 |
| 27 # Checkout root | 27 # Checkout root |
| 28 ROOT = os.path.dirname(os.path.dirname(SCRIPT_DIR)) | 28 ROOT = os.path.dirname(os.path.dirname(SCRIPT_DIR)) |
| 29 | 29 |
| 30 # Root output directory. | 30 # Root output directory. |
| 31 BUILD_DIR = join(ROOT, 'out', 'vs_addin') | 31 BUILD_DIR = join(ROOT, 'out', 'vs_addin') |
| 32 STAGING_DIR = join(BUILD_DIR, 'staging') | |
| 32 | 33 |
| 33 # Directory that contains the build assemblies. | 34 # Directory that contains the build assemblies. |
| 34 ASSEMBLY_DIRECTORY_2010 = join(BUILD_DIR, '2010', 'Debug') | 35 ASSEMBLY_DIRECTORY_2010 = join(BUILD_DIR, '2010', 'Debug') |
| 35 ASSEMBLY_DIRECTORY_2012 = join(BUILD_DIR, '2012', 'Debug') | 36 ASSEMBLY_DIRECTORY_2012 = join(BUILD_DIR, '2012', 'Debug') |
| 36 | 37 |
| 37 # Directory containing static installer resources. | 38 # Directory containing static installer resources. |
| 38 RESOURCE_DIRECTORY = join(SCRIPT_DIR, 'InstallerResources') | 39 RESOURCE_DIRECTORY = join(SCRIPT_DIR, 'InstallerResources') |
| 39 | 40 |
| 40 # Base name of the final zip file. | 41 # Base name of the final zip file. |
| 41 OUTPUT_NAME = join(BUILD_DIR, 'vs_addin.tgz') | 42 OUTPUT_NAME = join(BUILD_DIR, 'vs_addin.tgz') |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 68 | 69 |
| 69 # List of source/destination pairs to include in archive file. | 70 # List of source/destination pairs to include in archive file. |
| 70 FILE_LIST = [ | 71 FILE_LIST = [ |
| 71 (ADDIN_ASSEMBLY_2010, '2010'), | 72 (ADDIN_ASSEMBLY_2010, '2010'), |
| 72 (ADDIN_ASSEMBLY_2012, '2012'), | 73 (ADDIN_ASSEMBLY_2012, '2012'), |
| 73 (join(ASSEMBLY_DIRECTORY_2010, 'NativeClientVSAddIn.AddIn'), '2010'), | 74 (join(ASSEMBLY_DIRECTORY_2010, 'NativeClientVSAddIn.AddIn'), '2010'), |
| 74 (join(ASSEMBLY_DIRECTORY_2012, 'NativeClientVSAddIn.AddIn'), '2012'), | 75 (join(ASSEMBLY_DIRECTORY_2012, 'NativeClientVSAddIn.AddIn'), '2012'), |
| 75 (join(ASSEMBLY_DIRECTORY_2010, 'NaCl.Build.CPPTasks.dll'), 'NaCl')] | 76 (join(ASSEMBLY_DIRECTORY_2010, 'NaCl.Build.CPPTasks.dll'), 'NaCl')] |
| 76 | 77 |
| 77 | 78 |
| 78 def AddFolderToArchive(path, archive, root=""): | 79 def MakeDir(dirname): |
| 80 if not os.path.isdir(dirname): | |
| 81 os.makedirs(dirname) | |
| 82 | |
| 83 | |
| 84 def StageDirectory(dir_to_copy): | |
|
binji
2014/09/23 20:37:35
this seems to be mostly copy/paste from AddFolderT
Sam Clegg
2014/09/24 17:24:42
Cleaned these up.
| |
| 85 """Adds an entire folder and sub folders to the staging directory. | |
| 86 | |
| 87 Args: | |
| 88 dir_to_copy: Directory to add. | |
| 89 basedir: The directory with the staging direcotry. | |
| 90 """ | |
| 91 # Ensure the dir_to_copy ends in trailing slash. | |
| 92 dir_to_copy = dir_to_copy.rstrip("/\\") + "\\" | |
| 93 for root, dir_names, files in os.walk(dir_to_copy): | |
| 94 for filename in files: | |
| 95 src_path = join(root, filename) | |
| 96 | |
| 97 # If the file path matches an exclude, don't include it. | |
| 98 if any(re.search(expr, src_path) for expr in EXCLUDES): | |
| 99 continue | |
| 100 | |
| 101 relative_dir = root[len(dir_to_copy):] | |
|
binji
2014/09/23 20:37:35
I usually use os.path.relpath for this
Sam Clegg
2014/09/24 17:24:42
Done. Thanks.
| |
| 102 dest_path = join(STAGING_DIR, relative_dir, filename) | |
| 103 | |
| 104 MakeDir(os.path.dirname(dest_path)) | |
| 105 assert(not os.path.exists(dest_path)) | |
| 106 shutil.copy(src_path, dest_path) | |
| 107 | |
| 108 | |
| 109 def AddFolderToArchive(path, archive): | |
| 79 """Adds an entire folder and sub folders to an open archive object. | 110 """Adds an entire folder and sub folders to an open archive object. |
| 80 | 111 |
| 81 The archive must already be open and it is not closed by this function. | 112 The archive must already be open and it is not closed by this function. |
| 82 | 113 |
| 83 Args: | 114 Args: |
| 84 path: Folder to add. | 115 path: Folder to add. |
| 85 archive: Already open archive file. | 116 archive: Already open archive file. |
| 86 | |
| 87 Returns: | |
| 88 Nothing. | |
| 89 """ | 117 """ |
| 90 # Ensure the path ends in trailing slash. | 118 # Ensure the path ends in trailing slash. |
| 91 path = path.rstrip("/\\") + "\\" | 119 path = path.rstrip("/\\") + "\\" |
| 92 for dir_path, dir_names, files in os.walk(path): | 120 for dir_path, dir_names, files in os.walk(path): |
| 93 for filename in files: | 121 for filename in files: |
| 94 read_path = join(dir_path, filename) | 122 src_path = join(dir_path, filename) |
| 95 | 123 |
| 96 # If the file path matches an exclude, don't include it. | 124 # If the file path matches an exclude, don't include it. |
| 97 if any(re.search(expr, read_path) for expr in EXCLUDES): | 125 if any(re.search(expr, src_path) for expr in EXCLUDES): |
| 98 continue | 126 continue |
| 99 | 127 |
| 100 zip_based_dir = dir_path[len(path):] | 128 archive_dir = os.path.join('vs_addin', dir_path[len(path):]) |
| 101 write_path = join(root, zip_based_dir, filename) | 129 archive_name = join(archive_dir, filename) |
| 102 WriteFileToArchive(archive, read_path, write_path) | 130 |
| 131 print 'Archiving: %s' % archive_name | |
| 132 archive.add(src_path, archive_name) | |
| 103 | 133 |
| 104 | 134 |
| 105 def CopyAddinFile(assembly, path, vs_version): | 135 def CopyAddinFile(assembly, path, vs_version): |
| 106 """Copy the .AddIn file to the given path while making the necessary | 136 """Copy the .AddIn file to the given path while making the necessary |
| 107 replacements. | 137 replacements. |
| 108 | 138 |
| 109 The version number is obtained from the NativeClientAddIn.dll assembly which | 139 The version number is obtained from the NativeClientAddIn.dll assembly which |
| 110 is built during the build process. | 140 is built during the build process. |
| 111 """ | 141 """ |
| 112 infopath = '\\VarFileInfo\\Translation' | 142 infopath = '\\VarFileInfo\\Translation' |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 127 replacements = {'VS_VERSION': vs_version, 'ADDIN_VERSION': version} | 157 replacements = {'VS_VERSION': vs_version, 'ADDIN_VERSION': version} |
| 128 data = string.Template(data).substitute(replacements) | 158 data = string.Template(data).substitute(replacements) |
| 129 dest_file.write(data) | 159 dest_file.write(data) |
| 130 | 160 |
| 131 | 161 |
| 132 def Error(msg): | 162 def Error(msg): |
| 133 sys.stderr.write(msg + '\n') | 163 sys.stderr.write(msg + '\n') |
| 134 sys.exit(1) | 164 sys.exit(1) |
| 135 | 165 |
| 136 | 166 |
| 137 def WriteFileToArchive(archive, filename, archive_name): | |
| 138 archive_name = join('vs_addin', archive_name) | |
| 139 if archive_name.replace('\\', '/') in archive.getnames(): | |
| 140 print 'Skipping: %s' % archive_name | |
| 141 return | |
| 142 print 'Adding: %s' % archive_name | |
| 143 archive.add(filename, archive_name) | |
| 144 | |
| 145 | |
| 146 def CopyWithReplacement(src, dest, replacements): | 167 def CopyWithReplacement(src, dest, replacements): |
| 147 if os.path.exists(dest): | 168 MakeDir(dest) |
| 148 shutil.rmtree(dest) | |
| 149 os.makedirs(dest) | |
| 150 src_basename = os.path.basename(src) | 169 src_basename = os.path.basename(src) |
| 151 dest_basename = os.path.basename(dest) | 170 dest_basename = os.path.basename(dest) |
| 152 | 171 |
| 153 olddir = os.getcwd() | 172 olddir = os.getcwd() |
| 154 try: | 173 try: |
| 155 os.chdir(src) | 174 os.chdir(src) |
| 156 for root, dirs, filenames in os.walk('.'): | 175 for root, dirs, filenames in os.walk('.'): |
| 157 for filename in filenames: | 176 for filename in filenames: |
| 158 srcfile = join(root, filename) | 177 srcfile = join(root, filename) |
| 159 # skip non-files, in particular .svn folders. | 178 # skip non-files, in particular .svn folders. |
| 160 if not os.path.isfile(srcfile): | 179 if not os.path.isfile(srcfile): |
| 161 continue | 180 continue |
| 162 | 181 |
| 163 destdir = join(dest, root.replace(src_basename, dest_basename)) | 182 destdir = join(dest, root.replace(src_basename, dest_basename)) |
| 164 if not os.path.exists(destdir): | 183 destdir = os.path.normpath(destdir) |
| 165 os.makedirs(destdir) | 184 MakeDir(destdir) |
| 166 | 185 |
| 167 destfile = join(destdir, filename.replace(src_basename, dest_basename)) | 186 destfile = join(destdir, filename.replace(src_basename, dest_basename)) |
| 187 if os.path.exists(destfile): | |
| 188 print 'Skipping: %s' % destfile | |
| 189 continue | |
| 190 | |
| 168 with open(srcfile, "rb") as f: | 191 with open(srcfile, "rb") as f: |
| 169 data = f.read() | 192 data = f.read() |
| 170 for pat, subst in replacements.iteritems(): | 193 for pat, subst in replacements.iteritems(): |
| 171 data = data.replace(pat, subst) | 194 data = data.replace(pat, subst) |
| 195 | |
| 172 with open(destfile, "wb") as f: | 196 with open(destfile, "wb") as f: |
| 173 f.write(data) | 197 f.write(data) |
| 174 finally: | 198 finally: |
| 175 os.chdir(olddir) | 199 os.chdir(olddir) |
| 176 | 200 |
| 177 | 201 |
| 178 def main(): | 202 def main(): |
| 179 if not os.path.exists(BUILD_DIR): | 203 if not os.path.exists(BUILD_DIR): |
| 180 Error("build dir not found: %s" % BUILD_DIR) | 204 Error("build dir not found: %s" % BUILD_DIR) |
| 181 | 205 |
| 182 CopyAddinFile(ADDIN_ASSEMBLY_2010, ASSEMBLY_DIRECTORY_2010, '10.0') | 206 CopyAddinFile(ADDIN_ASSEMBLY_2010, ASSEMBLY_DIRECTORY_2010, '10.0') |
| 183 CopyAddinFile(ADDIN_ASSEMBLY_2012, ASSEMBLY_DIRECTORY_2012, '11.0') | 207 CopyAddinFile(ADDIN_ASSEMBLY_2012, ASSEMBLY_DIRECTORY_2012, '11.0') |
| 184 | 208 |
| 185 archive = tarfile.open(OUTPUT_NAME, 'w:gz') | 209 if os.path.exists(STAGING_DIR): |
| 210 shutil.rmtree(STAGING_DIR) | |
| 186 | 211 |
| 187 for source_dest in FILE_LIST: | 212 # Start by staging the entire resource tree |
| 188 file_name = os.path.basename(source_dest[0]) | 213 StageDirectory(RESOURCE_DIRECTORY) |
| 189 dest = join(source_dest[1], file_name) | |
| 190 WriteFileToArchive(archive, source_dest[0], dest) | |
| 191 | 214 |
| 192 AddFolderToArchive(RESOURCE_DIRECTORY, archive) | 215 # Then stage anything in the FILE_LIST |
| 216 for source, dest in FILE_LIST: | |
| 217 file_name = os.path.basename(source) | |
| 218 dest = join(STAGING_DIR, dest, file_name) | |
| 219 assert(not os.path.exists(dest)) | |
| 220 MakeDir(os.path.dirname(dest)) | |
| 221 shutil.copy(source, dest) | |
| 193 | 222 |
| 194 # Duplicate the NaCl64 platform but rename it to NaCl32 | 223 # Duplicate the NaCl64 platform but rename it to NaCl32 |
| 195 src = join(RESOURCE_DIRECTORY, 'NaCl64') | 224 src = join(RESOURCE_DIRECTORY, 'NaCl64') |
| 196 | 225 |
| 197 # Create NaCl32 | 226 # Create NaCl32 |
| 198 dest = join(BUILD_DIR, 'NaCl32') | 227 dest = join(STAGING_DIR, 'NaCl32') |
| 199 CopyWithReplacement(src, dest, {'x86_64': 'i686', '64': '32'}) | 228 CopyWithReplacement(src, dest, {'x86_64': 'i686', '64': '32'}) |
| 200 AddFolderToArchive(dest, archive, "NaCl32") | |
| 201 | 229 |
| 202 # Create NaClARM | 230 # Create NaClARM |
| 203 arm_replacements = { | 231 arm_replacements = { |
| 204 'x86_64': 'arm', | 232 'x86_64': 'arm', |
| 205 '64': 'arm', | 233 '64': 'arm', |
| 206 'win_x86': 'win_arm' | 234 'win_x86': 'win_arm' |
| 207 } | 235 } |
| 208 | 236 |
| 209 dest = join(BUILD_DIR, 'NaClARM') | 237 dest = join(STAGING_DIR, 'NaClARM') |
| 210 CopyWithReplacement(src, dest, arm_replacements) | 238 CopyWithReplacement(src, dest, arm_replacements) |
| 211 AddFolderToArchive(dest, archive, "NaClARM") | |
| 212 | 239 |
| 213 # Create PNaCl | 240 # Create PNaCl |
| 214 pnacl_replacements = { | 241 pnacl_replacements = { |
| 215 'NaCl64': 'PNaCl', | 242 'NaCl64': 'PNaCl', |
| 216 'x86_64': 'pnacl', | 243 'x86_64': 'pnacl', |
| 217 '64': '32', | 244 '64': '32', |
| 218 '.nexe': '.pexe', | 245 '.nexe': '.pexe', |
| 219 'nacl_link.xml': 'pnacl_link.xml', | 246 'nacl_link.xml': 'pnacl_link.xml', |
| 220 '$(ProjectName)_$(PlatformArchitecture)': '$(ProjectName)', | 247 '$(ProjectName)_$(PlatformArchitecture)': '$(ProjectName)', |
| 221 } | 248 } |
| 222 | 249 |
| 223 dest = join(BUILD_DIR, 'PNaCl') | 250 dest = join(STAGING_DIR, 'PNaCl') |
| 224 CopyWithReplacement(src, dest, pnacl_replacements) | 251 CopyWithReplacement(src, dest, pnacl_replacements) |
| 225 AddFolderToArchive(dest, archive, "PNaCl") | |
| 226 | 252 |
| 253 # Create archive | |
| 254 archive = tarfile.open(OUTPUT_NAME, 'w:gz') | |
| 255 AddFolderToArchive(STAGING_DIR, archive) | |
| 227 archive.close() | 256 archive.close() |
| 228 | 257 |
| 229 | 258 |
| 230 if __name__ == '__main__': | 259 if __name__ == '__main__': |
| 231 main() | 260 main() |
| OLD | NEW |