コード例 #1
0
        //TODO: need to add debug, nodebug catching
        void FinishedCompile(bool bErrored)
        {
            PrintDebugLine("Finished opC++ Build.");
            //handle post-build operations
            CurrentThread = null;

            EnableCompileButtons();

            PostEvent = "";

            if (bErrored)
            {
                return;
            }

            if (CurrentMode != null)
            {
                // if the command was from the toolbar, we can customize the post build event using settings
                if (!CurrentMode.bIntercepted)
                {
                    Options options = OptionsManager.GetGlobalOptions().GetGlobalConfiguration().Options;

                    if (CurrentMode.Action == CompileTypes.Build)
                    {
                        if (CurrentMode.Selection == SelectionTypes.Solution)
                        {
                            //TODO: grab the command
                            PostEvent = options.PostBuildSolution.Value;
                        }
                        else if (CurrentMode.Selection == SelectionTypes.Project)
                        {
                            //TODO: grab the command
                            PostEvent = options.PostBuildProject.Value;
                        }
                    }
                    else if (CurrentMode.Action == CompileTypes.Clean)
                    {
                        //TODO: grab the command
                        PostEvent = options.PostCleanSolution.Value;
                    }
                }
                else if (CurrentMode.Action == CompileTypes.Debug)
                {
                    PostEvent = "Debug.Start";
                }
                else if (CurrentMode.Action == CompileTypes.NoDebug)
                {
                    PostEvent = "Debug.StartWithoutDebugging";
                }
                else
                {
                    //setup the post-build event
                    if (CurrentMode.Action == CompileTypes.Build)
                    {
                        PostEvent = "Build.Build";
                    }
                    else if (CurrentMode.Action == CompileTypes.Rebuild)
                    {
                        PostEvent = "Build.Rebuild";
                    }
                    else if (CurrentMode.Action == CompileTypes.Clean)
                    {
                        PostEvent = "Build.Clean";
                    }

                    if (CurrentMode.Selection == SelectionTypes.Project)
                    {
                        PostEvent += "Selection";
                    }
                    else if (CurrentMode.Selection == SelectionTypes.ProjectOnly)
                    {
                        PostEvent += "OnlyProject";
                    }
                    else if (CurrentMode.Selection == SelectionTypes.Solution)
                    {
                        PostEvent += "Solution";
                    }
                }
            }

            if (PostEvent.Length != 0)
            {
                App().ExecuteCommand(PostEvent, "");
            }
        }
コード例 #2
0
        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();
        }