/// <summary> /// Constructs the WebServer, starts the web server process. /// </summary> /// <param name="outputWindowPane">Existing output pane to send web server output to.</param> /// <param name="properties">PropertyManager that is set to a valid project/platform.</param> public WebServer(OutputWindowPane outputWindowPane, PropertyManager properties) { if (outputWindowPane == null) { throw new ArgumentNullException("outputWindowPane"); } if (properties == null) { throw new ArgumentNullException("properties"); } webServerOutputPane_ = outputWindowPane; // Read port from properties, if invalid port then set to default value. int webServerPort; if (!int.TryParse(properties.WebServerPort, out webServerPort)) { webServerPort = DefaultWebServerPort; } string webServerExecutable = "python.exe"; string httpd = Path.Combine(properties.SDKRootDirectory, "examples", "httpd.py"); if (!File.Exists(httpd)) httpd = Path.Combine(properties.SDKRootDirectory, "tools", "httpd.py"); string webServerArguments = httpd + " --no_dir_check " + webServerPort; webServerOutputPane_.Clear(); webServerOutputPane_.OutputString(Strings.WebServerStartMessage + "\n"); webServerOutputPane_.Activate(); // Start the web server process. try { webServer_ = new System.Diagnostics.Process(); webServer_.StartInfo.CreateNoWindow = true; webServer_.StartInfo.UseShellExecute = false; webServer_.StartInfo.RedirectStandardOutput = true; webServer_.StartInfo.RedirectStandardError = true; webServer_.StartInfo.FileName = webServerExecutable; webServer_.StartInfo.Arguments = webServerArguments; webServer_.StartInfo.WorkingDirectory = properties.ProjectDirectory; webServer_.OutputDataReceived += WebServerMessageReceive; webServer_.ErrorDataReceived += WebServerMessageReceive; webServer_.Start(); webServer_.BeginOutputReadLine(); webServer_.BeginErrorReadLine(); } catch (Exception e) { webServerOutputPane_.OutputString(Strings.WebServerStartFail + "\n"); webServerOutputPane_.OutputString("Exception: " + e.Message + "\n"); } }
/// <summary> /// Called when Visual Studio starts a debugging session. /// Here we kick off the debugger and web server if appropriate. /// </summary> /// <param name="reason">Indicates how we are entering run mode (breakpoint or launch).</param> private void DebuggerOnEnterRunMode(dbgEventReason reason) { // If we are starting debugging (not re-entering from a breakpoint) // then load project settings and start the debugger-helper. if (reason == dbgEventReason.dbgEventReasonLaunchProgram) { PropertyManager properties = new PropertyManager(); properties.SetTargetToActive(dte_); if (properties.PlatformType == PropertyManager.ProjectPlatformType.NaCl) { debugger_ = new PluginDebuggerGDB(dte_, properties); webServer_ = new WebServer(webServerOutputPane_, properties); } else if (properties.PlatformType == PropertyManager.ProjectPlatformType.Pepper) { debugger_ = new PluginDebuggerVS(dte_, properties); webServer_ = new WebServer(webServerOutputPane_, properties); } } }
/// <summary> /// Goes through all projects in the solution and updates their properties with necessary /// modifications if they are NaCl or Pepper configurations. We add the version information /// here so that the version is stored directly in the project file. The call to /// PerformPropertyFixes() performs a work around on the property pages to force Visual Studio /// to save some specific properties into the project file to get around issue 140162. /// </summary> private void PerformPropertyModifications() { string naclAddInVersion = GetAddInMajorVersion().ToString(); var configs = Utility.GetPlatformVCConfigurations(dte_, Strings.PepperPlatformName); configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaCl64PlatformName)); configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.NaCl32PlatformName)); configs.AddRange(Utility.GetPlatformVCConfigurations(dte_, Strings.PNaClPlatformName)); var properties = new PropertyManager(); foreach (VCConfiguration config in configs) { properties.SetTarget(config); IVCRulePropertyStorage debugger = config.Rules.Item("WindowsLocalDebugger"); string executable = debugger.GetUnevaluatedPropertyValue("LocalDebuggerCommand"); // Perform project modifications of the NaClAddInVersion in the project file // is out of date, or if the WindowsLocalDebugger contains CHROME_PATH. The // later can happen if the developer deletes the .user file. if (executable.Contains("$(CHROME_PATH)") || properties.NaClAddInVersion != naclAddInVersion) { Debug.WriteLine("Modifying Config: " + config.Name); // Set the NaCl add-in version so that it is stored in the project file. properties.SetProperty("ConfigurationGeneral", "NaClAddInVersion", naclAddInVersion); // Expand the CHROME_PATH variable to its full path. string expandedChrome = properties.GetProperty( "WindowsLocalDebugger", "LocalDebuggerCommand"); properties.SetProperty("WindowsLocalDebugger", "LocalDebuggerCommand", expandedChrome); // Change the library includes to have the appropriate extension. string libs = properties.GetProperty("Link", "AdditionalDependencies"); if (properties.PlatformType == PropertyManager.ProjectPlatformType.NaCl) { libs = libs.Replace(".lib", string.Empty); } else if (properties.PlatformType == PropertyManager.ProjectPlatformType.Pepper) { string[] libsList = libs.Split(';'); libs = string.Empty; foreach (string lib in libsList) { string baseLibName = lib.Replace(".lib", string.Empty); if (!string.IsNullOrWhiteSpace(lib)) { libs = string.Concat(libs, baseLibName, ".lib;"); } } } properties.SetProperty("Link", "AdditionalDependencies", libs); } } }
/// <summary> /// Constructs the PluginDebuggerHelper. /// </summary> /// <param name="dte">Automation object from Visual Studio.</param> /// <param name="properties">PropertyManager pointing to a valid project/platform.</param> public PluginDebuggerVS(DTE2 dte, PropertyManager properties) : base(dte, properties) { pluginAssembly_ = properties.PluginAssembly; PluginFoundEvent += new EventHandler<PluginFoundEventArgs>(Attach); }
public void SetTargetTest() { string expectedSDKRootDir = Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable); Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not set!"); expectedSDKRootDir = expectedSDKRootDir.TrimEnd(new char[] { '/', '\\' }); PropertyManager target = new PropertyManager(); dte_.Solution.Open(naclSolution); Project naclProject = dte_.Solution.Projects.Item(TestUtilities.NaClProjectUniqueName); Project notNacl = dte_.Solution.Projects.Item(TestUtilities.NotNaClProjectUniqueName); // Invalid project. target.SetTarget(notNacl, Strings.PepperPlatformName, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.Other, target.PlatformType, "SetTarget should not succeed with non-nacl/pepper project."); // Try valid project with different platforms. target.SetTarget(naclProject, Strings.NaCl64PlatformName, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTarget did not succeed with NaCl64 platform on valid project."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root incorrect."); target.SetTarget(naclProject, Strings.NaClARMPlatformName, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTarget did not succeed with NaClARM platform on valid project."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root incorrect."); target.SetTarget(naclProject, Strings.PNaClPlatformName, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTarget did not succeed with nacl platform on valid project."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root incorrect."); target.SetTarget(naclProject, Strings.PepperPlatformName, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.Pepper, target.PlatformType, "SetTarget did not succeed with pepper platform on valid project."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root incorrect."); target.SetTarget(naclProject, "Win32", "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.Other, target.PlatformType, "SetTarget did not set 'other' platform on when Win32 platform of valid project."); // Setting the start-up project to a non-cpp project should make loading fail. object[] badStartupProj = { TestUtilities.NotNaClProjectUniqueName }; dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; target.SetTargetToActive(dte_); Assert.AreEqual( PropertyManager.ProjectPlatformType.Other, target.PlatformType, "SetTargetToActive should not succeed with non-nacl/pepper project."); // Setting the start-up project to correct C++ project, but also setting the platform // to non-nacl/pepper should make loading fail. object[] startupProj = { TestUtilities.NaClProjectUniqueName }; dte_.Solution.SolutionBuild.StartupProjects = startupProj; TestUtilities.SetSolutionConfiguration(dte_, TestUtilities.NaClProjectUniqueName, "Debug", "Win32"); target.SetTargetToActive(dte_); Assert.AreEqual( PropertyManager.ProjectPlatformType.Other, target.PlatformType, "SetTargetToActive should not succeed with Win32 platform."); // Now setting the platform to NaCl64 should make this succeed. TestUtilities.SetSolutionConfiguration(dte_, TestUtilities.NaClProjectUniqueName, "Debug", Strings.NaCl64PlatformName); target.SetTargetToActive(dte_); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTargetToActive should succeed with NaCl platform and valid project."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root incorrect."); }
public void SetPropertyTest() { string setTargetSolution = TestUtilities.CreateBlankValidNaClSolution( dte_, "PropertyManagerTestSetTarget", NativeClientVSAddIn.Strings.NaCl64PlatformName, NativeClientVSAddIn.Strings.NaCl64PlatformName, TestContext); // Set up the property manager to read the NaCl platform settings from BlankValidSolution. PropertyManager target = new PropertyManager(); dte_.Solution.Open(setTargetSolution); Project naclProject = dte_.Solution.Projects.Item(TestUtilities.NaClProjectUniqueName); foreach (string platform in NaClPlatformNames()) { target.SetTarget(naclProject, platform, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTarget did not succeed with nacl platform on valid project."); string newValue = "ThisIsNew"; target.SetProperty("ConfigurationGeneral", "VSNaClSDKRoot", newValue); Assert.AreEqual( newValue, target.GetProperty("ConfigurationGeneral", "VSNaClSDKRoot"), "SetProperty() did not set property VSNaClSDKRoot."); } }
public void GetPropertyTest() { string expectedSDKRootDir = Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable); Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not set!"); expectedSDKRootDir = expectedSDKRootDir.TrimEnd(new char[] { '/', '\\' }); // Set up the property manager to read the NaCl platform settings from BlankValidSolution. PropertyManager target = new PropertyManager(); dte_.Solution.Open(naclSolution); Project naclProject = dte_.Solution.Projects.Item(TestUtilities.NaClProjectUniqueName); string slnDir = Path.GetDirectoryName(naclSolution); string projectDir = Path.Combine( slnDir, Path.GetDirectoryName(TestUtilities.NaClProjectUniqueName)) + @"\"; foreach (string platform in NaClPlatformNames()) { target.SetTarget(naclProject, platform, "Debug"); Assert.AreEqual( PropertyManager.ProjectPlatformType.NaCl, target.PlatformType, "SetTarget did not succeed with nacl platform on valid project."); string outputDir = Path.Combine(projectDir, platform, "newlib", "Debug") + @"\"; string assembly = Path.Combine(outputDir, TestUtilities.BlankNaClProjectName); if (platform == "NaCl64") assembly += "_64.nexe"; else if (platform == "NaCl32") assembly += "_32.nexe"; else if (platform == "NaClARM") assembly += "_arm.nexe"; else if (platform == "PNaCl") assembly += ".pexe"; else Assert.Fail(); Assert.AreEqual(projectDir, target.ProjectDirectory, "ProjectDirectory."); Assert.AreEqual(outputDir, target.OutputDirectory, "OutputDirectory."); Assert.AreEqual(assembly, target.PluginAssembly, "PluginAssembly."); Assert.AreEqual(expectedSDKRootDir, target.SDKRootDirectory, "SDK Root."); Assert.AreEqual( @"newlib", target.GetProperty("ConfigurationGeneral", "ToolchainName"), "GetProperty() with ToolchainName incorrect."); } }