Chromium Code Reviews| 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 |
| 14 import platform | 16 import platform |
| 15 import shutil | 17 import shutil |
| 16 | 18 |
| 19 NACL_PLATFORM_NAME = 'NaCl' | |
| 20 PEPPER_PLATFORM_NAME = 'PPAPI' | |
| 21 | |
| 22 DEFAULT_ADD_IN_DIRECTORY = os.path.expandvars( | |
| 23 '%USERPROFILE%\\My Documents\\Visual Studio 2010\\Addins') | |
| 24 | |
| 25 DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') | |
| 26 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 27 | |
| 17 def main(): | 28 def main(): |
| 18 if platform.system() != 'Windows': | 29 if platform.system() != 'Windows': |
| 19 raise Exception('Must install to Windows system') | 30 raise Exception('Must install to Windows system') |
| 20 | 31 |
| 21 # Ensure environment variables are set | 32 # Admin is needed to write to the default platform directory. |
| 33 if ctypes.windll.shell32.IsUserAnAdmin() != 1: | |
| 34 raise Exception("Not running as administrator. The install script needs " | |
| 35 + "write access to protected Visual Studio directories.") | |
| 36 | |
| 37 # Ensure environment variables are set. | |
| 22 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) | 38 nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) |
|
noelallen1
2012/07/27 00:17:41
This is somewhat dubious... Admin and normal user
tysand
2012/07/28 01:13:11
Good catch, but I've verified that running python
| |
| 23 chrome_path = os.getenv('CHROME_PATH', None) | 39 chrome_path = os.getenv('CHROME_PATH', None) |
| 24 if nacl_sdk_root is None: | 40 if nacl_sdk_root is None: |
| 25 raise Exception('Environment Variable NACL_SDK_ROOT is not set') | 41 raise Exception('Environment Variable NACL_SDK_ROOT is not set') |
| 26 if chrome_path is None: | 42 if chrome_path is None: |
| 27 raise Exception('Environment Variable CHROME_PATH is not set') | 43 raise Exception('Environment Variable CHROME_PATH is not set') |
| 28 | 44 |
| 29 # Copy the necessary files into place | 45 # Ensure add-in directory exists otherwise ask user for correct path. |
| 30 add_in_directory = os.path.expandvars( | 46 add_in_directory = DEFAULT_ADD_IN_DIRECTORY |
| 31 '%USERPROFILE%\My Documents\Visual Studio 2010\Addins') | 47 if not os.path.exists(add_in_directory): |
| 32 shutil.copy('./NativeClientVSAddIn.AddIn', add_in_directory) | 48 print "Could not find Visual Studio add-in directory:" |
| 33 shutil.copy('./NativeClientVSAddIn.dll', add_in_directory) | 49 print add_in_directory |
| 50 print "Please enter path: " | |
| 51 add_in_directory = raw_input().strip() | |
|
binji
2012/07/26 23:32:17
use command line args instead of raw_input
tysand
2012/07/28 01:13:11
Done.
| |
| 52 if not os.path.exists(add_in_directory): | |
| 53 raise Exception("Add-in directory did not exist") | |
| 54 | |
| 55 # Ensure MS Build directory exists otherwise ask user for correct path. | |
| 56 ms_build_directory = DEFAULT_MS_BUILD_DIRECTORY | |
| 57 if not os.path.exists(ms_build_directory): | |
| 58 print "Could not find MS Build directory:" | |
| 59 print ms_build_directory | |
| 60 print "Please enter path: " | |
| 61 ms_build_directory = raw_input().strip() | |
| 62 if not os.path.exists(ms_build_directory): | |
| 63 raise Exception("MS Build directory did not exist") | |
| 64 | |
| 65 platform_directory = os.path.join( | |
| 66 ms_build_directory, | |
| 67 'Microsoft.Cpp\\v4.0\\Platforms') | |
| 68 nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) | |
| 69 pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) | |
| 70 | |
| 71 # Remove existing installation. | |
| 72 if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): | |
| 73 print "Warning: Pre-existing add-in installation will be overwritten." | |
| 74 print "Continue? ((Yes))/((No))" | |
| 75 remove_answer = raw_input().strip() | |
| 76 | |
| 77 if remove_answer.lower() == "yes" or remove_answer.lower() == "y": | |
| 78 if os.path.exists(nacl_directory): | |
| 79 shutil.rmtree(nacl_directory) | |
| 80 if os.path.exists(pepper_directory): | |
| 81 shutil.rmtree(pepper_directory) | |
| 82 else: | |
| 83 raise Exception('User did not allow overwrite of existing install.') | |
| 84 | |
| 85 print "Installing..." | |
| 86 | |
| 87 # Copy the necessary files into place. | |
| 88 shutil.copy( | |
|
binji
2012/07/26 23:32:17
Make sure to clean up copied files if an exception
tysand
2012/07/28 01:13:11
Done.
| |
| 89 os.path.join(SCRIPT_DIR, 'NativeClientVSAddIn.AddIn'), | |
| 90 add_in_directory) | |
| 91 shutil.copy( | |
| 92 os.path.join(SCRIPT_DIR, 'NativeClientVSAddIn.dll'), | |
| 93 add_in_directory) | |
| 94 print "Add-in installed." | |
| 95 | |
| 96 shutil.copytree(os.path.join(SCRIPT_DIR, 'NaCl'), nacl_directory) | |
| 97 print "NaCl platform installed." | |
| 98 | |
| 99 # Ask user before installing PPAPI template. | |
| 100 print "\n" | |
| 101 print "Set up configuration to enable Pepper development with Visual Studio?" | |
| 102 print ("((Yes)) - I want to create and copy relevant files into a" | |
| 103 + " Pepper subdirectory") | |
| 104 print "((No)) - I am not interested or will set up the configuration later" | |
| 105 ppapi_answer = raw_input().strip() | |
| 106 if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y": | |
| 107 create_ppapi_platform.CreatePPAPI(ms_build_directory) | |
| 108 print "PPAPI platform installed." | |
| 109 else: | |
| 110 print "Not installing PPAPI platform." | |
| 111 | |
| 112 print "\nInstallation complete!\n" | |
| 34 | 113 |
| 35 if __name__ == '__main__': | 114 if __name__ == '__main__': |
| 36 main() | 115 main() |
| OLD | NEW |