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 """Copies necessary add-in files into place to install the add-in. | 6 """Copies necessary add-in files into place to install the add-in. |
7 | 7 |
8 This script will copy the necessary files for the Visual Studio add-in | 8 This script will copy the necessary files for the Visual Studio add-in |
9 to where Visual Studio can find them. It assumes the current directory | 9 to where Visual Studio can find them. It assumes the current directory |
10 contains the necessary files to copy. | 10 contains the necessary files to copy. |
11 """ | 11 """ |
12 | 12 |
| 13 import create_ppapi_platform |
| 14 import ctypes |
13 import os | 15 import os |
| 16 import optparse |
14 import platform | 17 import platform |
15 import shutil | 18 import shutil |
| 19 import sys |
| 20 |
| 21 NACL_PLATFORM_NAME = 'NaCl' |
| 22 PEPPER_PLATFORM_NAME = 'PPAPI' |
| 23 |
| 24 DEFAULT_VS_USER_DIRECTORY = os.path.expandvars( |
| 25 '%USERPROFILE%\\My Documents\\Visual Studio 2010') |
| 26 |
| 27 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') |
| 28 |
| 29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 30 |
| 31 ADDIN_FILES = ['NativeClientVSAddIn.AddIn', 'NativeClientVSAddIn.dll'] |
| 32 |
| 33 def UninstallDirectory(directory): |
| 34 if os.path.exists(directory): |
| 35 shutil.rmtree(directory) |
| 36 print 'Removed: %s' % (directory) |
| 37 else: |
| 38 print 'Failed to remove non-existant directory: %s' % (directory) |
| 39 |
| 40 |
| 41 def UninstallFile(file_path): |
| 42 if os.path.exists(file_path): |
| 43 os.remove(file_path) |
| 44 print 'Removed: %s' % (file_path) |
| 45 else: |
| 46 print 'Failed to remove non-existant file: %s' % (file_path) |
| 47 |
| 48 |
| 49 def Uninstall(nacl_directory, pepper_directory, addin_directory): |
| 50 UninstallDirectory(nacl_directory) |
| 51 UninstallDirectory(pepper_directory) |
| 52 for file_name in ADDIN_FILES: |
| 53 UninstallFile(os.path.join(addin_directory, file_name)) |
| 54 |
16 | 55 |
17 def main(): | 56 def main(): |
| 57 parser = optparse.OptionParser(usage='Usage: %prog [options]') |
| 58 parser.add_option('-b', '--msbuild-path', dest='msbuild_path', |
| 59 default=DEFAULT_MS_BUILD_DIRECTORY, metavar='PATH', |
| 60 help='Provide the path to the MSBuild directory') |
| 61 parser.add_option('-a', '--vsuser-path', dest='vsuser_path', |
| 62 default=DEFAULT_VS_USER_DIRECTORY, metavar='PATH', |
| 63 help='Provide the path to the Visual Studio user directory') |
| 64 parser.add_option('-f', '--force', action="store_true", dest='overwrite', |
| 65 default=False, help='Force an overwrite of existing files') |
| 66 parser.add_option('-p', '--ppapi', action="store_true", dest='install_ppapi', |
| 67 help='Install PPAPI template without asking.') |
| 68 parser.add_option('-n', '--no-ppapi', action="store_false", |
| 69 dest='install_ppapi', help='Do not install PPAPI template and do not ask') |
| 70 parser.add_option('-u', '--uninstall', action="store_true", |
| 71 dest='uninstall', help='Remove the add-in.') |
| 72 (options, args) = parser.parse_args() |
| 73 |
18 if platform.system() != 'Windows': | 74 if platform.system() != 'Windows': |
19 raise Exception('Must install to Windows system') | 75 raise Exception('Must install to Windows system') |
20 | 76 |
21 # Ensure environment variables are set | 77 if sys.version_info < (2, 6, 2): |
| 78 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ |
| 79 "Current version is %s\n\n" % (sys.version_info[:3],) |
| 80 |
| 81 # Admin is needed to write to the default platform directory. |
| 82 if ctypes.windll.shell32.IsUserAnAdmin() != 1: |
| 83 raise Exception("Not running as administrator. The install script needs " |
| 84 "write access to protected Visual Studio directories.") |
| 85 |
| 86 # Ensure install directories exist. |
| 87 if not os.path.exists(options.vsuser_path): |
| 88 raise Exception("Could not find user Visual Studio directory: %s" % ( |
| 89 options.vsuser_path)) |
| 90 if not os.path.exists(options.msbuild_path): |
| 91 raise Exception("Could not find MS Build directory: %s" % ( |
| 92 options.msbuild_path)) |
| 93 |
| 94 addin_directory = os.path.join(options.vsuser_path, 'Addins') |
| 95 platform_directory = os.path.join( |
| 96 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms') |
| 97 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) |
| 98 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) |
| 99 |
| 100 # If uninstalling then redirect to uninstall program. |
| 101 if options.uninstall: |
| 102 Uninstall(nacl_directory, pepper_directory, addin_directory) |
| 103 print "\nUninstall complete!\n" |
| 104 exit(0) |
| 105 |
| 106 if not os.path.exists(platform_directory): |
| 107 raise Exception("Could not find path: %s" % platform_directory) |
| 108 if not os.path.exists(addin_directory): |
| 109 os.mkdir(addin_directory) |
| 110 |
| 111 # Ensure environment variables are set. |
22 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) | 112 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) |
23 chrome_path = os.getenv('CHROME_PATH', None) | 113 chrome_path = os.getenv('CHROME_PATH', None) |
24 if nacl_sdk_root is None: | 114 if nacl_sdk_root is None: |
25 raise Exception('Environment Variable NACL_SDK_ROOT is not set') | 115 raise Exception('Environment Variable NACL_SDK_ROOT is not set') |
26 if chrome_path is None: | 116 if chrome_path is None: |
27 raise Exception('Environment Variable CHROME_PATH is not set') | 117 raise Exception('Environment Variable CHROME_PATH is not set') |
28 | 118 |
29 # Copy the necessary files into place | 119 # Remove existing installation. |
30 add_in_directory = os.path.expandvars( | 120 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): |
31 '%USERPROFILE%\My Documents\Visual Studio 2010\Addins') | 121 # If not forced then ask user permission. |
32 shutil.copy('./NativeClientVSAddIn.AddIn', add_in_directory) | 122 if not options.overwrite: |
33 shutil.copy('./NativeClientVSAddIn.dll', add_in_directory) | 123 print "Warning: Pre-existing add-in installation will be overwritten." |
| 124 print "Continue? ((Yes))/((No))" |
| 125 remove_answer = raw_input().strip() |
| 126 if not (remove_answer.lower() == "yes" or remove_answer.lower() == "y"): |
| 127 raise Exception('User did not allow overwrite of existing install.') |
| 128 print "Removing existing install..." |
| 129 Uninstall(nacl_directory, pepper_directory, addin_directory) |
| 130 |
| 131 # Ask user before installing PPAPI template. |
| 132 if options.install_ppapi is None: |
| 133 print "\n" |
| 134 print "Set up configuration to enable Pepper development " \ |
| 135 "with Visual Studio?" |
| 136 print "((Yes)) - I want to create and copy relevant files into a " \ |
| 137 "Pepper subdirectory" |
| 138 print "((No)) - I am not interested or will set up the configuration later" |
| 139 ppapi_answer = raw_input().strip() |
| 140 if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y": |
| 141 options.install_ppapi = True |
| 142 else: |
| 143 options.install_ppapi = False |
| 144 print "Not installing PPAPI platform." |
| 145 |
| 146 print "Installing..." |
| 147 |
| 148 try: |
| 149 # Copy the necessary files into place. |
| 150 for file_name in ADDIN_FILES: |
| 151 shutil.copy(os.path.join(SCRIPT_DIR, file_name), addin_directory) |
| 152 print "Add-in installed." |
| 153 |
| 154 shutil.copytree(os.path.join(SCRIPT_DIR, 'NaCl'), nacl_directory) |
| 155 print "NaCl platform installed." |
| 156 |
| 157 if options.install_ppapi: |
| 158 create_ppapi_platform.CreatePPAPI(options.msbuild_path) |
| 159 print "PPAPI platform installed." |
| 160 except: |
| 161 print "\nException occured! Rolling back install...\n" |
| 162 Uninstall(nacl_directory, pepper_directory, addin_directory) |
| 163 raise |
| 164 else: |
| 165 print "\nInstallation complete!\n" |
34 | 166 |
35 if __name__ == '__main__': | 167 if __name__ == '__main__': |
36 main() | 168 main() |
OLD | NEW |