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 | 13 import create_ppapi_platform |
14 import ctypes | 14 import ctypes |
15 import os | 15 import os |
16 import optparse | 16 import optparse |
17 import platform | 17 import platform |
18 import shutil | 18 import shutil |
19 import sys | 19 import sys |
| 20 import subprocess |
| 21 import time |
20 | 22 |
21 NACL_PLATFORM_NAME = 'NaCl' | 23 NACL_PLATFORM_NAME = 'NaCl' |
22 PEPPER_PLATFORM_NAME = 'PPAPI' | 24 PEPPER_PLATFORM_NAME = 'PPAPI' |
23 | 25 |
24 DEFAULT_VS_USER_DIRECTORY = os.path.expandvars( | 26 DEFAULT_VS_USER_DIRECTORY = os.path.expandvars( |
25 '%USERPROFILE%\\My Documents\\Visual Studio 2010') | 27 '%USERPROFILE%\\My Documents\\Visual Studio 2010') |
26 | 28 |
27 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') | 29 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') |
28 | 30 |
29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 31 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
(...skipping 20 matching lines...) Expand all Loading... |
50 print 'Failed to remove non-existant file: %s' % (file_path) | 52 print 'Failed to remove non-existant file: %s' % (file_path) |
51 | 53 |
52 | 54 |
53 def Uninstall(nacl_directory, pepper_directory, addin_directory): | 55 def Uninstall(nacl_directory, pepper_directory, addin_directory): |
54 UninstallDirectory(nacl_directory) | 56 UninstallDirectory(nacl_directory) |
55 UninstallDirectory(pepper_directory) | 57 UninstallDirectory(pepper_directory) |
56 for file_name in ADDIN_FILES: | 58 for file_name in ADDIN_FILES: |
57 UninstallFile(os.path.join(addin_directory, file_name)) | 59 UninstallFile(os.path.join(addin_directory, file_name)) |
58 | 60 |
59 | 61 |
| 62 def CheckForRunningProgams(): |
| 63 tasklist = os.popen('tasklist.exe').readlines() |
| 64 tasklist = [l for l in tasklist if 'MSBuild' in l or 'devenv' in l] |
| 65 return tasklist |
| 66 |
| 67 |
| 68 def Ask(question): |
| 69 while True: |
| 70 print '\n' |
| 71 print question |
| 72 print "Continue? ((Yes))/((No))" |
| 73 answer = raw_input().strip().lower() |
| 74 if answer in ('y', 'yes'): |
| 75 return True |
| 76 if answer in ('n', 'no'): |
| 77 return False |
| 78 |
| 79 |
60 def main(): | 80 def main(): |
61 parser = optparse.OptionParser(usage='Usage: %prog [options]') | 81 parser = optparse.OptionParser(usage='Usage: %prog [options]') |
62 parser.add_option('-b', '--msbuild-path', dest='msbuild_path', | 82 parser.add_option('-b', '--msbuild-path', dest='msbuild_path', |
63 default=DEFAULT_MS_BUILD_DIRECTORY, metavar='PATH', | 83 default=DEFAULT_MS_BUILD_DIRECTORY, metavar='PATH', |
64 help='Provide the path to the MSBuild directory') | 84 help='Provide the path to the MSBuild directory') |
65 parser.add_option('-a', '--vsuser-path', dest='vsuser_path', | 85 parser.add_option('-a', '--vsuser-path', dest='vsuser_path', |
66 default=DEFAULT_VS_USER_DIRECTORY, metavar='PATH', | 86 default=DEFAULT_VS_USER_DIRECTORY, metavar='PATH', |
67 help='Provide the path to the Visual Studio user directory') | 87 help='Provide the path to the Visual Studio user directory') |
68 parser.add_option('-f', '--force', action="store_true", dest='overwrite', | 88 parser.add_option('-f', '--force', action="store_true", |
69 default=False, help='Force an overwrite of existing files') | 89 default=False, help='Force an overwrite of existing files') |
70 parser.add_option('-p', '--ppapi', action="store_true", dest='install_ppapi', | 90 parser.add_option('-p', '--ppapi', action="store_true", dest='install_ppapi', |
71 help='Install PPAPI template without asking.') | 91 help='Install PPAPI template without asking.') |
72 parser.add_option('-n', '--no-ppapi', action="store_false", | 92 parser.add_option('-n', '--no-ppapi', action="store_false", |
73 dest='install_ppapi', help='Do not install PPAPI template and do not ask') | 93 dest='install_ppapi', help='Do not install PPAPI template and do not ask') |
74 parser.add_option('-u', '--uninstall', action="store_true", | 94 parser.add_option('-u', '--uninstall', action="store_true", |
75 dest='uninstall', help='Remove the add-in.') | 95 dest='uninstall', help='Remove the add-in.') |
76 (options, args) = parser.parse_args() | 96 (options, args) = parser.parse_args() |
77 | 97 |
78 print "*************************************************" | 98 print "*************************************************" |
79 print "Native-Client Visual Studio 2010 Add-in Installer" | 99 print "Native-Client Visual Studio 2010 Add-in Installer" |
80 print "*************************************************\n" | 100 print "*************************************************\n" |
81 print "Please ensure Visual Studio and MSBuild are closed " \ | |
82 "during installation.\n" | |
83 | 101 |
84 if platform.system() != 'Windows': | 102 if platform.system() != 'Windows': |
85 raise InstallError('Must install to Windows system') | 103 raise InstallError('Must install to Windows system') |
86 | 104 |
| 105 if CheckForRunningProgams(): |
| 106 if not options.force: |
| 107 print "Visual Studio and MSBuild must be closed during installation" |
| 108 if not Ask("Kill all instances now?"): |
| 109 raise InstallError('Please close all Visual Studio or MSBuild ' |
| 110 'instances before installing') |
| 111 os.system("taskkill.exe /IM MSBuild.exe /f") |
| 112 os.system("taskkill.exe /IM devenv.exe") |
| 113 if CheckForRunningProgams(): |
| 114 for i in xrange(10): |
| 115 if not CheckForRunningProgams(): |
| 116 break |
| 117 time.sleep(1) |
| 118 if not CheckForRunningProgams(): |
| 119 break |
| 120 if i == 5: |
| 121 print "Trying taskkill with /f" |
| 122 os.system("taskkill.exe /IM devenv.exe /f") |
| 123 if CheckForRunningProgams(): |
| 124 raise InstallError('Failed to kill Visual Studio and MSBuild instances') |
| 125 |
87 if sys.version_info < (2, 6, 2): | 126 if sys.version_info < (2, 6, 2): |
88 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ | 127 print "\n\nWARNING: Only python version 2.6.2 or greater is supported. " \ |
89 "Current version is %s\n\n" % (sys.version_info[:3],) | 128 "Current version is %s\n\n" % (sys.version_info[:3],) |
90 | 129 |
91 # Admin is needed to write to the default platform directory. | 130 # Admin is needed to write to the default platform directory. |
92 if ctypes.windll.shell32.IsUserAnAdmin() != 1: | 131 if ctypes.windll.shell32.IsUserAnAdmin() != 1: |
93 raise InstallError("Not running as administrator. The install script needs " | 132 raise InstallError("Not running as administrator. The install script needs " |
94 "write access to protected Visual Studio directories.") | 133 "write access to protected Visual Studio directories.") |
95 | 134 |
96 # Ensure install directories exist. | 135 # Ensure install directories exist. |
97 if not os.path.exists(options.vsuser_path): | 136 if not os.path.exists(options.vsuser_path): |
98 raise InstallError("Could not find user Visual Studio directory: %s" % ( | 137 raise InstallError("Could not find user Visual Studio directory: %s" % ( |
99 options.vsuser_path)) | 138 options.vsuser_path)) |
100 if not os.path.exists(options.msbuild_path): | 139 if not os.path.exists(options.msbuild_path): |
101 raise InstallError("Could not find MS Build directory: %s" % ( | 140 raise InstallError("Could not find MS Build directory: %s" % ( |
102 options.msbuild_path)) | 141 options.msbuild_path)) |
103 | 142 |
104 addin_directory = os.path.join(options.vsuser_path, 'Addins') | 143 addin_directory = os.path.join(options.vsuser_path, 'Addins') |
105 platform_directory = os.path.join( | 144 platform_directory = os.path.join( |
106 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms') | 145 options.msbuild_path, 'Microsoft.Cpp\\v4.0\\Platforms') |
107 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) | 146 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) |
108 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) | 147 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) |
109 | 148 |
110 # If uninstalling then redirect to uninstall program. | 149 # If uninstalling then redirect to uninstall program. |
111 if options.uninstall: | 150 if options.uninstall: |
112 Uninstall(nacl_directory, pepper_directory, addin_directory) | 151 Uninstall(nacl_directory, pepper_directory, addin_directory) |
113 print "\nUninstall complete!\n" | 152 print "\nUninstall complete!\n" |
114 exit(0) | 153 sys.exit(0) |
115 | 154 |
116 if not os.path.exists(platform_directory): | 155 if not os.path.exists(platform_directory): |
117 raise InstallError("Could not find path: %s" % platform_directory) | 156 raise InstallError("Could not find path: %s" % platform_directory) |
118 if not os.path.exists(addin_directory): | 157 if not os.path.exists(addin_directory): |
119 os.mkdir(addin_directory) | 158 os.mkdir(addin_directory) |
120 | 159 |
121 # Ensure environment variables are set. | 160 # Ensure environment variables are set. |
122 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) | 161 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) |
123 chrome_path = os.getenv('CHROME_PATH', None) | 162 chrome_path = os.getenv('CHROME_PATH', None) |
124 if nacl_sdk_root is None: | 163 if nacl_sdk_root is None: |
125 raise InstallError('Environment Variable NACL_SDK_ROOT is not set') | 164 raise InstallError('Environment Variable NACL_SDK_ROOT is not set') |
126 if chrome_path is None: | 165 if chrome_path is None: |
127 raise InstallError('Environment Variable CHROME_PATH is not set') | 166 raise InstallError('Environment Variable CHROME_PATH is not set') |
128 | 167 |
| 168 |
129 # Remove existing installation. | 169 # Remove existing installation. |
130 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): | 170 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): |
131 # If not forced then ask user permission. | 171 # If not forced then ask user permission. |
132 if not options.overwrite: | 172 if not options.force: |
133 print "\nWarning: Pre-existing add-in installation will be overwritten." | 173 if not Ask("Warning: Pre-existing add-in installation " |
134 print "Continue? ((Yes))/((No))" | 174 "will be overwritten.") |
135 remove_answer = raw_input().strip() | |
136 if not (remove_answer.lower() == "yes" or remove_answer.lower() == "y"): | |
137 raise InstallError('User did not allow overwrite of existing install.') | 175 raise InstallError('User did not allow overwrite of existing install.') |
138 print "Removing existing install..." | 176 print "Removing existing install..." |
139 Uninstall(nacl_directory, pepper_directory, addin_directory) | 177 Uninstall(nacl_directory, pepper_directory, addin_directory) |
140 | 178 |
| 179 |
141 # Ask user before installing PPAPI template. | 180 # Ask user before installing PPAPI template. |
142 if options.install_ppapi is None: | 181 if options.install_ppapi is None: |
143 print "\n" | 182 ppapi_answer = Ask("Set up configuration to enable Pepper development " \ |
144 print "Set up configuration to enable Pepper development " \ | 183 "with Visual Studio?\n" \ |
145 "with Visual Studio?" | 184 "((Yes)) - I want to create and copy relevant files into a " \ |
146 print "((Yes)) - I want to create and copy relevant files into a " \ | 185 "Pepper subdirectory\n" \ |
147 "Pepper subdirectory" | 186 "((No)) - I am not interested or will set up the configuration later") |
148 print "((No)) - I am not interested or will set up the configuration later" | 187 if ppapi_answer: |
149 ppapi_answer = raw_input().strip() | |
150 if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y": | |
151 options.install_ppapi = True | 188 options.install_ppapi = True |
152 print "Confirmed installer will include PPAPI platform." | 189 print "Confirmed installer will include PPAPI platform." |
153 else: | 190 else: |
154 options.install_ppapi = False | 191 options.install_ppapi = False |
155 print "Will not install PPAPI platform during installation." | 192 print "Will not install PPAPI platform during installation." |
156 | 193 |
157 print "\nBegin installing components..." | 194 print "\nBegin installing components..." |
158 | 195 |
159 try: | 196 try: |
160 # Copy the necessary files into place. | 197 # Copy the necessary files into place. |
(...skipping 23 matching lines...) Expand all Loading... |
184 except shutil.Error as e: | 221 except shutil.Error as e: |
185 print "Error while copying file. Please ensure file is not in use." | 222 print "Error while copying file. Please ensure file is not in use." |
186 print e | 223 print e |
187 except WindowsError as e: | 224 except WindowsError as e: |
188 if e.winerror == 5: | 225 if e.winerror == 5: |
189 print "Access denied error. Please ensure Visual Studio and MSBuild" | 226 print "Access denied error. Please ensure Visual Studio and MSBuild" |
190 print "processes are closed." | 227 print "processes are closed." |
191 else: | 228 else: |
192 raise | 229 raise |
193 | 230 |
OLD | NEW |