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

Unified Diff: visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py

Issue 10797040: PPAPI Patching System and Unit Tests (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Finalized PPAPI settings Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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..4662a381cec0e1cfd97eabe5ee7207cec7590015
--- /dev/null
+++ b/visual_studio/NativeClientVSAddIn/InstallerResources/create_ppapi_platform.py
@@ -0,0 +1,181 @@
+#!/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 pdb
binji 2012/07/24 22:13:08 remove debugging code
tysand 2012/07/24 23:19:49 Done.
+import os
+import shutil
+import string
+import xml_patch
+import xml.etree.ElementTree
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+
+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 PrependCopyright(source_file_name, dest_file_name):
+ """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.
+ """
+ with open(source_file_name, 'r') as source_file:
+ 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
+
+ with open(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 open(dest_file_name, 'w') as changed:
+ changed.writelines(copyright_notice + chrome_notice + xml_data)
+
+
+def CreateTemplateFile(source, patch, dest):
+ """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.PatchXML(source_xml, patch_xml)
+
+ if not os.path.exists(os.path.dirname(dest)):
+ os.makedirs(os.path.dirname(dest))
+
+ FixAttributesNamespace(modified_xml)
+ default_namespace = GetDefaultNamespace(modified_xml)
+ modified_xml.write(dest, default_namespace=default_namespace)
+ PrependCopyright(source, dest)
+
+
+def GetDefaultNamespace(tree):
+ # Returns the uri (namespace identifier) of the root element.
+ tag = tree.getroot().tag
+ if tag[:1] == "{":
binji 2012/07/24 22:13:08 nice trick, tag[:1] is the same as tag[0] but it w
tysand 2012/07/24 23:19:49 Changed this to tag.startswith("{") following your
+ uri, rest = tag[1:].rsplit("}", 1)
+ return uri
+ else:
+ return None
+
+
+def FixAttributesNamespace(tree):
+ # ElementTree's implementation seems to be broken in that attributes
+ # do not inherit the default namespace of their node or parent nodes.
+ # This causes issues with ElementTree.write() when using a default namespace.
+ # Since the attributes do not have a namespace, the code that collects a
+ # mapping between local names and qualified names (with a namespace) breaks.
+ # The work-around is to give all attributes the default namespace.
+ default_namespace = GetDefaultNamespace(tree)
+ for elem in tree.getroot().getiterator():
+ new_attrib = dict()
+ for key, value in elem.attrib.items():
+ # If the attribute does not have a namespace yet then give it one.
+ if key[:1] != "{":
+ new_key = "{%s}%s" % (default_namespace, key)
+ new_attrib[new_key] = value
+ else:
+ new_attrib[key] = value
+ elem.attrib = new_attrib
+
+
+def main():
+ install_dir = os.path.expandvars(
+ '%ProgramFiles(x86)%\\MSBuild\\Microsoft.Cpp\\v4.0\\Platforms')
+
+ # Note 1033 is code for the english language.
+ ui_xml_dir = os.path.expandvars(
+ '%ProgramFiles(x86)%\\MSBuild\\Microsoft.Cpp\\v4.0\\1033')
+
+ win32_dir = os.path.join(install_dir, 'Win32')
+ ppapi_dir = os.path.join(install_dir, 'PPAPI')
+ patch_dir = os.path.join(SCRIPT_DIR, 'PPAPI_Patch')
+
+ if not os.path.exists(win32_dir):
+ raise Exception('Win32 platform is not installed on this machine!')
+
+ for template_creation in PLATFORM_FILES:
+ CreateTemplateFile(
+ 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:
+ CreateTemplateFile(
+ 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:
+ copy_from = os.path.join(patch_dir, file_name)
+ copy_to = os.path.join(ppapi_dir, file_name)
+ if not os.path.exists(os.path.dirname(copy_to)):
+ os.makedirs(os.path.dirname(copy_to))
+ shutil.copyfile(copy_from, copy_to)
+
+ 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()

Powered by Google App Engine
This is Rietveld 408576698