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

Side by Side Diff: visual_studio/NativeClientVSAddIn/create_package.py

Issue 14122017: [VS Addin] Add visual studio 2012 support (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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
11 result in out/vs_addin/vs_addin.tgz. 11 result in out/vs_addin/vs_addin.tgz.
12 """ 12 """
13 13
14 import os 14 import os
15 import re 15 import re
16 import fileinput 16 import fileinput
17 import win32api 17 import win32api
18 import shutil 18 import shutil
19 import tarfile 19 import tarfile
20 import zipfile 20 import zipfile
21 import string
21 import sys 22 import sys
22 from os.path import join 23 from os.path import join
23 24
24 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 25 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
25 26
26 # Checkout root 27 # Checkout root
27 ROOT = os.path.dirname(os.path.dirname(SCRIPT_DIR)) 28 ROOT = os.path.dirname(os.path.dirname(SCRIPT_DIR))
28 29
29 # Root output directory. 30 # Root output directory.
30 BUILD_DIR = join(ROOT, 'out', 'vs_addin') 31 BUILD_DIR = join(ROOT, 'out', 'vs_addin')
31 32
32 # Directory that contains the build assemblies. 33 # Directory that contains the build assemblies.
33 ASSEMBLY_DIRECTORY = join(BUILD_DIR, 'Debug') 34 ASSEMBLY_DIRECTORY_2010 = join(BUILD_DIR, '2010', 'Debug')
35 ASSEMBLY_DIRECTORY_2012 = join(BUILD_DIR, '2012', 'Debug')
34 36
35 # Directory containing static installer resources. 37 # Directory containing static installer resources.
36 RESOURCE_DIRECTORY = join(SCRIPT_DIR, 'InstallerResources') 38 RESOURCE_DIRECTORY = join(SCRIPT_DIR, 'InstallerResources')
37 39
38 # Base name of the final zip file. 40 # Base name of the final zip file.
39 OUTPUT_NAME = join(BUILD_DIR, 'vs_addin.tgz') 41 OUTPUT_NAME = join(BUILD_DIR, 'vs_addin.tgz')
40 42
41 # AddIn metadata file path. We will modify this with the version #. 43 # AddIn metadata file path. We will modify this with the version #.
42 ADDIN_METADATA = join(RESOURCE_DIRECTORY, 'NativeClientVSAddIn.AddIn') 44 ADDIN_METADATA = join(RESOURCE_DIRECTORY, 'NativeClientVSAddIn.AddIn')
43 45
44 # AddIn dll file path. We will obtain our add-in version from this. 46 # AddIn dll file path. We will obtain our add-in version from this.
45 ADDIN_ASSEMBLY = join(ASSEMBLY_DIRECTORY, 'NativeClientVSAddIn.dll') 47 ADDIN_ASSEMBLY_2010 = join(ASSEMBLY_DIRECTORY_2010, 'NativeClientVSAddIn.dll')
48 ADDIN_ASSEMBLY_2012 = join(ASSEMBLY_DIRECTORY_2012, 'NativeClientVSAddIn.dll')
46 49
47 # Regex list to exclude from the archive. If a file path matches any of the 50 # Regex list to exclude from the archive. If a file path matches any of the
48 # expressions during a call to AddFolderToArchive it is excluded from the 51 # expressions during a call to AddFolderToArchive it is excluded from the
49 # archive file. 52 # archive file.
50 EXCLUDES = [ 53 EXCLUDES = [
51 r'\.svn', # Exclude .svn directories. 54 r'\.svn$', # Exclude .svn directories.
binji 2013/05/25 00:02:55 it seems like this was correct before -- shouldn't
Sam Clegg 2013/05/29 04:58:33 Hmm yes I think you are right.
52 r'\.swp', # Exclude .swp files. 55 r'\.swp$', # Exclude .swp files.
56 r'\.pyc$', # Exclude .pyc files.
53 r'examples\\.*\\chrome_data', 57 r'examples\\.*\\chrome_data',
54 r'examples\\.*\\Debug', 58 r'examples\\.*\\Debug',
55 r'examples\\.*\\newlib', 59 r'examples\\.*\\newlib',
56 r'examples\\.*\\glibc', 60 r'examples\\.*\\glibc',
57 r'examples\\.*\\PNaCl', 61 r'examples\\.*\\PNaCl',
58 r'examples\\.*\\win', 62 r'examples\\.*\\win',
59 r'examples\\.*\\ipch', 63 r'examples\\.*\\ipch',
60 r'examples\\.*\\*.sdf', 64 r'examples\\.*\\*.sdf',
61 r'examples\\.*\\*.suo', 65 r'examples\\.*\\*.suo',
62 # Exclude .AddIn file for now since we need to modify it with version info. 66 # Exclude .AddIn file for now since we need to modify it with version info.
63 re.escape(ADDIN_METADATA)] 67 re.escape(ADDIN_METADATA)]
64 68
65 # List of source/destination pairs to include in archive file. 69 # List of source/destination pairs to include in archive file.
66 FILE_LIST = [ 70 FILE_LIST = [
67 (ADDIN_ASSEMBLY, ''), 71 (ADDIN_ASSEMBLY_2010, '2010'),
68 (join(ASSEMBLY_DIRECTORY, 'NaCl.Build.CPPTasks.dll'), 'NaCl')] 72 (ADDIN_ASSEMBLY_2012, '2012'),
73 (join(ASSEMBLY_DIRECTORY_2010, 'NativeClientVSAddIn.AddIn'), '2010'),
74 (join(ASSEMBLY_DIRECTORY_2012, 'NativeClientVSAddIn.AddIn'), '2012'),
75 (join(ASSEMBLY_DIRECTORY_2010, 'NaCl.Build.CPPTasks.dll'), 'NaCl')]
69 76
70 77
71 def AddFolderToArchive(path, archive, root=""): 78 def AddFolderToArchive(path, archive, root=""):
72 """Adds an entire folder and sub folders to an open archive object. 79 """Adds an entire folder and sub folders to an open archive object.
73 80
74 The archive must already be open and it is not closed by this function. 81 The archive must already be open and it is not closed by this function.
75 82
76 Args: 83 Args:
77 path: Folder to add. 84 path: Folder to add.
78 archive: Already open archive file. 85 archive: Already open archive file.
79 86
80 Returns: 87 Returns:
81 Nothing. 88 Nothing.
82 """ 89 """
83 # Ensure the path ends in trailing slash. 90 # Ensure the path ends in trailing slash.
84 path = path.rstrip("/\\") + "\\" 91 path = path.rstrip("/\\") + "\\"
85 for dir_path, dir_names, files in os.walk(path): 92 for dir_path, dir_names, files in os.walk(path):
86 for filename in files: 93 for filename in files:
87 read_path = join(dir_path, filename) 94 read_path = join(dir_path, filename)
88 95
89 # If the file path matches an exclude, don't include it. 96 # If the file path matches an exclude, don't include it.
90 if any(re.search(expr, read_path) for expr in EXCLUDES): 97 if any(re.search(expr, read_path) for expr in EXCLUDES):
91 continue 98 continue
92 99
93 zip_based_dir = dir_path[len(path):] 100 zip_based_dir = dir_path[len(path):]
94 write_path = join(root, zip_based_dir, filename) 101 write_path = join(root, zip_based_dir, filename)
95 WriteFileToArchive(archive, read_path, write_path) 102 WriteFileToArchive(archive, read_path, write_path)
96 103
97 104
98 def AddVersionModifiedAddinFile(archive): 105 def CopyAddinFile(assembly, path, vs_version):
99 """Modifies the .AddIn file with the build version and adds to the zip. 106 """Modifies the .AddIn file with the build version and adds to the zip.
100 107
101 The version number is obtained from the NativeClientAddIn.dll assembly which 108 The version number is obtained from the NativeClientAddIn.dll assembly which
102 is built during the build process. 109 is built during the build process.
103
104 Args:
105 archive: Already open archive file.
106 """ 110 """
107 path = '\\VarFileInfo\\Translation' 111 infopath = '\\VarFileInfo\\Translation'
108 pairs = win32api.GetFileVersionInfo(ADDIN_ASSEMBLY, path) 112 pairs = win32api.GetFileVersionInfo(assembly, infopath)
109 lang, codepage = pairs[0] 113 lang, codepage = pairs[0]
110 path = u'\\StringFileInfo\\%04X%04X\\ProductVersion' % (lang, codepage) 114 infopath = u'\\StringFileInfo\\%04X%04X\\ProductVersion' % (lang, codepage)
111 prodVersion = win32api.GetFileVersionInfo(ADDIN_ASSEMBLY, path) 115 prodVersion = win32api.GetFileVersionInfo(assembly, infopath)
112 version = "[%s]" % prodVersion 116 version = "[%s]" % prodVersion
113 print "\nNaCl VS Add-in Build version: %s\n" % (version) 117 print "\nNaCl VS Add-in Build version: %s\n" % (version)
114 118
115 metadata_filename = os.path.basename(ADDIN_METADATA) 119 metadata_filename = os.path.basename(ADDIN_METADATA)
116 modified_file = join(ASSEMBLY_DIRECTORY, metadata_filename) 120 modified_file = join(path, metadata_filename)
117 121
118 # Copy the metadata file to new location and modify the version info. 122 # Copy the metadata file to new location and modify the version info.
119 with open(ADDIN_METADATA, 'r') as source_file: 123 with open(ADDIN_METADATA, 'r') as source_file:
120 with open(modified_file, 'w') as dest_file: 124 with open(modified_file, 'w') as dest_file:
121 for line in source_file: 125 data = source_file.read()
122 dest_file.write(line.replace("[REPLACE_ADDIN_VERSION]", version)) 126 replacements = {'VS_VERSION': vs_version, 'ADDIN_VERSION': version}
123 127 data = string.Template(data).substitute(replacements)
124 WriteFileToArchive(archive, modified_file, metadata_filename) 128 dest_file.write(data)
binji 2013/05/25 00:02:55 not added to archive...?
Sam Clegg 2013/05/29 04:58:33 This is now done by including them in FILE_LIST.
125 129
126 130
127 def Error(msg): 131 def Error(msg):
128 sys.stderr.write(msg + '\n') 132 sys.stderr.write(msg + '\n')
129 sys.exit(1) 133 sys.exit(1)
130 134
131 135
132 def WriteFileToArchive(archive, filename, archive_name): 136 def WriteFileToArchive(archive, filename, archive_name):
133 archive_name = join('vs_addin', archive_name) 137 archive_name = join('vs_addin', archive_name)
134 if archive_name.replace('\\', '/') in archive.getnames(): 138 if archive_name.replace('\\', '/') in archive.getnames():
135 print 'Skipping: %s' % archive_name 139 print 'Skipping: %s' % archive_name
136 return 140 return
137 print 'Adding: %s' % archive_name 141 print 'Adding: %s' % archive_name
138 archive.add(filename, archive_name) 142 archive.add(filename, archive_name)
139 143
140 144
141 def CopyWithReplacement(src, dest, replacements): 145 def CopyWithReplacement(src, dest, replacements):
142 if os.path.exists(dest): 146 if os.path.exists(dest):
143 shutil.rmtree(dest) 147 shutil.rmtree(dest)
144 os.makedirs(dest) 148 os.makedirs(dest)
145 src_basename = os.path.basename(src) 149 src_basename = os.path.basename(src)
146 dest_basename = os.path.basename(dest) 150 dest_basename = os.path.basename(dest)
147 for filename in os.listdir(src): 151
148 srcfile = join(src, filename) 152 olddir = os.getcwd()
149 # skip non-files, in particular .svn folders. 153 try:
150 if not os.path.isfile(srcfile): 154 os.chdir(src)
binji 2013/05/25 00:02:55 why chdir?
Sam Clegg 2013/05/29 04:58:33 So that 'root' below is relative to 'src'. Altern
151 continue 155 for root, dirs, filenames in os.walk('.'):
152 destfile = join(dest, filename.replace(src_basename, dest_basename)) 156 for filename in filenames:
153 with open(srcfile, "rb") as f: 157 srcfile = join(root, filename)
154 data = f.read() 158 # skip non-files, in particular .svn folders.
155 for pat, subst in replacements.iteritems(): 159 if not os.path.isfile(srcfile):
156 data = data.replace(pat, subst) 160 continue
157 with open(destfile, "wb") as f: 161
158 f.write(data) 162 destdir = join(dest, root.replace(src_basename, dest_basename))
163 if not os.path.exists(destdir):
164 os.makedirs(destdir)
165
166 destfile = join(destdir, filename.replace(src_basename, dest_basename))
167 with open(srcfile, "rb") as f:
168 data = f.read()
169 for pat, subst in replacements.iteritems():
170 data = data.replace(pat, subst)
171 with open(destfile, "wb") as f:
172 f.write(data)
173 finally:
174 os.chdir(olddir)
159 175
160 176
161 def main(): 177 def main():
162 if not os.path.exists(BUILD_DIR): 178 if not os.path.exists(BUILD_DIR):
163 Error("build dir not found: %s" % BUILD_DIR) 179 Error("build dir not found: %s" % BUILD_DIR)
164 180
181 CopyAddinFile(ADDIN_ASSEMBLY_2010, ASSEMBLY_DIRECTORY_2010, '10.0')
182 CopyAddinFile(ADDIN_ASSEMBLY_2012, ASSEMBLY_DIRECTORY_2012, '11.0')
183
165 archive = tarfile.open(OUTPUT_NAME, 'w:gz') 184 archive = tarfile.open(OUTPUT_NAME, 'w:gz')
185
166 for source_dest in FILE_LIST: 186 for source_dest in FILE_LIST:
167 file_name = os.path.basename(source_dest[0]) 187 file_name = os.path.basename(source_dest[0])
168 dest = join(source_dest[1], file_name) 188 dest = join(source_dest[1], file_name)
169 WriteFileToArchive(archive, source_dest[0], dest) 189 WriteFileToArchive(archive, source_dest[0], dest)
170 190
171 AddFolderToArchive(RESOURCE_DIRECTORY, archive) 191 AddFolderToArchive(RESOURCE_DIRECTORY, archive)
172 192
173 # Duplicate the NaCl64 platform but rename it to NaCl32 193 # Duplicate the NaCl64 platform but rename it to NaCl32
174 src = join(RESOURCE_DIRECTORY, 'NaCl64') 194 src = join(RESOURCE_DIRECTORY, 'NaCl64')
175 195
(...skipping 20 matching lines...) Expand all
196 '64': '32', 216 '64': '32',
197 '.nexe': '.pexe', 217 '.nexe': '.pexe',
198 'nacl_link.xml': 'pnacl_link.xml', 218 'nacl_link.xml': 'pnacl_link.xml',
199 '$(ProjectName)_$(PlatformArchitecture)': '$(ProjectName)', 219 '$(ProjectName)_$(PlatformArchitecture)': '$(ProjectName)',
200 } 220 }
201 221
202 dest = join(BUILD_DIR, 'PNaCl') 222 dest = join(BUILD_DIR, 'PNaCl')
203 CopyWithReplacement(src, dest, pnacl_replacements) 223 CopyWithReplacement(src, dest, pnacl_replacements)
204 AddFolderToArchive(dest, archive, "PNaCl") 224 AddFolderToArchive(dest, archive, "PNaCl")
205 225
206 AddVersionModifiedAddinFile(archive)
207 archive.close() 226 archive.close()
208 227
209 228
210 if __name__ == '__main__': 229 if __name__ == '__main__':
211 main() 230 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698