Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """ This script creates the PPAPI project settings template. | |
| 7 | |
| 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. | |
| 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. | |
| 12 """ | |
| 13 | |
| 14 import os | |
| 15 import shutil | |
| 16 import string | |
| 17 import xml_patch | |
| 18 import xml.etree.ElementTree | |
| 19 | |
| 20 PLATFORM_FILES = [ | |
| 21 ('Microsoft.Cpp.Win32.default.props', | |
| 22 'Microsoft.Cpp.[platform].default.props.patch', | |
| 23 'Microsoft.Cpp.PPAPI.default.props'), | |
| 24 ('Microsoft.Cpp.Win32.props', | |
| 25 'Microsoft.Cpp.[platform].props.patch', | |
| 26 'Microsoft.Cpp.PPAPI.props'), | |
| 27 ('Microsoft.Cpp.Win32.targets', | |
| 28 'Microsoft.Cpp.[platform].targets.patch', | |
| 29 'Microsoft.Cpp.PPAPI.targets'), | |
| 30 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.props', | |
| 31 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.props.patch', | |
| 32 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.props'), | |
| 33 ('PlatformToolsets\\v100\\Microsoft.Cpp.Win32.v100.targets', | |
| 34 'PlatformToolsets\\v100\\Microsoft.Cpp.[platform].v100.targets.patch', | |
| 35 'PlatformToolsets\\v100\\Microsoft.Cpp.PPAPI.v100.targets')] | |
| 36 | |
| 37 UI_FILES = [ | |
| 38 ('general.xml', | |
| 39 'Props\\ppapi_general.xml.patch', | |
| 40 'Props\\ppapi_general.xml'), | |
| 41 ('general_ps.xml', | |
| 42 'Props\\ppapi_general_ps.xml.patch', | |
| 43 'Props\\ppapi_general_ps.xml')] | |
| 44 | |
| 45 COPY_FILES = [ | |
| 46 'ImportAfter\\PPAPI.override.props'] | |
| 47 | |
| 48 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.
| |
| 49 """Adds the copyright notice from source file to the dest file. | |
| 50 | |
| 51 Since the patch_xml function does not read comments, the copyright is skipped | |
| 52 during the initial copy. This function adds it back and also attaches a | |
| 53 notice that the file was based on source_file_name and slightly modified. | |
| 54 | |
| 55 Args: | |
| 56 source_file_name: The original Win32 file. | |
| 57 dest_file_name: The existing PPAPI file. | |
| 58 | |
| 59 Returns: | |
| 60 None. | |
| 61 """ | |
| 62 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.
| |
| 63 in_copyright = False | |
| 64 copyright_notice = '' | |
| 65 for line in source_file: | |
| 66 if '<!--' in line: | |
| 67 in_copyright = True | |
| 68 if in_copyright: | |
| 69 copyright_notice += line | |
| 70 if '-->' in line: | |
| 71 in_copyright = False | |
| 72 break | |
| 73 source_file.close() | |
| 74 | |
| 75 with file(dest_file_name, 'r') as original: | |
| 76 xml_data = original.read() | |
| 77 | |
| 78 chrome_notice = ('<!-- This file has been copied and modified from %s during ' | |
| 79 'the installation process. -->\n\n' % (source_file_name)) | |
| 80 | |
| 81 with file(dest_file_name, 'w') as changed: | |
| 82 changed.writelines(copyright_notice + chrome_notice + xml_data) | |
| 83 | |
|
noelallen1
2012/07/20 21:46:01
Style: Two blank lines between top-level definitio
tysand
2012/07/24 21:24:15
Done.
| |
| 84 def create_template_file(source, patch, dest): | |
|
noelallen1
2012/07/20 21:46:01
CreateTemplateFile...
tysand
2012/07/24 21:24:15
Done.
| |
| 85 """Creates a single PPAPI template file. | |
| 86 | |
| 87 Args: | |
| 88 source: The path source file to create from. | |
| 89 patch: The path to the patch file to apply. | |
| 90 dest: The path to the file to create. | |
| 91 Returns: | |
| 92 None. | |
| 93 """ | |
| 94 source_xml = xml.etree.ElementTree.parse(source) | |
| 95 patch_xml = xml.etree.ElementTree.parse(patch) | |
| 96 modified_xml = xml_patch.patch_xml(source_xml, patch_xml) | |
| 97 | |
| 98 if not os.path.exists(os.path.dirname(dest)): | |
| 99 os.makedirs(os.path.dirname(dest)) | |
| 100 modified_xml.write(dest) | |
| 101 | |
| 102 prepend_copyright(source, dest) | |
| 103 | |
| 104 def main(): | |
| 105 install_dir = os.path.expandvars( | |
| 106 '%ProgramFiles(x86)%\\MSBuild\\Microsoft.Cpp\\v4.0\\Platforms') | |
| 107 ui_xml_dir = os.path.expandvars( | |
| 108 '%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
| |
| 109 win32_dir = os.path.join(install_dir, 'Win32') | |
| 110 ppapi_dir = os.path.join(install_dir, 'PPAPI') | |
| 111 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.
| |
| 112 | |
| 113 if not os.path.exists(win32_dir): | |
| 114 raise Exception('Win32 platform is not installed on this machine!') | |
| 115 | |
| 116 for template_creation in PLATFORM_FILES: | |
| 117 create_template_file( | |
| 118 os.path.join(win32_dir, template_creation[0]), | |
| 119 os.path.join(patch_dir, template_creation[1]), | |
| 120 os.path.join(ppapi_dir, template_creation[2])) | |
| 121 | |
| 122 for template_creation in UI_FILES: | |
| 123 create_template_file( | |
| 124 os.path.join(ui_xml_dir, template_creation[0]), | |
| 125 os.path.join(patch_dir, template_creation[1]), | |
| 126 os.path.join(ppapi_dir, template_creation[2])) | |
| 127 | |
| 128 for file_name in COPY_FILES: | |
| 129 path = os.path.join(ppapi_dir, file_name) | |
| 130 if not os.path.exists(os.path.dirname(path)): | |
| 131 os.makedirs(os.path.dirname(path)) | |
| 132 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.
| |
| 133 | |
| 134 shutil.copyfile( | |
| 135 os.path.join(win32_dir, 'Microsoft.Build.CPPTasks.Win32.dll'), | |
| 136 os.path.join(ppapi_dir, 'Microsoft.Build.CPPTasks.PPAPI.dll')) | |
| 137 | |
| 138 if __name__ == '__main__': | |
| 139 main() | |
| OLD | NEW |