bool CompileCommandsUnavailable() { if (App() == null) { return(true); } Projects projects = App().Solution.Projects; foreach (Project p in projects) { VCProject project = p.Object as VCProject; if (project != null) { string config = ProjectUtility.ProjectActiveConfiguration(p); List <VCFile> ohs = ProjectUtility.GetOhFiles(p); ProjectUtility.FilterActiveFiles(ref ohs, config); if (ohs.Count != 0) { return(false); } } } return(true); }
// Returns the active configuration. public OptionsElement GetActiveConfiguration() { string activeConfiguration = ProjectUtility.GetActiveConfiguration(project); string activePlatform = ProjectUtility.GetActivePlatform(project); return(GetNewConfiguration(activeConfiguration, activePlatform)); }
/*=== construction ===*/ public ProjectOptionsForm() { InitializeComponent(); /*=== Grab the current project. ===*/ List <Project> projects = ProjectUtility.GetActiveProjectOnly(); Project project = projects[0]; this.Text = project.Name + " : " + this.Text; /*=== Populate the combo boxes. ===*/ List <string> configurations = ProjectUtility.GetConfigurations(project); List <string> platforms = ProjectUtility.GetPlatforms(project); foreach (string s in configurations) { comboConfigurations.Items.Add(s); } foreach (string s in platforms) { comboPlatforms.Items.Add(s); } comboConfigurations.SelectedItem = ProjectUtility.GetActiveConfiguration(project); comboPlatforms.SelectedItem = ProjectUtility.GetActivePlatform(project); /*=== Setup the property grid. ===*/ this.propertyGrid.Initialize(project); this.propertyGrid.RefreshGrid((string)comboConfigurations.SelectedItem, (string)comboPlatforms.SelectedItem); }
// Returns the path of the project options file for the input project. public static string GetProjectOptionsFilename(Project project) { if (project == null) { return(""); } return(ProjectUtility.GetFullProjectPath(project) + ProjectUtility.GetProjectName(project) + ProjectOptionsFile); }
private void ProjectSettingsStatus(object sender, EventArgs e) { if (bAddinLocked) { ProjectSettingsCommand.Enabled = false; return; } bool hasOhFiles = ProjectUtility.SolutionHasOhFiles(App().Solution); ProjectSettingsCommand.Enabled = hasOhFiles; }
private void FeatureManagerStatus(object sender, EventArgs e) { if (bAddinLocked) { FeatureManagerCommand.Enabled = false; return; } #if DEBUG bool hasOhFiles = ProjectUtility.SolutionHasOhFiles(App().Solution); FeatureManagerCommand.Enabled = hasOhFiles; #else FeatureManagerCommand.Enabled = false; #endif }
// // Command status callbacks // private void ButtonStatus(object sender, EventArgs e) { if (bAddinLocked) { DisableCompileButtons(); return; } bool hasOhFiles = ProjectUtility.SolutionHasOhFiles(App().Solution); if (IsCompiling() || hasOhFiles == false) { DisableCompileButtons(); } else { EnableCompileButtons(); } }
/*=== overrides ===*/ // Reload this project's options file. public override void Load() { if (project == null) { return; } string file = Paths.GetProjectOptionsFilename(project); ProjectOptionsSet os = null; // Load the project options. XmlUtility.LoadXml(file, ref os); if (os == null) { this.Options = new List <OptionsElement>(); } else { this.Options = os.Options; } string activeConfiguration = ProjectUtility.GetActiveConfiguration(project); string activePlatform = ProjectUtility.GetActivePlatform(project); if (GetConfiguration(activeConfiguration, activePlatform) == null) { OptionsElement oe = new OptionsElement(); oe.Configuration = activeConfiguration; oe.Platform = activePlatform; oe.Options.SetDefaults(); AddConfiguration(oe); // Save the new project options. Save(); } }
// Resolves a path with visual studio macros in it. public static string ResolveVisualStudioMacros(Project project, string path) { // Replace $(PlatformName) with the platform name. path = path.Replace("$(PlatformName)", ProjectUtility.GetActivePlatform(project)); // Replace $(ConfigurationName) with the configuration name. path = path.Replace("$(ConfigurationName)", ProjectUtility.GetActiveConfiguration(project)); // Replace $(ProjectName) with the project name. path = path.Replace("$(ProjectName)", ProjectUtility.GetProjectName(project)); // Replace $(SolutionName) with the solution name. path = path.Replace("$(SolutionName)", ProjectUtility.GetSolutionName()); // Replace $(ProjectDir) with the project directory. path = path.Replace("$(ProjectDir)", ProjectUtility.GetFullProjectPath(project)); // Replace $(SolutionDir) with the solution directory. path = path.Replace("$(SolutionDir)", ProjectUtility.GetFullSolutionPath()); //if we still have $() it should error really! return(path); }
void StartCompile(CompileMode mode) { // a compile is running already if (IsCompiling()) { //TODO: should halt compiling really return; //CurrentThread.Stop(); } if (mode.bIntercepted) { Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options; bool bExtendCommands = options.ExtendCommands.Value; if (!bExtendCommands) { return; } } if (IsVSCompiling()) { //cancel it App().ExecuteCommand("Build.Cancel", ""); } // activate the output pane... GetOutputPane().Clear(); ActivateOutputPane(); // ok, lets attempt to start compiling now. CurrentThread = null; PostEvent = ""; // no solution loaded DTE2 app = App(); Solution solution = app.Solution; if (solution == null) { return; } // first save all the open files - this is a global setting SaveOpenFiles(); List <Project> Projects; // find the selections we need (projects) if (mode.Selection == SelectionTypes.Solution) { Projects = ProjectUtility.GetSolutionProjects(); } else if (mode.Selection == SelectionTypes.Project) { Projects = ProjectUtility.GetActiveProjects(); } else // if (mode.Selection == SelectionTypes.ProjectOnly) { Projects = ProjectUtility.GetActiveProjectOnly(); } // // Mode Arguments // // clean : send it -clean // rebuild : send it -force // build : none... string ModeArguments = ""; if (mode.Action == CompileTypes.Rebuild) { ModeArguments += "-force"; } else if (mode.Action == CompileTypes.Clean) { ModeArguments += "-clean"; } //else if Debug || NoDebug || Build ... no additional needed //TODO: need the global options path string GlobalArguments = "-dependencies \"" + Paths.GetGlobalOptionsFilename() + "\""; //no projects to compile if (Projects.Count == 0) { return; } List <CommandSetting> CommandSettings = new List <CommandSetting>(); int numprojects = Projects.Count; for (int ip = 0; ip < numprojects; ip++) { Project project = Projects[ip]; string ActiveConfiguration = ProjectUtility.ProjectActiveConfiguration(project); List <VCFile> ohfiles = ProjectUtility.GetOhFiles(project); // does it contain active oh files? if not skip it. ProjectUtility.FilterActiveFiles(ref ohfiles, ActiveConfiguration); if (ohfiles.Count == 0) { continue; } // are the project settings set to enable opcpp? bool bProjectEnabled = true; if (!bProjectEnabled) { continue; } //3. do we have .doh files in the project? List <VCFile> dohfiles = ProjectUtility.GetDohFiles(project); ProjectUtility.FilterActiveFiles(ref dohfiles, ActiveConfiguration); // if (dohfiles.Count == 0) // continue; //fetch the project doh files from the global/project doh settings List <string> ProjectDohFiles = new List <string>(); // if(ProjectDohFiles.Count + dohfiles.Count == 0) // { // //print a message "Project has oh files but no dialect was found or specified" // continue; // } //now build the settings CommandSetting setting = new CommandSetting(); setting.Project = project; setting.WorkingDir = StringUtility.RLeft(project.FileName, "\\"); //build the oh files list from the arguments //build the doh files list from the arguments string ohfilestring = ""; for (int i = 0; i < ohfiles.Count; i++) { VCFile file = ohfiles[i]; ohfilestring += '"'; ohfilestring += file.FullPath; ohfilestring += '"'; if (i + 1 < ohfiles.Count) { ohfilestring += ','; } } string dohfilestring = ""; for (int i = 0; i < dohfiles.Count; i++) { VCFile file = dohfiles[i]; dohfilestring += '"'; dohfilestring += file.FullPath; dohfilestring += '"'; if (i + 1 < dohfiles.Count) { dohfilestring += ','; } } for (int i = 0; i < ProjectDohFiles.Count; i++) { dohfilestring += '"'; dohfilestring += ProjectDohFiles[i]; dohfilestring += '"'; if (i + 1 < ProjectDohFiles.Count) { dohfilestring += ','; } } string FileArguments = ""; if (ohfilestring.Length > 0) { FileArguments += " -oh " + ohfilestring; } if (dohfilestring.Length > 0) { FileArguments += " -doh " + dohfilestring; } // fetch the global + overloaded project arguments CommandLineInfo info = OptionsManager.GetCommandLineInfo(project); setting.ExePath = info.ExecutablePath; FileArguments += " -dependencies \"" + Paths.GetProjectOptionsFilename(project) + "\""; if (setting.ExePath == "") { LogCompile("Error: opCpp exe path is undefined, please define in global and/or project settings"); return; } string ProjectArguments = info.Arguments; string MacroArguments = FileArguments + " " + ProjectArguments + " " + ModeArguments + " " + GlobalArguments; if (opBeta.IsBeta) { MacroArguments += " -beta"; } setting.Arguments = Paths.ResolveVisualStudioMacros(project, MacroArguments); //verify the macros worked... Regex findmacros = new Regex("$\\(*.\\)"); Match result = findmacros.Match(setting.Arguments); if (result.Success) { string foundstring = setting.Arguments.Substring(result.Index, result.Length); LogCompile("Error: bad macro found in settings - " + foundstring); return; } CommandSettings.Add(setting); } //no commands to execute if (CommandSettings.Count == 0) { // CurrentMode = null; // FinishedCompile(false); return; } //execute commands CurrentMode = mode; CurrentThread = new opCppThread(CommandSettings); CurrentThread.OnReadLine = LogCompile; CurrentThread.OnEnd = FinishedCompile; CurrentThread.Start(); }
/*=== utility ===*/ public override void Running() { bool bErrored = false; foreach (opCpp2005.CommandSetting command in Commands) { try { Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options; // Print out the project that's currently compiling. if (!command.Arguments.Contains("-clean")) { string configuration = ProjectUtility.GetActiveConfiguration(command.Project); string platform = ProjectUtility.GetActivePlatform(command.Project); string message = "------ opC++ Build started: Project: " + command.Project.Name + ", Configuration: " + configuration + " " + platform + " ------"; OnReadLine(message); } if (options.OutputCommandline.Value) //TODO: hook into global options { string argstring = command.Arguments.Replace("-beta", ""); OnReadLine("---------------------------------------------"); OnReadLine("Working Directory = " + command.WorkingDir); OnReadLine("Path = " + command.ExePath); OnReadLine("Arguments = " + argstring); OnReadLine("::::::::::::::::::::::::::::::::::::::::::::;"); } //create a new process process = new System.Diagnostics.Process(); process.StartInfo.WorkingDirectory = command.WorkingDir; //this path is from the registry //NOTE: this should be integrated with the installer process.StartInfo.FileName = command.ExePath; process.StartInfo.Arguments = command.Arguments; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.ErrorDialog = false; //process.EnableRaisingEvents = true; //process. process.OutputDataReceived += new DataReceivedEventHandler(a_OutputDataReceived); process.Start(); //begin async output reading process.BeginOutputReadLine(); // while(!process.HasExited) // { // string value; // while( (value = process.StandardOutput.ReadLine()) != null ) // OnReadLine(value); // } //while (!process.HasExited) ; //wait only 10 seconds (temporary?) process.WaitForExit(1000 * 10); //the second call makes sure the async output is all finished before proceeding. process.WaitForExit(); if (process.HasExited) { //success } else { bErrored = true; //check status...this should be temporary! OnReadLine("Error: opC++ may not have finished in 10 seconds."); break; } if (process.ExitCode != 0) { bErrored = true; break; } } catch (Exception e) { OnReadLine("exception: " + e.Message + "\nStack Trace: " + e.StackTrace); bErrored = true; break; } } OnEnd(bErrored); }