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

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

Issue 10830151: VS Add-in more properties and improvements (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 zips the distributable package. 6 """Takes the output of the build step and zips the distributable package.
7 7
8 This script assumes the build script has been run to compile the add-in. 8 This script assumes the build script has been run to compile the add-in.
9 It zips up all files required for the add-in installation and places the 9 It zips up all files required for the add-in installation and places the
10 result in out/NativeClientVSAddin.zip 10 result in out/NativeClientVSAddin.zip
11 """ 11 """
12 12
13 import codecs
13 import os 14 import os
15 import re
16 import fileinput
17 import win32api
18 import shutil
14 import zipfile 19 import zipfile
15 20
16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 21 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17 22
18 # Root output directory. 23 # Root output directory.
19 BUILD_OUTPUT_DIRECTORY = os.path.join( 24 BUILD_OUTPUT_DIRECTORY = os.path.join(
20 SCRIPT_DIR, 25 SCRIPT_DIR,
21 "../../out/NativeClientVSAddIn/") 26 "../../out/NativeClientVSAddIn")
22
23 # Directory containing static installer resources.
24 RESOURCE_DIRECTORY = os.path.join(SCRIPT_DIR, "InstallerResources/")
25 27
26 # Directory that contains the build assemblies. 28 # Directory that contains the build assemblies.
27 ASSEMBLY_DIRECTORY = os.path.join(BUILD_OUTPUT_DIRECTORY, "Debug") 29 ASSEMBLY_DIRECTORY = os.path.join(BUILD_OUTPUT_DIRECTORY, "Debug")
28 30
31 # Directory containing static installer resources.
32 RESOURCE_DIRECTORY = os.path.join(SCRIPT_DIR, "InstallerResources")
33
29 # Base name of the final zip file. 34 # Base name of the final zip file.
30 OUTPUT_NAME = os.path.join(BUILD_OUTPUT_DIRECTORY, "NativeClientVSAddIn.zip") 35 OUTPUT_NAME = os.path.join(BUILD_OUTPUT_DIRECTORY, "NativeClientVSAddIn.zip")
31 36
37 # AddIn metadata file path. We will modify this with the version #.
38 ADDIN_METADATA = os.path.join(RESOURCE_DIRECTORY, "NativeClientVSAddIn.AddIn")
39
40 # AddIn dll file path. We will obtain our add-in version from this.
41 ADDIN_ASSEMBLY = os.path.join(ASSEMBLY_DIRECTORY, "NativeClientVSAddIn.dll")
42
43 # Regex list to exclude from the zip. If a file path matches any of the
44 # expressions during a call to AddFolderToZip it is excluded from the zip file.
45 EXCLUDES = [
46 '.*\.svn.*', # Exclude .svn directories.
47 # Exclude .AddIn file for now since we need to modify it with version info.
48 re.escape(ADDIN_METADATA)]
49
32 # List of source/destination pairs to include in zip file. 50 # List of source/destination pairs to include in zip file.
33 FILE_LIST = [ 51 FILE_LIST = [
34 (os.path.join(ASSEMBLY_DIRECTORY, "NativeClientVSAddIn.dll"), ''), 52 (ADDIN_ASSEMBLY, ''),
35 (os.path.join(ASSEMBLY_DIRECTORY, "NaCl.Build.CPPTasks.dll"), 'NaCl')] 53 (os.path.join(ASSEMBLY_DIRECTORY, "NaCl.Build.CPPTasks.dll"), 'NaCl')]
36 54
37 55
38 def AddFolderToZip(path, zip_file): 56 def AddFolderToZip(path, zip_file):
39 """Adds an entire folder and sub folders to an open zipfile object. 57 """Adds an entire folder and sub folders to an open zipfile object.
40 58
41 The zip_file must already be open and it is not closed by this function. 59 The zip_file must already be open and it is not closed by this function.
42 60
43 Args: 61 Args:
44 path: Folder to add. 62 path: Folder to add.
45 zipfile: Already open zip file. 63 zipfile: Already open zip file.
46 64
47 Returns: 65 Returns:
48 Nothing. 66 Nothing.
49 """ 67 """
50 # Ensure the path ends in trailing slash. 68 # Ensure the path ends in trailing slash.
51 path = path.rstrip("/\\") + "\\" 69 path = path.rstrip("/\\") + "\\"
52 for dir_path, dir_names, files in os.walk(path): 70 for dir_path, dir_names, files in os.walk(path):
53 for file in files: 71 for file in files:
54 read_path = os.path.join(dir_path, file) 72 read_path = os.path.join(dir_path, file)
73
74 # If the file path matches an exclude, don't include it.
75 if any(re.search(expr, read_path) is not None for expr in EXCLUDES):
76 continue
77
55 zip_based_dir = dir_path[len(path):] 78 zip_based_dir = dir_path[len(path):]
56 write_path = os.path.join(zip_based_dir, file) 79 write_path = os.path.join(zip_based_dir, file)
57 zip_file.write(read_path, write_path, zipfile.ZIP_DEFLATED) 80 zip_file.write(read_path, write_path, zipfile.ZIP_DEFLATED)
58 81
82 def AddVersionModifiedAddinFile(zip_file):
83 """Modifies the .AddIn file with the build version and adds to the zip.
84
85 The version number is obtained from the NativeClientAddIn.dll assembly which
86 is built during the build process.
87
88 Args:
89 zip_file: Already open zip file.
90 """
91 info = win32api.GetFileVersionInfo(ADDIN_ASSEMBLY, "\\")
92 ms = info['FileVersionMS']
93 ls = info['FileVersionLS']
94 version = "[%i.%i.%i.%i]" % (
95 win32api.HIWORD(ms), win32api.LOWORD(ms),
96 win32api.HIWORD(ls), win32api.LOWORD(ls))
97 print "\nNaCl VS Add-in Build version: %s\n" % (version)
98
99 metadata_filename = os.path.basename(ADDIN_METADATA)
100 modified_file = os.path.join(ASSEMBLY_DIRECTORY, metadata_filename)
101
102 # Copy the metadata file to new location and modify the version info.
103 with codecs.open(ADDIN_METADATA, 'r', encoding='utf-16') as source_file:
104 with codecs.open(modified_file, 'w', encoding='utf-16') as dest_file:
105 for line in source_file:
106 dest_file.write(line.replace("[REPLACE_ADDIN_VERSION]", version))
107
108 zip_file.write(modified_file, metadata_filename, zipfile.ZIP_DEFLATED)
109
59 110
60 def main(): 111 def main():
61 # Zip the package. 112 # Zip the package.
62 out_file = zipfile.ZipFile(OUTPUT_NAME, 'w') 113 out_file = zipfile.ZipFile(OUTPUT_NAME, 'w')
63 for source_dest in FILE_LIST: 114 for source_dest in FILE_LIST:
64 file_name = os.path.basename(source_dest[0]) 115 file_name = os.path.basename(source_dest[0])
65 dest = os.path.join(source_dest[1], file_name) 116 dest = os.path.join(source_dest[1], file_name)
66 out_file.write(source_dest[0], dest, zipfile.ZIP_DEFLATED) 117 out_file.write(source_dest[0], dest, zipfile.ZIP_DEFLATED)
67 AddFolderToZip(RESOURCE_DIRECTORY, out_file) 118 AddFolderToZip(RESOURCE_DIRECTORY, out_file)
119 AddVersionModifiedAddinFile(out_file)
68 out_file.close() 120 out_file.close()
69 121
70 122
71 if __name__ == '__main__': 123 if __name__ == '__main__':
72 main() 124 main()
OLDNEW
« no previous file with comments | « visual_studio/NativeClientVSAddIn/UnitTests/TestUtilities.cs ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698