// This method returns the command line argument string. public static CommandLineInfo GetCommandLineInfo(Project p) { /*=== Read the options. ===*/ Options gOptions = GetGlobalOptions().GetGlobalConfiguration().Options; Options pOptions = GetProjectOptions(p).GetActiveConfiguration().Options; /*=== Use reflection to build the command line string. ===*/ string cmd = ""; FieldInfo[] oFields; Type oType = typeof(Options); char[] trimchars = { '"' }; // Get the fields for type 'Options'. oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance); /*=== Loop through the data members in the 'Options' object. ===*/ for (int i = 0; i < oFields.Length; i++) { /*=== If the current field is not an option, ignore it. ===*/ if (!oFields[i].FieldType.IsSubclassOf(typeof(OptionBase))) { continue; } /*=== Parse this option's attributes. ===*/ List <Attribute> attrs = AttributeUtility.GetAllAttributes(oFields[i], false); OptionInfo info = new OptionInfo(attrs); // If a commandline syntax isn't specified, ignore this option. if (info.CommandLine == "") { continue; } string tag = info.CommandLine; // Handle string list options. if (oFields[i].FieldType == typeof(StringListOption)) { StringListOption gOption = (StringListOption)oFields[i].GetValue(gOptions); StringListOption pOption = (StringListOption)oFields[i].GetValue(pOptions); int gsize = gOption.StringList.Count; int psize = pOption.StringList.Count; if (gsize > 0) { cmd += " " + tag + " "; cmd += '"' + gOption.StringList[0].Trim(trimchars) + '"'; for (int j = 1; j < gsize; j++) { cmd += "," + '"' + gOption.StringList[j].Trim(trimchars) + '"'; } } if (psize > 0) { int j = 0; if (gsize < 1) { cmd += " " + tag + " "; cmd += '"' + pOption.StringList[0].Trim(trimchars) + '"'; j = 1; } for (; j < psize; j++) { cmd += "," + '"' + pOption.StringList[j].Trim(trimchars) + '"'; } } } // Handle string options. else if (oFields[i].FieldType == typeof(StringOption)) { StringOption gOption = (StringOption)oFields[i].GetValue(gOptions); StringOption pOption = (StringOption)oFields[i].GetValue(pOptions); if (pOption.Value != "") { cmd += " " + tag + " " + '"' + pOption.Value.Trim(trimchars) + '"'; } else if (gOption.Value != "") { cmd += " " + tag + " " + '"' + gOption.Value.Trim(trimchars) + '"'; } } // Handle boolean options. else if (oFields[i].FieldType == typeof(BoolOption)) { BoolOption gOption = (BoolOption)oFields[i].GetValue(gOptions); BoolOption pOption = (BoolOption)oFields[i].GetValue(pOptions); bool on = pOption.UseDefault ? gOption.Value : pOption.Value; if (on) { cmd += " " + tag; } } // Handle int options. else if (oFields[i].FieldType == typeof(IntOption)) { IntOption gOption = (IntOption)oFields[i].GetValue(gOptions); IntOption pOption = (IntOption)oFields[i].GetValue(pOptions); int val = pOption.UseDefault ? gOption.Value : pOption.Value; cmd += " " + tag + " " + val; } } /*=== Setup the command line info data structure. ===*/ CommandLineInfo cmdinfo = new CommandLineInfo(); /*=== set the license path ===*/ if (pOptions.LicensePath.Value != "") { cmd += " -license " + '"' + pOptions.LicensePath.Value.Trim(trimchars) + '"'; } else if (gOptions.LicensePath.Value != "") { cmd += " -license " + '"' + gOptions.LicensePath.Value.Trim(trimchars) + '"'; } else { cmd += " -license " + '"' + opLicenseUtility.FullLicenseFileName + '"'; } cmdinfo.Arguments = cmd; /*=== set the executable path ===*/ if (pOptions.ExecutablePath.Value != "") { cmdinfo.ExecutablePath = pOptions.ExecutablePath.Value.Trim(trimchars); } else if (gOptions.ExecutablePath.Value != "") { cmdinfo.ExecutablePath = gOptions.ExecutablePath.Value.Trim(trimchars); } else { cmdinfo.ExecutablePath = Path.GetFullPath(Paths.GetFullAppPath() + "..\\Release\\opCpp.exe"); } return(cmdinfo); }
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(); }