Example #1
0
        public static bool fManageMessages(CppCmd _oCmd, string _sMsg)
        {
            if (_sMsg.IndexOf("Unhandled Exception") >= 0)
            {
                Output.TraceError(_sMsg);
                nError++;
                return(true);
            }

            if (_sMsg.Length >= 3 && _sMsg[1] == '|' && (_sMsg[2] != '/' || _sMsg[2] != '\\'))
            {
                string _sMessage = _sMsg.Substring(2).Trim();
                switch (_sMsg[0])
                {
                case 'W':
                    Output.TraceWarning(_sMessage);
                    return(true);

                case 'I':
                    Output.TraceAction(_sMessage);
                    return(true);

                case 'E':
                    Output.TraceError(_sMessage);
                    nError++;
                    return(true);

                case 'A':

                    String[] _aMsg = _sMessage.Split('|');
                    if (_aMsg.Length >= 2)
                    {
                        switch (_aMsg[0])
                        {
                        case "[C~:Lib]":
                            Output.TraceAction(_sMessage);
                            fAssistCwLib(_sMessage);

                            return(true);

                        case "C~>C++":
                        case "C~2Cpp":
                        case "Cw2Cpp":
                            Output.TraceAction(_sMessage);
                            _oCmd.fAddCompiledObject(_aMsg[1] + ".cpp");                  //Know as .cpp object
                            return(true);

                        case "C~:UpToDate":
                        case "CwUpToDate":
                        case "CwUp2Date":
                            Output.TraceColored("\f27C~:Up2Date|\f28" + _aMsg[1]);
                            _oCmd.fAddUpToDateObject(_aMsg[1] + ".cpp");
                            return(true);
                        }
                    }
                    break;
                }
            }
            return(false);
        }
Example #2
0
        public static string fDelocaliseFile(string _sPath, string _sExtention)
        {
            string _sResult = "";

            //  Debug.fTrace("fDelocaliseFile: " + _sPath);
            try{
                _sResult = File.ReadAllText(_sPath);
                if (_sExtention.ToLower() == ".cwmake") //Change default dir
                {
                    string _sDirectory = Path.GetDirectoryName(Path.GetFullPath(_sPath));
                    // Debug.fTrace("wDir = " + _sDirectory);
                    //fSetGlobalVar("wDir", _sDirectory );

                    Data.oArg = new ArgumentManager();  //Reset ARG Sure?

                    CppCmd.fSetWorkingDir(Data.oArg, _sDirectory);


                    //  ArgumentManager.fSetVar(oArg, );
                    //   .o
                    // fSetWorkingDir(_sFullValue);
                }
            }catch (Exception e) {}
            //   Debug.fTrace("Result: " + _sResult);
            return(_sResult);
        }
Example #3
0
        public Depandance(CppCmd _parent, string _sPath)
        {
            //TEMP DESACTIVATE
            //    bHaveNewerFile = true;
            ////////////////////
            //Console.WriteLine("Depandance: " + _sPath );


            parent = _parent;
            if (_sPath.Length > 1)
            {
                //    string _sToType =  Path.GetExtension(_sPath);
                if (_sPath[_sPath.Length - 1] == 'o')
                {
                    sOutputPath = _sPath;
                    sPath       = _sPath.Substring(0, _sPath.Length - 1) + "d";


                    if (File.Exists(sOutputPath) && File.Exists(sPath))
                    {
                        dtObjFile = File.GetLastWriteTime(sOutputPath);
                        fReadDepandance(File.ReadAllText(sPath), _parent, true);
                        return;
                    }
                }
            }

            // Console.WriteLine("bHaveNewerFile " + bHaveNewerFile);
            bHaveNewerFile = true;
        }
Example #4
0
        internal void fAddInclude(CppCmd _oCppCmd, string _sPath)
        {
            _sPath = PathHelper.fNormalizeFolderAndRel(_sPath);

            /*
             * _sPath = _sPath.Replace('\\', '/').Replace('\"', ' ').Trim();
             *          if(_sPath[0] == '\''){
             *                  _sPath =_sPath.Substring(1);
             *          }
             *          if(_sPath[_sPath.Length-1] == '\''){
             *                  _sPath = _sPath.Substring(0,_sPath.Length-1);
             *          }*/

            _oCppCmd.aInclude.Add(_sPath);
            if (aAllInclude.Contains(_sPath))
            {
                return;
            }
            aAllInclude.Add(_sPath);


            if (!Data.aAllInclude.Contains(_sPath))
            {
                Data.aAllInclude.Add(_sPath);
            }
        }
Example #5
0
        public static void fShowResult(OutToken _oOut)
        {
            string _sOut = _oOut.sOut;
            CppCmd _oCmd = _oOut.oFrom;

            if (Data.bNowBuilding)
            {
                if (fManageMessages(_oCmd, _sOut))
                {
                    return;
                }

                if (_oOut.eType == OutType.Undefined)
                {
                    Output.TraceUndefined(_sOut);
                    return;
                }
                if (_oOut.eType == OutType.Warning)
                {
                    Output.TraceWarningLite(_sOut);
                    return;
                }
                if (_oOut.eType == OutType.Error)
                {
                    Output.TraceErrorLite(_sOut);
                    return;
                }

                //Add color manually
                if (_sOut.Length > 8)
                {
                    if (_sOut[7] == ':')                      //no color by default
                    {
                        bool   bFound = false;
                        string _sCmd  = _sOut.Substring(0, 7).ToLower();
                        switch (_sCmd)
                        {
                        case "warning":
                            bFound = true;
                            Output.TraceWarning(_sOut);
                            break;
                        }
                    }
                }

                string _sResult = Output.Trace(_sOut, true);

                /*
                 * if( Data.oMainForm != null) {
                 *   Data.oMainForm.fAddItem(_sResult);
                 * }*/
            }
        }
Example #6
0
 public static void fShowProcOutput(CppCmd _oCmd)
 {
     if (aOutput != null && aOutput.Count > 0)
     {
         //_oCmd.oDepandance.fShowFile();
         foreach (OutToken _oOut in aOutput)  //Show all precedant commands
         {
             if (_oCmd == _oOut.oFrom && _oOut.bShowed == false)
             {
                 _oOut.bShowed = true;
                 fShowProcOutputString(_oOut);
             }
         }
     }
 }
Example #7
0
        public static string  fGetGlobalVar(string _sVar, bool _bWeak = false)
        {
//Output.TraceWarning("fGetGlobalVar " + _sVar);

            /*
             * if(_sVar == "lPThread") {
             * Output.TraceWarning("fGetGlobalVar " + _sVar);
             * }*/
            if (Data.aVarGlobal.ContainsKey(_sVar))
            {
                return(CppCmd.fExtractVar(Data.aVarGlobal[_sVar], null));
            }
            if (_bWeak)
            {
                return("{" + _sVar + "}");//Keep original
            }
            return("");
        }
Example #8
0
        public void fReadDepandance(string _sText, CppCmd _oCmd, bool _bReadAll = false)   //_bReadAll for #Has_dependance
        {
            bReadAll = _bReadAll;

            //   bool _bFirstLine = true;

            // _sLine = _sLine.Substring(_sLine.IndexOf(": ")+1).Trim(); //Remove first line object file reference xxx.o: \

            if (_oCmd != null)   //Be sure to Verify all depandant other source files
                                 // Console.WriteLine("-----fReadDepandance for: "+_oCmd.sOutputFile);
            {
                foreach (string _sFile in  _oCmd.aCompileFiles)
                {
                    if (fChekdependance(_sFile))
                    {
                        if (!bReadAll)
                        {
                            return;
                        }
                    }
                }
            }



            //Replace("/:",":") (=> dgcpp)
            string[] aReadLine = _sText.Replace('\\', '/').Replace("/:", ":").Split(new[] { "/\r\n", "\r\n", "\n" }, StringSplitOptions.None);
            foreach (string _sALine in aReadLine)
            {
                //  ": " First line is object reference -> Optimise?
                string _sSubLine = _sALine.Substring(_sALine.IndexOf(": ") + 1).Replace("/ ", "*").Trim(); //When we have space Clang add '/'  "/ "," "
                //     _sLine = _sLine.Substring(_sLine.IndexOf(' ' ) + 1).Replace('*', ' '); //Remove self lookup //  obj/cw/Lib_GZ/EntryPoint.cpp obj/cw\Lib_GZ/EntryPoint.h \

                foreach (string _sNewLine  in _sSubLine.Split(' '))
                {
                    string _sLine = _sNewLine.Replace('*', ' ');

                    if (_sLine == "" || _sLine[_sLine.Length - 1] == ':')
                    {
                        continue;
                    }

                    //Cwc Arg Line
                    if (_sALine.Length > 3 && _sALine[0] == 'C' && _sALine[1] == 'w' && _sALine[2] == 'c')    ///TODO test before to save time
                    // while(true){Thread.Sleep(1);}
                    {
                        string _sCmd = _sALine.Substring(4);       //_sALine is unmodified : "/ " by " " in include folder

                        string _sOldCmd = parent.sCompiler + " " + parent.sConfig_Type + " " + parent.sExeCmdUnique + " >> " + parent.sRecompileOnChangeCmd;
                        // Debug.fTrace("CompareNew:" + _sCmd);
                        //Debug.fTrace("CompareOld:" +  _sOldCmd);  //TODO   Data.sCompiler Test if may change between files
                        //    Console.WriteLine("CompareNew:" + _sCmd);
                        //Console.WriteLine("CompareOld:" +  _sOldCmd);  //TODO   Data.sCompiler Test if may change between files
                        if (_sOldCmd != _sCmd)                          //Command are not the same
                        {
                            fHaveNewerFile();
                            //bHaveNewerFile = true;

                            return;
                        }
                    }
                    else
                    {
                        if (fChekdependance(_sLine))
                        {
                            if (!bReadAll)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #9
0
        internal static string fSend2App(CppCmd _oCmd, string _sExplicite_Name, string _sExplicite_App, string _sExplicite_Call, bool _bWaitToFinish = false, List <CppCmd> aSubInputCmd = null)
        {
            bool _bFinished = false;

            if (_bWaitToFinish)
            {
                sProcOutputRetrun = "";
            }

            string _sExe = fExtracQuote(_sExplicite_App);
            string _sArg = fExtracQuote_sArg + " " + _sExplicite_Call;

            //TODO merge with fSend2Compiler
            Output.TraceAction(_sExplicite_Name + " => " + _sExplicite_Call);

            uint _nMyTicket = 0;

            lock (oLockTicket) {
                _nMyTicket = nTotalTicket;
                nTotalTicket++;
            }

            if (bHasError || !Data.bNowBuilding)
            {
                return("");
            }

            CheckAllThreadsHaveFinishedWorking();
            if (bHasError || !Data.bNowBuilding)
            {
                return("");
            }
            Interlocked.Increment(ref safeInstanceCount);

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += new DoWorkEventHandler(
                delegate(object o, DoWorkEventArgs args){
                if (bHasError || !Data.bNowBuilding)
                {
                    Interlocked.Decrement(ref safeInstanceCount);
                    return;
                }

                StringBuilder output = new StringBuilder();
                StringBuilder error  = new StringBuilder();

                using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) {
                        using (Process process = new Process()) {
                            _oCmd.oCurrProcess     = process;
                            _oCmd.sLaunchCmdResult = "";

                            process.StartInfo.FileName  = _sExe;
                            process.StartInfo.Arguments = _sArg;

                            process.StartInfo.CreateNoWindow = true;
                            //process.StartInfo.CreateNoWindow = false;
                            process.StartInfo.UseShellExecute        = false;
                            process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.RedirectStandardError  = true;

                            if (aSubInputCmd != null)
                            {
                                process.StartInfo.RedirectStandardInput = true;
                            }

                            process.StartInfo.WorkingDirectory = _oCmd.s_pProject;

                            try  {
                                process.OutputDataReceived += (sender, e) => {
                                    if (e.Data != null)
                                    {
                                        fCompilerError(e.Data, _sExplicite_Name + " : " + _sExplicite_Call, _nMyTicket, false, _oCmd);
                                    }
                                };
                                process.ErrorDataReceived += (sender, e) => {
                                    if (e.Data != null)
                                    {
                                        fCompilerError(e.Data, _sExplicite_Name + " : " + _sExplicite_Call, _nMyTicket, true, _oCmd);
                                    }
                                };

                                Console.WriteLine("Start " + process.StartInfo.FileName);
                                Console.WriteLine("arg " + process.StartInfo.Arguments);

                                process.Start();
                                process.BeginOutputReadLine();
                                process.BeginErrorReadLine();
                                fLaunchInputApp(process, aSubInputCmd);

                                process.WaitForExit();
                                ///////////////////////////////////////
                                ///Wait for displaying in order
                                ////////////////////////////////////////*
                                while (Base.bAlive && Data.bNowBuilding)
                                {
                                    Thread.CurrentThread.Join(1);
                                    lock (oLockTicket) {
                                        if (nCurrentTicket == _nMyTicket)
                                        {
                                            // Console.WriteLine("*** Process  " + nCurrentTicket + " " + _oCmd == null );
                                            fShowSendedCmd(_oCmd);
                                            fShowProcOutput(_oCmd);
                                            if (nErrorTicket == nCurrentTicket && (nError > 0))
                                            {
                                                //Console.WriteLine(":: " +  GuiForm.fIsChecked("afterFileErrorToolStripMenuItem")); //TODO TODOTODO
                                                fShowProcOutput(_oCmd);
                                                Build.StopBuild(); //Dont display other file errors
                                                break;
                                            }
                                            nCurrentTicket++;
                                            break;
                                        }
                                    }
                                }
                                ///////////////////////////////////////////////
                            }catch (Exception e) {
                                Output.TraceError("Error with " + process.StartInfo.FileName + "[" + process.StartInfo.Arguments + "]:" + e.Message);
                            } finally {}

                            try { while (!process.HasExited)
                                  {
                                      Thread.CurrentThread.Join(1);
                                      if (!Data.bNowBuilding)
                                      {
                                          break;
                                      }
                                  }
                            }catch (Exception e) {}

                            _bFinished = true;
                            Interlocked.Decrement(ref safeInstanceCount); //safeInstanceCount never decremented if after  fAddCommandLineVerificationToDepedancesFile?? on link time : exception?
                        }
                    }
            });
            worker.RunWorkerAsync();

            if (_oCmd.bRetryForInput)
            {
                while (!_bFinished)
                {
                    Thread.CurrentThread.Join(1);
                }
                if (_oCmd.sLaunchCmdResult == "")
                {
                    //Recursive call
                    //Thread.Sleep(1); //Minimal wait
                    return(fSend2App(_oCmd, _sExplicite_Name, _sExplicite_App, _sExplicite_Call, _bWaitToFinish, aSubInputCmd));
                }
                return(_oCmd.sLaunchCmdResult);
            }

            if (_bWaitToFinish)
            {
                while (!_bFinished)
                {
                    Thread.CurrentThread.Join(1);
                }
                return(sProcOutputRetrun.Trim());
            }

            return("");
        }
Example #10
0
        public static void fCompilerError(string _sResult, string _sArg, uint _nMyTicket, bool _bStdError = false, CppCmd _oCmd = null)
        {
            //Direct show if current
            lock (oLockTicket) {
                _oCmd.sLaunchCmdResult += _sResult + "\n";

                if (_oCmd.sCloseWhen != "")
                {
                    if (_sResult.IndexOf(_oCmd.sCloseWhen) != -1)
                    {
                        if (_oCmd.oCurrProcess != null && !_oCmd.oCurrProcess.HasExited)
                        {
                            _oCmd.oCurrProcess.Kill();
                        }
                    }
                }

                if (_oCmd != null && _oCmd.oToInputProcess != null)
                {
                    _oCmd.oToInputProcess.StandardInput.WriteLine(_sResult);
                    //   _oCmd.oToInputProcess.StandardInput.Write(_sResult + "\n");
                    _oCmd.oToInputProcess.Refresh();
                    Console.WriteLine("R:" + _sResult);
                    return;
                }


                sProcOutputRetrun += " " + _sResult;
                if (!(Base.bAlive && Data.bNowBuilding))
                {
                    return;
                }

                if (nCurrentTicket == _nMyTicket)  //Direct show to not wait ending compilation
                {
                    fShowProcOutput(_oCmd);
                }

                if (_bStdError)
                {
                    if (fFindValidKeyWord(_sResult, "error") != -1)                    //Generiquer error check!?
                    {
                        nError++;

                        if (_nMyTicket < nErrorTicket || nErrorTicket == -1)
                        {
                            nErrorTicket = (int)_nMyTicket;
                        }
                    }
                }

                if (aOutput != null)
                {
                    OutToken _oOut = new OutToken();
                    _oOut.oFrom = _oCmd;
                    _oOut.sOut  = _sResult;

                    if (_sResult.IndexOf("undefined reference to") != -1)
                    {
                        _oOut.eType = OutType.Undefined;
                    }

                    if (fFindValidKeyWord(_sResult, "error") != -1)
                    {
                        _oOut.eType = OutType.Error;
                    }
                    if (fFindValidKeyWord(_sResult, "warning") != -1)
                    {
                        _oOut.eType = OutType.Warning;
                    }
                    aOutput.Add(_oOut);
                }

                if (nCurrentTicket == _nMyTicket)  //Direct show to not wait ending compilation
                {
                    fShowProcOutput(_oCmd);
                }
            }
        }
Example #11
0
 public static void fShowSendedCmd(CppCmd _oFrom)
 {
     fShowArg(_oFrom.sCommandToShow, _oFrom.bIsSubCmd);
     _oFrom.sCommandToShow = "";
 }
Example #12
0
        public static void fSend2Compiler(string _sArg, bool _bLinkTime = false, bool _bCompileAndLink = false, CppCmd _oCmd = null, string _sAllFile = "")
        {
            //string _sPlatform = _oCmd.oParent.sPlatform;
            string _sPlatform = _oCmd.oParent.fGetVar("_sPlatform");

            if (_oCmd.oCompiler == null)
            {
                //Debug.fTrace("Unknow Compiler");
                Output.TraceError("Unknow Compiler");
                return;
            }

            string _sInfo = "";

            if (_oCmd != null && _bLinkTime)
            {
                if (_oCmd.bToStaticLib)
                {
                    _sInfo = " [Static_Link]";
                }
                else if (_oCmd.bToDynamicLib)
                {
                    _sInfo = " [Dynamic_Link]";
                }
                else
                {
                    _sInfo = " [Link]";
                }
            }

            string _sObjectList = "";

            if (_sAllFile != "")
            {
                _sObjectList = "[\f1B" + _sAllFile + "\f1F]";
            }

            string _sFinalArg = _sArg.Replace("\\\"", "\"");

            _sFinalArg = _sFinalArg.Replace("%%", "¶"); //A way to keep %
            _sFinalArg = _sFinalArg.Replace('%', '\\'); //Backslash special char % transform, we must have a ways to send backslash to compiler
            _sFinalArg = _sFinalArg.Replace('¶', '%');  //A way to keep %

            _oCmd.sCommandToShow = "\f1F (" + _oCmd.sExecutableName + _oCmd.sExecutableType + _sInfo + ")" + _sObjectList + "  " + _sFinalArg;

            uint _nMyTicket = 0;

            lock (oLockTicket) {
                _nMyTicket = nTotalTicket;
                nTotalTicket++;
            }

            if (bHasError || !Data.bNowBuilding)
            {
                return;
            }

            CheckAllThreadsHaveFinishedWorking();
            if (bHasError || !Data.bNowBuilding)
            {
                return;
            }
            Interlocked.Increment(ref safeInstanceCount);
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += new DoWorkEventHandler(
                delegate(object o, DoWorkEventArgs args)
            {
                if (bHasError || !Data.bNowBuilding)
                {
                    Interlocked.Decrement(ref safeInstanceCount);
                    // Debug.fTrace("Dec " + safeInstanceCount);
                    return;
                }

                StringBuilder output = new StringBuilder();
                StringBuilder error  = new StringBuilder();

                using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
                    using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
                    {
                        using (Process process = new Process()) {
                            process.StartInfo.FileName  = _oCmd.sExecutable;
                            process.StartInfo.Arguments = _sFinalArg;

                            process.StartInfo.CreateNoWindow         = true;
                            process.StartInfo.UseShellExecute        = false;
                            process.StartInfo.RedirectStandardOutput = true;
                            process.StartInfo.RedirectStandardError  = true;

                            process.StartInfo.WorkingDirectory = _oCmd.s_pProject;

                            try  {
                                if (process.StartInfo.FileName.Length + process.StartInfo.Arguments.Length >= 32700) // Command line size limitation, real 32768
                                //Todo verify for .wdat folder?
                                {
                                    process.StartInfo.Arguments = "@.wdat/arg.wdat";
                                    File.WriteAllText(@".wdat/arg.wdat", _sFinalArg);
                                }

                                process.OutputDataReceived += (sender, e) => { if (e.Data != null)
                                                                               {
                                                                                   fCompilerError(e.Data, _sArg, _nMyTicket, false, _oCmd);
                                                                               }
                                };
                                process.ErrorDataReceived += (sender, e) => { if (e.Data != null)
                                                                              {
                                                                                  fCompilerError(e.Data, _sArg, _nMyTicket, true, _oCmd);
                                                                              }
                                };

                                process.Start();
                                process.BeginOutputReadLine();
                                process.BeginErrorReadLine();
                                process.WaitForExit();

                                ///////////////////////////////////////
                                ///Wait for displaying in order
                                //////////////////////////////////////
                                while (Base.bAlive && Data.bNowBuilding)
                                {
                                    Thread.CurrentThread.Join(1);
                                    lock (oLockTicket) {
                                        if (nCurrentTicket == _nMyTicket)
                                        {
                                            fShowSendedCmd(_oCmd);
                                            fShowProcOutput(_oCmd);

                                            if (nErrorTicket == nCurrentTicket && (nError > 0))  //&& GuiForm.fIsChecked("afterFileErrorToolStripMenuItem") //TODO
                                            {
                                                fShowProcOutput(_oCmd);
                                                Build.StopBuild(); //Dont display other file errors
                                                break;
                                            }


                                            nCurrentTicket++;
                                            break;
                                        }
                                    }
                                }
                                ////////////////////////////////////
                            }catch (Exception e) {
                                Output.TraceError(e.Message);
                                string _sSended = process.StartInfo.FileName + " " + process.StartInfo.Arguments;
                                Output.TraceAction(_sSended);
                                if (_sSended.Length >= 32768)
                                {
                                    Output.TraceWarning("You may have exceeded the maximum command line size of 32768 characters: " + _sSended.Length + " chars");
                                }
                                Interlocked.Decrement(ref safeInstanceCount);
                                return;
                            }



                            while (!process.HasExited)
                            {
                                Thread.CurrentThread.Join(1);
                                if (!Data.bNowBuilding)
                                {
                                    break;
                                }
                            }

                            Interlocked.Decrement(ref safeInstanceCount); //safeInstanceCount never decremented if after  fAddCommandLineVerificationToDepedancesFile?? on link time : exception?
                            if (_oCmd != null && !_bLinkTime)
                            {
                                _oCmd.fAddCommandLineVerificationToDepedancesFile(_oCmd); //TODO is infinite loop?
                            }
                        }
                    }
            });
            worker.RunWorkerAsync();
        }
Example #13
0
        /*
         * // foreach (string _sSub in _aSub) { if (!IsEmpty(_sSub)) {  //Get first valid
         * break;
         * }}
         */

        public void ExtractCommandLine(string _sCmd)
        {
            CppCmd _oCppCmd = new CppCmd(this, _sCmd);

            oCurCppSeq.aCppCmd.Add(_oCppCmd);
        }