Index: visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py |
diff --git a/visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py b/visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f1a6210b9c168f7366efb0d53e9073b7b7754c3 |
--- /dev/null |
+++ b/visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py |
@@ -0,0 +1,139 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+""" This script creates the PPAPI project settings template. |
+ |
+For copyright reasons, we should not directly distribute the PPAPI template |
+because it is nearly a clone of the Win32 template which is Copyrighted. |
+Instead, this script copies the existing Win32 template from the user's system |
+and intelligently modifies the copy to be the PPAPI template. |
+""" |
+ |
+import os |
+import shutil |
+import string |
+import xml_patch |
+import xml.etree.ElementTree |
+ |
+PLATFORM_FILES = [ |
+ ('Microsoft.Cpp.Win32.default.props', |
+ 'Microsoft.Cpp.[platform].default.props.patch', |
+ 'Microsoft.Cpp.PPAPI.default.props'), |
+ ('Microsoft.Cpp.Win32.props', |
+ 'Microsoft.Cpp.[platform].props.patch', |
+ 'Microsoft.Cpp.PPAPI.props'), |
+ ('Microsoft.Cpp.Win32.targets', |
+ 'Microsoft.Cpp.[platform].targets.patch', |
+ 'Microsoft.Cpp.PPAPI.targets'), |
+ ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.props', |
+ 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.props.patch', |
+ 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.props'), |
+ ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.targets', |
+ 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.targets.patch', |
+ 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.targets')] |
+ |
+UI_FILES = [ |
+ ('general.xml', |
+ 'Props\\ppapi_general.xml.patch', |
+ 'Props\\ppapi_general.xml'), |
+ ('general_ps.xml', |
+ 'Props\\ppapi_general_ps.xml.patch', |
+ 'Props\\ppapi_general_ps.xml')] |
+ |
+COPY_FILES = [ |
+ 'ImportAfter\\PPAPI.override.props'] |
+ |
+def prepend_copyright(source_file_name, dest_file_name): |
noelallen1
2012/07/20 21:46:01
Style: FunctionName(...)
tysand
2012/07/24 21:24:15
Done.
|
+ """Adds the copyright notice from source file to the dest file. |
+ |
+ Since the patch_xml function does not read comments, the copyright is skipped |
+ during the initial copy. This function adds it back and also attaches a |
+ notice that the file was based on source_file_name and slightly modified. |
+ |
+ Args: |
+ source_file_name: The original Win32 file. |
+ dest_file_name: The existing PPAPI file. |
+ |
+ Returns: |
+ None. |
+ """ |
+ source_file = open(source_file_name, 'r') |
binji
2012/07/20 22:54:49
with open(...) as source_file:
...
tysand
2012/07/24 21:24:15
Done.
|
+ in_copyright = False |
+ copyright_notice = '' |
+ for line in source_file: |
+ if '<!--' in line: |
+ in_copyright = True |
+ if in_copyright: |
+ copyright_notice += line |
+ if '-->' in line: |
+ in_copyright = False |
+ break |
+ source_file.close() |
+ |
+ with file(dest_file_name, 'r') as original: |
+ xml_data = original.read() |
+ |
+ chrome_notice = ('<!-- This file has been copied and modified from %s during ' |
+ 'the installation process. -->\n\n' % (source_file_name)) |
+ |
+ with file(dest_file_name, 'w') as changed: |
+ changed.writelines(copyright_notice + chrome_notice + xml_data) |
+ |
noelallen1
2012/07/20 21:46:01
Style: Two blank lines between top-level definitio
tysand
2012/07/24 21:24:15
Done.
|
+def create_template_file(source, patch, dest): |
noelallen1
2012/07/20 21:46:01
CreateTemplateFile...
tysand
2012/07/24 21:24:15
Done.
|
+ """Creates a single PPAPI template file. |
+ |
+ Args: |
+ source: The path source file to create from. |
+ patch: The path to the patch file to apply. |
+ dest: The path to the file to create. |
+ Returns: |
+ None. |
+ """ |
+ source_xml = xml.etree.ElementTree.parse(source) |
+ patch_xml = xml.etree.ElementTree.parse(patch) |
+ modified_xml = xml_patch.patch_xml(source_xml, patch_xml) |
+ |
+ if not os.path.exists(os.path.dirname(dest)): |
+ os.makedirs(os.path.dirname(dest)) |
+ modified_xml.write(dest) |
+ |
+ prepend_copyright(source, dest) |
+ |
+def main(): |
+ install_dir = os.path.expandvars( |
+ '%ProgramFiles(x86)%\\MSBuild\\Microsoft.Cpp\\v4.0\\Platforms') |
+ ui_xml_dir = os.path.expandvars( |
+ '%ProgramFiles(x86)%\\MSBuild\\Microsoft.Cpp\\v4.0\\1033') |
noelallen1
2012/07/20 21:46:01
Do you know what this magic number is and can it c
tysand
2012/07/24 21:24:15
It's the code for the english language, I'm not su
|
+ win32_dir = os.path.join(install_dir, 'Win32') |
+ ppapi_dir = os.path.join(install_dir, 'PPAPI') |
+ patch_dir = 'PPAPI_Patch' |
binji
2012/07/20 22:54:49
better to use the script's directory than a relati
tysand
2012/07/24 21:24:15
Done.
|
+ |
+ if not os.path.exists(win32_dir): |
+ raise Exception('Win32 platform is not installed on this machine!') |
+ |
+ for template_creation in PLATFORM_FILES: |
+ create_template_file( |
+ os.path.join(win32_dir, template_creation[0]), |
+ os.path.join(patch_dir, template_creation[1]), |
+ os.path.join(ppapi_dir, template_creation[2])) |
+ |
+ for template_creation in UI_FILES: |
+ create_template_file( |
+ os.path.join(ui_xml_dir, template_creation[0]), |
+ os.path.join(patch_dir, template_creation[1]), |
+ os.path.join(ppapi_dir, template_creation[2])) |
+ |
+ for file_name in COPY_FILES: |
+ path = os.path.join(ppapi_dir, file_name) |
+ if not os.path.exists(os.path.dirname(path)): |
+ os.makedirs(os.path.dirname(path)) |
+ shutil.copy(file_name, ppapi_dir) |
binji
2012/07/20 22:54:49
use SCRIPT_DIR, not a relative path.
tysand
2012/07/24 21:24:15
Done.
|
+ |
+ shutil.copyfile( |
+ os.path.join(win32_dir, 'Microsoft.Build.CPPTasks.Win32.dll'), |
+ os.path.join(ppapi_dir, 'Microsoft.Build.CPPTasks.PPAPI.dll')) |
+ |
+if __name__ == '__main__': |
+ main() |