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 """ This script creates the PPAPI project settings template. | 6 """ This script creates the PPAPI project settings template. |
7 | 7 |
8 For copyright reasons, we should not directly distribute the PPAPI template | 8 For copyright reasons, we should not directly distribute the PPAPI template |
9 because it is nearly a clone of the Win32 template which is Copyrighted. | 9 because it is nearly a clone of the Win32 template which is Copyrighted. |
10 Instead, this script copies the existing Win32 template from the user's system | 10 Instead, this script copies the existing Win32 template from the user's system |
11 and intelligently modifies the copy to be the PPAPI template. | 11 and intelligently modifies the copy to be the PPAPI template. |
12 """ | 12 """ |
13 | 13 |
14 import os | 14 import os |
15 import optparse | 15 import optparse |
16 import shutil | 16 import shutil |
17 import string | 17 import string |
18 import xml_patch | 18 import xml_patch |
19 import third_party.etree.ElementTree as ElementTree | 19 import third_party.etree.ElementTree as ElementTree |
20 | 20 import sys |
21 | 21 |
22 PEPPER_PLATFORM_NAME = 'PPAPI' | 22 PEPPER_PLATFORM_NAME = 'PPAPI' |
23 | 23 |
24 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') | 24 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') |
25 | 25 |
26 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 26 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
27 | 27 |
28 PLATFORM_FILES = [ | 28 PLATFORM_FILES_2010 = [ |
29 ('Microsoft.Cpp.Win32.default.props', | 29 ('Microsoft.Cpp.Win32.default.props', |
30 'Microsoft.Cpp.[platform].default.props.patch', | 30 'Microsoft.Cpp.Win32.default.props.patch', |
31 'Microsoft.Cpp.PPAPI.default.props'), | 31 'Microsoft.Cpp.PPAPI.default.props'), |
32 ('Microsoft.Cpp.Win32.props', | 32 ('Microsoft.Cpp.Win32.props', |
33 'Microsoft.Cpp.[platform].props.patch', | 33 'Microsoft.Cpp.Win32.props.patch', |
34 'Microsoft.Cpp.PPAPI.props'), | 34 'Microsoft.Cpp.PPAPI.props'), |
35 ('Microsoft.Cpp.Win32.targets', | 35 ('Microsoft.Cpp.Win32.targets', |
36 'Microsoft.Cpp.[platform].targets.patch', | 36 'Microsoft.Cpp.Win32.targets.patch', |
37 'Microsoft.Cpp.PPAPI.targets'), | 37 'Microsoft.Cpp.PPAPI.targets'), |
38 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.props', | 38 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.props', |
39 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.props.patch', | 39 'PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.props.patch', |
40 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.props'), | 40 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.props'), |
41 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.targets', | 41 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.targets', |
42 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.targets.patch', | 42 'PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.targets.patch', |
43 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.targets')] | 43 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.targets')] |
44 | 44 |
45 PLATFORM_FILES_2012 = [ | |
46 ('Microsoft.Cpp.Win32.default.props', | |
47 'V110/Microsoft.Cpp.Win32.default.props.patch', | |
48 'Microsoft.Cpp.PPAPI.default.props'), | |
49 ('Microsoft.Cpp.Win32.targets', | |
50 'V110/Microsoft.Cpp.Win32.targets.patch', | |
51 'Microsoft.Cpp.PPAPI.targets'), | |
52 ('PlatformToolsets\\v110\\Microsoft.Cpp.Win32.v110.props', | |
53 'V110\\PlatformToolsets\\v110\\Microsoft.Cpp.Win32.v110.props.patch', | |
54 'PlatformToolsets\\v110\\Microsoft.Cpp.PPAPI.v110.props'), | |
55 ('PlatformToolsets\\v110\\Microsoft.Cpp.Win32.v110.targets', | |
56 'V110\\PlatformToolsets\\v110\\Microsoft.Cpp.Win32.v110.targets.patch', | |
57 'PlatformToolsets\\v110\\Microsoft.Cpp.PPAPI.v110.targets')] | |
58 | |
45 UI_FILES = [ | 59 UI_FILES = [ |
46 ('general.xml', | 60 ('general.xml', |
47 'Props\\ppapi_general.xml.patch', | 61 'Props\\ppapi_general.xml.patch', |
48 'Props\\ppapi_general.xml'), | 62 'Props\\ppapi_general.xml'), |
49 ('general_ps.xml', | 63 ('general_ps.xml', |
50 'Props\\ppapi_general_ps.xml.patch', | 64 'Props\\ppapi_general_ps.xml.patch', |
51 'Props\\ppapi_general_ps.xml')] | 65 'Props\\ppapi_general_ps.xml')] |
52 | 66 |
53 COPY_FILES = [ | 67 ADD_FILES = [ |
54 'ImportAfter\\PPAPI.override.props'] | 68 'ImportAfter\\PPAPI.override.props'] |
55 | 69 |
56 | 70 |
71 class Error(Exception): | |
72 pass | |
73 | |
74 | |
57 def PrependCopyright(source_file_name, dest_file_name): | 75 def PrependCopyright(source_file_name, dest_file_name): |
58 """Adds the copyright notice from source file to the dest file. | 76 """Adds the copyright notice from source file to the dest file. |
59 | 77 |
60 Since the patch_xml function does not read comments, the copyright is skipped | 78 Since the patch_xml function does not read comments, the copyright is skipped |
61 during the initial copy. This function adds it back and also attaches a | 79 during the initial copy. This function adds it back and also attaches a |
62 notice that the file was based on source_file_name and slightly modified. | 80 notice that the file was based on source_file_name and slightly modified. |
63 | 81 |
64 Args: | 82 Args: |
65 source_file_name: The original Win32 file. | 83 source_file_name: The original Win32 file. |
66 dest_file_name: The existing PPAPI file. | 84 dest_file_name: The existing PPAPI file. |
(...skipping 28 matching lines...) Expand all Loading... | |
95 | 113 |
96 Args: | 114 Args: |
97 source: The path source file to create from. | 115 source: The path source file to create from. |
98 patch: The path to the patch file to apply. | 116 patch: The path to the patch file to apply. |
99 dest: The path to the file to create. | 117 dest: The path to the file to create. |
100 Returns: | 118 Returns: |
101 None. | 119 None. |
102 """ | 120 """ |
103 source_xml = ElementTree.parse(source) | 121 source_xml = ElementTree.parse(source) |
104 patch_xml = ElementTree.parse(patch) | 122 patch_xml = ElementTree.parse(patch) |
105 modified_xml = xml_patch.PatchXML(source_xml, patch_xml) | 123 print "Patching: %s" % dest |
124 try: | |
125 modified_xml = xml_patch.PatchXML(source_xml, patch_xml) | |
126 except Exception as e: | |
127 raise Error("Error patching file: %s: %s" % (source, e)) | |
106 | 128 |
107 if not os.path.exists(os.path.dirname(dest)): | 129 if not os.path.exists(os.path.dirname(dest)): |
108 os.makedirs(os.path.dirname(dest)) | 130 os.makedirs(os.path.dirname(dest)) |
109 | 131 |
110 FixAttributesNamespace(modified_xml) | 132 FixAttributesNamespace(modified_xml) |
111 default_namespace = GetDefaultNamespace(modified_xml) | 133 default_namespace = GetDefaultNamespace(modified_xml) |
112 modified_xml.write(dest, default_namespace=default_namespace) | 134 modified_xml.write(dest, default_namespace=default_namespace) |
113 PrependCopyright(source, dest) | 135 PrependCopyright(source, dest) |
114 | 136 |
115 | 137 |
(...skipping 20 matching lines...) Expand all Loading... | |
136 for key, value in elem.attrib.items(): | 158 for key, value in elem.attrib.items(): |
137 # If the attribute does not have a namespace yet then give it one. | 159 # If the attribute does not have a namespace yet then give it one. |
138 if key[:1] != "{": | 160 if key[:1] != "{": |
139 new_key = "{%s}%s" % (default_namespace, key) | 161 new_key = "{%s}%s" % (default_namespace, key) |
140 new_attrib[new_key] = value | 162 new_attrib[new_key] = value |
141 else: | 163 else: |
142 new_attrib[key] = value | 164 new_attrib[key] = value |
143 elem.attrib = new_attrib | 165 elem.attrib = new_attrib |
144 | 166 |
145 | 167 |
146 def CreatePPAPI(msbuild_dir): | 168 def CreatePPAPIPlatform(install_dir): |
147 """Creates the PPAPI template. | 169 if not os.path.exists(install_dir): |
170 raise Error('install directory was not found: %s' % install_dir) | |
148 | 171 |
149 Args: | |
150 msbuild_dir: The path to the MSBuild installation. | |
151 | |
152 Returns: | |
153 Nothing. | |
154 | |
155 Raises: | |
156 Exception indicating Win32 platform was not found. | |
157 """ | |
158 if not os.path.exists(msbuild_dir): | |
159 raise Exception('MSBuild directory was not found!') | |
160 | |
161 install_dir = os.path.join(msbuild_dir, 'Microsoft.Cpp\\v4.0\\Platforms') | |
162 | 172 |
163 # Note 1033 is code for the english language. | 173 # Note 1033 is code for the english language. |
164 ui_xml_dir = os.path.join(msbuild_dir, 'Microsoft.Cpp\\v4.0\\1033') | 174 ui_xml_dir = os.path.join(os.path.dirname(install_dir), '1033') |
165 | 175 |
166 win32_dir = os.path.join(install_dir, 'Win32') | 176 win32_dir = os.path.join(install_dir, 'Win32') |
167 ppapi_dir = os.path.join(install_dir, PEPPER_PLATFORM_NAME) | 177 ppapi_dir = os.path.join(install_dir, PEPPER_PLATFORM_NAME) |
168 patch_dir = os.path.join(SCRIPT_DIR, 'PPAPI_Patch') | 178 patch_dir = os.path.join(SCRIPT_DIR, 'PPAPI_Patch') |
169 | 179 |
170 if not os.path.exists(win32_dir): | 180 if not os.path.exists(win32_dir): |
171 raise Exception('Win32 platform is not installed on this machine!') | 181 raise Error('Win32 MSBuild folder not found: %s' % win32_dir) |
binji
2013/05/25 00:02:55
s/folder/directory/
Sam Clegg
2013/05/29 04:58:33
Done.
| |
172 | 182 |
173 for template_creation in PLATFORM_FILES: | 183 print "Cloning Win32 platform from: %s" % win32_dir |
184 | |
185 for root, dirs, files in os.walk(win32_dir): | |
186 root = root.replace(win32_dir, '')[1:] | |
187 | |
188 if not os.path.exists(os.path.join(ppapi_dir, root)): | |
189 os.makedirs(os.path.join(ppapi_dir, root)) | |
190 | |
191 for filename in files: | |
192 src = os.path.join(win32_dir, root, filename) | |
193 dest = os.path.join(ppapi_dir, root, filename.replace('Win32', 'PPAPI')) | |
194 #print "duplicating: %s" % dest | |
binji
2013/05/25 00:02:55
remove
Sam Clegg
2013/05/29 04:58:33
Done.
| |
195 shutil.copyfile(src, dest) | |
196 | |
197 if 'V110' in install_dir: | |
198 platform_files = PLATFORM_FILES_2012 | |
199 else: | |
200 platform_files = PLATFORM_FILES_2010 | |
201 | |
202 for template_creation in platform_files: | |
174 CreateTemplateFile( | 203 CreateTemplateFile( |
175 os.path.join(win32_dir, template_creation[0]), | 204 os.path.join(win32_dir, template_creation[0]), |
176 os.path.join(patch_dir, template_creation[1]), | 205 os.path.join(patch_dir, template_creation[1]), |
177 os.path.join(ppapi_dir, template_creation[2])) | 206 os.path.join(ppapi_dir, template_creation[2])) |
178 | 207 |
179 for template_creation in UI_FILES: | 208 for template_creation in UI_FILES: |
180 CreateTemplateFile( | 209 CreateTemplateFile( |
181 os.path.join(ui_xml_dir, template_creation[0]), | 210 os.path.join(ui_xml_dir, template_creation[0]), |
182 os.path.join(patch_dir, template_creation[1]), | 211 os.path.join(patch_dir, template_creation[1]), |
183 os.path.join(ppapi_dir, template_creation[2])) | 212 os.path.join(ppapi_dir, template_creation[2])) |
184 | 213 |
185 for file_name in COPY_FILES: | 214 for file_name in ADD_FILES: |
186 copy_from = os.path.join(patch_dir, file_name) | 215 copy_from = os.path.join(patch_dir, file_name) |
187 copy_to = os.path.join(ppapi_dir, file_name) | 216 copy_to = os.path.join(ppapi_dir, file_name) |
188 if not os.path.exists(os.path.dirname(copy_to)): | 217 if not os.path.exists(os.path.dirname(copy_to)): |
189 os.makedirs(os.path.dirname(copy_to)) | 218 os.makedirs(os.path.dirname(copy_to)) |
190 shutil.copyfile(copy_from, copy_to) | 219 shutil.copyfile(copy_from, copy_to) |
191 | 220 |
192 shutil.copyfile( | 221 |
193 os.path.join(win32_dir, 'Microsoft.Build.CPPTasks.Win32.dll'), | 222 def CreatePPAPI(msbuild_dir): |
194 os.path.join(ppapi_dir, 'Microsoft.Build.CPPTasks.PPAPI.dll')) | 223 """Creates the PPAPI template. |
224 | |
225 Args: | |
226 msbuild_dir: The path to the MSBuild installation. | |
227 | |
228 Returns: | |
229 Nothing. | |
230 | |
231 Raises: | |
232 Error indicating Win32 platform was not found. | |
233 """ | |
234 | |
235 if not os.path.exists(msbuild_dir): | |
236 raise Error('MSBuild directory was not found: %s' % msbuild_dir) | |
237 | |
238 install_dir = os.path.join(msbuild_dir, 'Microsoft.Cpp\\v4.0\\Platforms') | |
binji
2013/05/25 00:02:55
vs 2012 has this directory too?
Sam Clegg
2013/05/29 04:58:33
Done.
| |
239 CreatePPAPIPlatform(install_dir) | |
240 | |
241 install_dir = os.path.join(msbuild_dir, | |
242 'Microsoft.Cpp\\v4.0\\V110\\Platforms') | |
243 if os.path.exists(install_dir): | |
244 CreatePPAPIPlatform(install_dir) | |
195 | 245 |
196 | 246 |
197 def main(): | 247 def main(args): |
198 parser = optparse.OptionParser(usage='Usage: %prog [options]') | 248 try: |
199 parser.add_option('-b', '--msbuild-path', dest='msbuild_path', | 249 parser = optparse.OptionParser(usage='Usage: %prog [options]') |
200 default=DEFAULT_MS_BUILD_DIRECTORY, | 250 parser.add_option('-b', '--msbuild-path', |
201 help='Provide the path to the MSBuild directory', metavar='PATH') | 251 default=DEFAULT_MS_BUILD_DIRECTORY, |
202 (options, args) = parser.parse_args() | 252 help='Provide the path to the MSBuild directory', metavar='PATH') |
203 CreatePPAPI(options.msbuild_path) | 253 options, args = parser.parse_args(args) |
254 CreatePPAPI(options.msbuild_path) | |
255 | |
256 except Error as e: | |
257 sys.stderr.write("error: %s\n" % e) | |
258 return 1 | |
259 | |
260 return 0 | |
204 | 261 |
205 if __name__ == '__main__': | 262 if __name__ == '__main__': |
206 main() | 263 sys.exit(main(sys.argv[1:])) |
OLD | NEW |