Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 namespace UnitTests | 5 namespace UnitTests |
| 6 { | 6 { |
| 7 using System; | 7 using System; |
| 8 using System.Collections.Generic; | 8 using System.Collections.Generic; |
| 9 using System.IO; | 9 using System.IO; |
| 10 using System.Linq; | 10 using System.Linq; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 /// <summary> | 45 /// <summary> |
| 46 /// This starts an instance of Visual Studio and get its DTE object. | 46 /// This starts an instance of Visual Studio and get its DTE object. |
| 47 /// </summary> | 47 /// </summary> |
| 48 /// <returns>DTE of the started instance.</returns> | 48 /// <returns>DTE of the started instance.</returns> |
| 49 public static DTE2 StartVisualStudioInstance() | 49 public static DTE2 StartVisualStudioInstance() |
| 50 { | 50 { |
| 51 // Set up filter to handle threading events and automatically retry calls | 51 // Set up filter to handle threading events and automatically retry calls |
| 52 // to dte which fail because dte is busy. | 52 // to dte which fail because dte is busy. |
| 53 ComMessageFilter.Register(); | 53 ComMessageFilter.Register(); |
| 54 | 54 |
| 55 Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); | 55 Type visualStudioType; |
| 56 if (IsVS2012()) | |
| 57 visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.11.0"); | |
| 58 else | |
| 59 visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); | |
| 60 | |
| 56 DTE2 visualStudio = Activator.CreateInstance(visualStudioType) as DTE2; | 61 DTE2 visualStudio = Activator.CreateInstance(visualStudioType) as DTE2; |
| 57 if (visualStudio == null) | 62 if (visualStudio == null) |
| 58 { | 63 { |
| 59 throw new Exception("Visual Studio failed to start"); | 64 throw new Exception("Visual Studio failed to start"); |
| 60 } | 65 } |
| 61 | 66 |
| 62 visualStudio.MainWindow.Visible = true; | 67 visualStudio.MainWindow.Visible = true; |
| 63 return visualStudio; | 68 return visualStudio; |
| 64 } | 69 } |
| 65 | 70 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 77 } | 82 } |
| 78 | 83 |
| 79 dte.Quit(); | 84 dte.Quit(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 // Stop the message filter. | 87 // Stop the message filter. |
| 83 ComMessageFilter.Revoke(); | 88 ComMessageFilter.Revoke(); |
| 84 } | 89 } |
| 85 | 90 |
| 86 /// <summary> | 91 /// <summary> |
| 92 /// Set the type of the project: Executable, DynamicLibrary, StaticLibrary | |
| 93 /// </summary> | |
| 94 static void Set2012Tools(Project project, String platformName) | |
| 95 { | |
| 96 VCConfiguration config; | |
| 97 IVCRulePropertyStorage rule; | |
| 98 | |
| 99 config = TestUtilities.GetVCConfiguration(project, "Debug", platformName ); | |
| 100 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 101 rule.SetPropertyValue("PlatformToolset", "v110"); | |
| 102 | |
| 103 config = TestUtilities.GetVCConfiguration(project, "Release", platformNa me); | |
| 104 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 105 rule.SetPropertyValue("PlatformToolset", "v110"); | |
| 106 } | |
| 107 | |
| 108 public static void SetProjectType(Project project, string projectType, strin g platformName) | |
| 109 { | |
| 110 VCConfiguration config; | |
| 111 IVCRulePropertyStorage rule; | |
| 112 | |
| 113 config = TestUtilities.GetVCConfiguration(project, "Debug", platformName ); | |
| 114 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 115 rule.SetPropertyValue("ConfigurationType", projectType); | |
| 116 | |
| 117 config = TestUtilities.GetVCConfiguration(project, "Release", platformNa me); | |
| 118 rule = config.Rules.Item("ConfigurationGeneral"); | |
| 119 rule.SetPropertyValue("ConfigurationType", projectType); | |
| 120 } | |
| 121 | |
| 122 public static bool IsVS2012() | |
| 123 { | |
| 124 #if VS2012 | |
|
binji
2013/06/07 18:49:19
can only be determined at compile time?
Sam Clegg
2013/06/10 22:38:12
Yup..
http://stackoverflow.com/questions/8517159/
| |
| 125 return true; | |
| 126 #else | |
| 127 return false; | |
| 128 #endif | |
| 129 } | |
| 130 | |
| 131 static void AddPlatform(Project project, String platform, String copyFrom) | |
| 132 { | |
| 133 project.ConfigurationManager.AddPlatform(platform, copyFrom, true); | |
| 134 //if (IsVS2012()) | |
|
binji
2013/06/07 18:49:19
unused?
Sam Clegg
2013/06/11 18:53:58
Done.
| |
| 135 // Set2012Tools(project, platform); | |
| 136 } | |
| 137 | |
| 138 /// <summary> | |
| 87 /// Creates a blank valid NaCl project with up-to-date settings. The path t o the new solution | 139 /// Creates a blank valid NaCl project with up-to-date settings. The path t o the new solution |
| 88 /// is returned. | 140 /// is returned. |
| 89 /// </summary> | 141 /// </summary> |
| 90 /// <param name="dte">Interface to an open Visual Studio instance to use.</p aram> | 142 /// <param name="dte">Interface to an open Visual Studio instance to use.</p aram> |
| 91 /// <param name="name">Name to give newly created solution.</param> | 143 /// <param name="name">Name to give newly created solution.</param> |
| 92 /// <param name="pepperCopyFrom">Platform name to copy existing settings fro m to pepper.</param> | 144 /// <param name="pepperCopyFrom">Platform name to copy existing settings fro m to pepper.</param> |
| 93 /// <param name="naclCopyFrom">Platform name to copy existing settings from to NaCl.</param> | 145 /// <param name="naclCopyFrom">Platform name to copy existing settings from to NaCl.</param> |
| 94 /// <param name="testContext">Test context used for finding deployment direc tory.</param> | 146 /// <param name="testContext">Test context used for finding deployment direc tory.</param> |
| 95 /// <returns>Path to the newly created solution.</returns> | 147 /// <returns>Path to the newly created solution.</returns> |
| 96 public static string CreateBlankValidNaClSolution( | 148 public static string CreateBlankValidNaClSolution( |
| 97 DTE2 dte, string name, string pepperCopyFrom, string naclCopyFrom, TestC ontext testContext) | 149 DTE2 dte, string name, string pepperCopyFrom, string naclCopyFrom, TestC ontext testContext) |
| 98 { | 150 { |
| 99 const string BlankSolution = "BlankValidSolution"; | 151 string blankSolution = "BlankValidSolution"; |
| 152 string srcSolution = blankSolution; | |
| 153 if (IsVS2012()) | |
| 154 srcSolution += "2012"; | |
| 100 string newSolutionDir = Path.Combine(testContext.DeploymentDirectory, name ); | 155 string newSolutionDir = Path.Combine(testContext.DeploymentDirectory, name ); |
| 101 string newSolution = Path.Combine(newSolutionDir, BlankSolution + ".sln"); | 156 string newSolution = Path.Combine(newSolutionDir, blankSolution + ".sln"); |
| 102 CopyDirectory(Path.Combine(testContext.DeploymentDirectory, BlankSolution) , newSolutionDir); | 157 CopyDirectory(Path.Combine(testContext.DeploymentDirectory, srcSolution), newSolutionDir); |
| 103 | 158 |
| 104 try | 159 try |
| 105 { | 160 { |
| 106 dte.Solution.Open(newSolution); | 161 dte.Solution.Open(newSolution); |
| 107 Project proj = dte.Solution.Projects.Item(NaClProjectUniqueName); | 162 Project proj = dte.Solution.Projects.Item(NaClProjectUniqueName); |
| 108 | 163 |
| 109 // Order matters if copying from the other Native Client type. | 164 // Order matters if copying from the other Native Client type. |
| 110 if (PropertyManager.IsNaClPlatform(pepperCopyFrom)) | 165 if (PropertyManager.IsNaClPlatform(pepperCopyFrom)) |
| 111 { | 166 { |
| 112 // create nacl platforms first | 167 // create nacl platforms first |
| 113 proj.ConfigurationManager.AddPlatform(Strings.NaCl64PlatformName, nacl CopyFrom, true); | 168 AddPlatform(proj, Strings.NaCl64PlatformName, naclCopyFrom); |
| 114 proj.ConfigurationManager.AddPlatform(Strings.NaCl32PlatformName, nacl CopyFrom, true); | 169 AddPlatform(proj, Strings.NaCl32PlatformName, naclCopyFrom); |
| 115 proj.ConfigurationManager.AddPlatform(Strings.NaClARMPlatformName, nac lCopyFrom, true); | 170 AddPlatform(proj, Strings.NaClARMPlatformName, naclCopyFrom); |
| 116 proj.ConfigurationManager.AddPlatform(Strings.PNaClPlatformName, naclC opyFrom, true); | 171 AddPlatform(proj, Strings.PNaClPlatformName, naclCopyFrom); |
| 117 proj.ConfigurationManager.AddPlatform(Strings.PepperPlatformName, pepp erCopyFrom, true); | 172 AddPlatform(proj, Strings.PepperPlatformName, pepperCopyFrom); |
| 118 } | 173 } |
| 119 else | 174 else |
| 120 { | 175 { |
| 121 // create pepper platform first | 176 // create pepper platform first |
| 122 proj.ConfigurationManager.AddPlatform(Strings.PepperPlatformName, pepp erCopyFrom, true); | 177 AddPlatform(proj, Strings.PepperPlatformName, pepperCopyFrom); |
| 123 proj.ConfigurationManager.AddPlatform(Strings.NaCl64PlatformName, nacl CopyFrom, true); | 178 AddPlatform(proj, Strings.NaCl64PlatformName, naclCopyFrom); |
| 124 proj.ConfigurationManager.AddPlatform(Strings.NaCl32PlatformName, nacl CopyFrom, true); | 179 AddPlatform(proj, Strings.NaCl32PlatformName, naclCopyFrom); |
| 125 proj.ConfigurationManager.AddPlatform(Strings.NaClARMPlatformName, nac lCopyFrom, true); | 180 AddPlatform(proj, Strings.NaClARMPlatformName, naclCopyFrom); |
| 126 proj.ConfigurationManager.AddPlatform(Strings.PNaClPlatformName, naclC opyFrom, true); | 181 AddPlatform(proj, Strings.PNaClPlatformName, naclCopyFrom); |
| 127 } | 182 } |
| 128 | 183 |
| 184 proj.Save(); | |
| 185 | |
| 129 // Set the active solution configuration to Debug|NaCl64. | 186 // Set the active solution configuration to Debug|NaCl64. |
| 130 SetSolutionConfiguration(dte, NaClProjectUniqueName, "Debug", Strings.Na Cl64PlatformName); | 187 SetSolutionConfiguration(dte, NaClProjectUniqueName, "Debug", Strings.Na Cl64PlatformName); |
| 131 | 188 |
| 132 proj.Save(); | |
| 133 dte.Solution.SaveAs(newSolution); | 189 dte.Solution.SaveAs(newSolution); |
| 190 | |
| 191 SetSolutionConfiguration(dte, NaClProjectUniqueName, "Release", Strings. NaCl64PlatformName); | |
| 192 | |
| 193 dte.Solution.SaveAs(newSolution); | |
| 194 | |
| 134 } | 195 } |
| 135 finally | 196 finally |
| 136 { | 197 { |
| 137 if (dte.Solution != null) | 198 if (dte.Solution != null) |
| 138 { | 199 { |
| 139 dte.Solution.Close(); | 200 dte.Solution.Close(); |
| 140 } | 201 } |
| 141 } | 202 } |
| 142 | 203 |
| 143 return newSolution; | 204 return newSolution; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 } | 525 } |
| 465 | 526 |
| 466 foreach (DirectoryInfo subdir in dir.GetDirectories()) | 527 foreach (DirectoryInfo subdir in dir.GetDirectories()) |
| 467 { | 528 { |
| 468 string path = Path.Combine(dest, subdir.Name); | 529 string path = Path.Combine(dest, subdir.Name); |
| 469 CopyDirectory(subdir.FullName, path); | 530 CopyDirectory(subdir.FullName, path); |
| 470 } | 531 } |
| 471 } | 532 } |
| 472 } | 533 } |
| 473 } | 534 } |
| OLD | NEW |