Exemplo n.º 1
0
        public ModuleData(string _sAutorName, bool _bIsCompiler = false)
        {
            sAutorName = _sAutorName;
            string[] _aValue = _sAutorName.Split('/');              //Squential

            sAutor      = _aValue[0];
            sName       = _aValue[1];
            bIsCompiler = _bIsCompiler;


            string _sSpecialPrefix = "";
            string _sMainFolder    = "Lib/";

            if (bIsCompiler)
            {
                _sMainFolder = "Toolchain/";
            }
            _sMainFolder += sAutor + "/";


            if (sAutor == "Honera")              //Special lib
            {
                switch (sName)
                {
                case "Cwc":
                    _sMainFolder    = "";
                    _sSpecialPrefix = "Upd_";
                    break;

                case "Cwc_Demos":
                    _sMainFolder    = "";
                    _sSpecialPrefix = "_";
                    bAutoExplore    = true;
                    break;
                }
            }
            _sMainFolder += _sSpecialPrefix + sName + "/";

            sOutFolder    = PathHelper.GetExeDirectory() + _sMainFolder;          //Todo configurable base path
            sPrefixFolder = sName + "-";

            fUpdateGithubUrls();


            //  if (sName == "GZE")
            if (sName == "GZE_disable")
            {
                ModuleData _oLib = new ModuleData(this, "src/SubLib_3rdparty/", "GzNima");
                aSubLib.Add(_oLib);

                ModuleData _oLibBox2d = new ModuleData(this, "src/SubLib_3rdparty/", "GzBox2D");
                aSubLib.Add(_oLibBox2d);

                Output.TraceAction("ADD NIMA LIB: " + _oLib.sCurrFolder);
                Output.TraceAction("ADD Box2D LIB: " + _oLib.sCurrFolder);
                //Testlib
                //  ModuleData _oLib = new ModuleData(true, "");
                // oParent.fAddLib(_oLib);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public ModuleData(ModuleData _oParentLib, string _sSubPath = "", string _sName = "")
        {
            oParentLib  = _oParentLib;
            bSubLib     = true;
            bIsCompiler = false;

            sName      = _sName;
            sAutorName = _oParentLib.sAutorName + "/" + sName;
            sAutor     = _oParentLib.sAutor;

            sOutFolder    = _oParentLib.sOutFolder;
            sPrefixFolder = _oParentLib.sPrefixFolder;



            sSubPath = _sSubPath;



            Output.TraceAction("sAutorName " + sAutorName);
            Output.TraceAction("sOutFolder " + sOutFolder);
            Output.TraceAction("sPrefixFolder " + sPrefixFolder);

            //   sCurrFolder = _oParentLib.sCurrFolder + _sPath;
            //  fGetCompilerList();
        }
Exemplo n.º 4
0
        public static void     fPrjOut(string _sLetter, string _sOut)
        {
            if (_sOut == null)
            {
                return;
            }

            string _sPrefix = _sLetter + "> ";

            if (_sOut.Length > 4) //ex T[1]:xxxx
            {
                if (_sOut[1] == '[')
                {
                    switch (_sOut[0])
                    {
                    case 'P':
                        Output.TraceGood(_sPrefix + _sOut);
                        break;

                    case 'E':
                        Output.TraceError(_sPrefix + _sOut);
                        break;

                    case 'W':
                        Output.TraceWarning(_sPrefix + _sOut);
                        break;

                    case 'A':
                        Output.TraceAction(_sPrefix + _sOut);
                        break;

                    case 'T':
                        Output.TraceStd(_sPrefix + _sOut);
                        break;

                    default:
                        Output.Trace(_sPrefix + _sOut);
                        break;
                    }
                    return;
                }
            }
            Output.Trace(_sPrefix + _sOut);
            return;
        }
Exemplo n.º 5
0
        private static void fAssistCwLib(string _sMessage)
        {
            string[] _aMessage      = _sMessage.Split('|');
            int      _nIndex        = 0;
            string   _sParentModule = "";
            string   _sPath         = "";
            string   _sName         = "";

            foreach (string _sMsg in _aMessage)
            {
                _nIndex++;
                if (_sMsg.Length > 3)
                {
                    if (_sMsg[0] == '(')
                    {
                        _sParentModule = _sMsg.Substring(1, _sMsg.LastIndexOf(')') - 1);
                        _sName         = _sMsg.Substring(_sParentModule.Length + 2);
                    }
                    if (_nIndex != 1 && _sMsg[0] == '[')
                    {
                        _sPath = _sMsg.Substring(1, _sMsg.Length - 1 - 1);
                    }
                }
            }

            //FOUND a SUBLIB
            if (_sName != "" && _sParentModule != "" && _sPath != "")
            {
                ModuleData _oMyModule = ModuleData.fGetModule(_sParentModule, false);
                if (_oMyModule != null)
                {
                    ModuleData _oLib = new ModuleData(_oMyModule, _sPath, _sName);
                    _oMyModule.fAddSubLib(_oLib);
                    _oMyModule.fGetSubLibCompilerData(Data.oArg);  //Data.oArg  not sure

                    Output.TraceAction("Add SubLib: " + _sName);
                }
            }
        }
Exemplo n.º 6
0
        public static void      fHttpOutInfo(LaunchTool _oTool, string _sOut)
        {
            ParamHttp _oParam = (ParamHttp)_oTool.oCustom;

            //_oParam.sResult = _sOut;
            _oParam.sInfo += _sOut + "\n";
            //_oParam
            //Debug.fTrace("E: " + _sOut);

            //"Length:"
            if (_oParam.bDownloadFile)
            {
                int _nLimit = -1;
                if (_sOut.Length > 7 && _sOut[0] == 'L' && _sOut[6] == ':')
                {
                    string _sLength = _sOut.Substring(8);
                    //Debug.fTrace("_sLength: " + _sLength);
                    string _sSubLength = _sLength;
                    int    _nEnd       = _sSubLength.IndexOf(' ');
                    if (_nEnd != -1)
                    {
                        _sSubLength = _sSubLength.Substring(0, _nEnd);
                    }

                    int.TryParse(_sSubLength, out _nLimit);
                    //	Debug.fTrace("--Total!! " + _nLimit);
                }
                _oParam.nTotalBytes = _nLimit;
                //	Debug.fTrace("--_sOut[_sOut.Length - 1 ]!! " + _sOut[_sOut.Length - 1 ]);
                if (_sOut[_sOut.Length - 1] == 's')
                {
                    int _nEnd = _sOut.IndexOf('K');
                    if (_nEnd != -1)
                    {
                        string _sBytes = _sOut.Substring(0, _nEnd);
                        int    _nByte  = -1;
                        int.TryParse(_sBytes, out _nByte);
                        _oParam.nBytes = _nByte * 1000;
                        //	Debug.fTrace("--nBytes!! " + _oParam.nBytes);
                        fUrlProgress(_oParam);
                    }
                }

                // if(Data.oGuiConsole != null){ Data.oGuiConsole.Fctb.RemoveLines(aLineToDelete); aLineToDelete.Clear();}
                _sOut = _sOut.Trim();
                if (_sOut != "")
                {
                    if (_sOut.IndexOf("Cannot") >= 0 || _sOut.IndexOf("Bad") >= 0)
                    {
                        Output.TraceError("\rDownload: " + _sOut);
                    }
                    else
                    {
                        Output.TraceAction("\rDownload: " + _sOut);
                    }
                }

                // if(Data.oGuiConsole != null){ aLineToDelete.Add( Data.oGuiConsole.Fctb.LinesCount-1); }

                Debug.fRPrint("Download: " + _sOut + "                                                                                                 ");
            }
            ////	_oParam.oHeader = _response.Headers;
        }
Exemplo n.º 7
0
        public void fGetCompilerList()
        {
            if (bGetCompilerList)
            {
                return; //Already done
            }
            bGetCompilerList = true;
            Output.TraceAction("Get: " + sName);


            //fGetCompilerData
            //Debug.fTrace("fGetCompilerList : " +  sCurrFolder + "wType/");
            aCompilerData = new List <CompilerData>();
            aPlatformData = new Dictionary <string, CompilerData>();


            string _sFoundPath = PathHelper.fFindFolder(sCurrFolder, "cwc", 5);

            if (_sFoundPath == "")  //Default
            {
                _sFoundPath = sCurrFolder;
            }
            // Output.TraceAction("FOund?: " + _sFoundPath);
            String[] _aFiles = Directory.GetFiles(_sFoundPath, "*.cwcfg");
            if (_aFiles.Length == 0)
            {
                Output.TraceError("Cannot find '*.cwcfg' file in " + sCurrFolder);
                Data.bDontExecute = true;
                Build.StopBuild();
                return;
            }
            foreach (string _sCwcfg_File in _aFiles)
            {
                //     Output.TraceGood("Found " +  _sCwcfg_File);
                CompilerData _oCompilerData = new CompilerData(this, _sCwcfg_File);
                if (bIsCompiler)//It's a Compiler
                {
                    aCompilerData.Add(_oCompilerData);
                    //Output.TraceGood("Add:  " + _oCompilerData.sSubName);
                    aPlatformData.Add(_oCompilerData.sSubName, _oCompilerData);
                }
                else   //It's a lib
                {
                    oLibData = _oCompilerData;
                }
            }

            /*
             *
             *          string _sCompilerPlatform = sCurrFolder+ "wType/";
             *          if(!Directory.Exists(_sCompilerPlatform)) {//backward compatibility
             *      _sCompilerPlatform = sCurrFolder+ "_sPlatform/";
             * }
             *          if(Directory.Exists(_sCompilerPlatform)) {
             *
             *                  string[] _aFile = Directory.GetFiles( _sCompilerPlatform,"*.xml");
             *                  foreach (string _sFile in  _aFile){
             *                  //	Debug.fTrace("found:  " + _sFile);
             *                          CompilerData _oCompilerData = new CompilerData(this, _sFile );
             *                          aCompilerData.Add(_oCompilerData);
             *                                          //Debug.fTrace("Add:  " + _oCompilerData.sSubName);
             *                          aPlatformData.Add(_oCompilerData.sSubName,_oCompilerData );
             *                  }
             *                  if(_aFile.Length == 0){
             *                          Output.TraceError("Compiler " +sAutorName +  " 'wType' forlder require xml data");
             *                          Data.bDontExecute = true;
             *                          Build.StopBuild();
             *                  }
             *          //Debug.fTrace("---------------------:  " );
             *          }else{
             *                  Output.TraceError("Compiler " + sAutorName +  " require '_sPlatform' forlder with xml data");
             *                  Data.bDontExecute = true;
             *                  Build.StopBuild();
             *          }
             */
        }
Exemplo n.º 8
0
        public bool fLaunch(string _sPath, bool _bSanitize = false, string _sSubArg = "")
        {
            if (_sPath.Length > 1 && _sPath[_sPath.Length - 1] == '/') //Not a file
            {
                Output.TraceError("Path is not a File: " + _sPath);
                return(false);
            }
            //   Output.TraceError("Try: " + _sPath);

            bool _bDebug       = true;//Temp
            bool _bLaunchDebug = false;

            if (_bDebug)
            {
                _bLaunchDebug = true;
            }



            //	Debug.fTrace("Launch: " + _sPath);



            // if (oCurLaunch == null) { //We can reLaunch !? => Run button
            if (File.Exists(_sPath))
            {
                if (Data.oGuiConsole != null)
                {
                    Data.oGuiConsole.fLaunchPrj();
                }


                oCurLaunch = new LaunchTool();

                //oCurLaunch.bWaitEndForOutput = true;
                //	oCurLaunch.bRunInThread = false;

                oCurLaunch.bRedirectOutput = false;


                string _sArg     = "";
                string _sExePath = _sPath;
                if (Data.fGetGlobalVar("_sPlatform") == "Web_Emsc")
                {
                    _bDebug = false;     // No GDB
                    oCurLaunch.bRedirectOutput = true;
                    oCurLaunch.bHidden         = true;
                    oCurLaunch.UseShellExecute = true;


                    //	bWeb = true;
                    //	bSanitize = false;
                    string _sBrowser = Data.fGetViewIn();
                    _sArg = "\"" + Data.fGetGlobalVar("vWebRT_Emsc") + "emrun\" ";
                    //_sArg +=  "--serve_after_close ";
                    //_sArg +=  "--serve_after_exit ";

                    _sArg += "--browser \"" + _sBrowser + "\" ";
                    //_sArg +=  "--kill_exit ";
                    //sArg +=  "--kill_start ";

                    _sArg += "\"" + _sExePath + "\" ";


                    _sExePath = Data.fGetGlobalVar("vWebRT_Python") + "python.exe";

                    //_sWorkPath = _sExePath;

                    //	public
                }
                else
                {
                    //Normal
                    //	oCurLaunch.bDontKill = true;
                    //oCurLaunch.UseShellExecute = false;
                }

                _sArg += _sSubArg;
                _sArg  = _sArg.Trim();
                //Output.TraceWarning("_sSubArg " + _sSubArg);

                oCurLaunch.dError = new LaunchTool.dIError(fAppError); //Too much error in Emsc?
                oCurLaunch.dOut   = new LaunchTool.dIOut(fAppOut);

                oCurLaunch.dExit = new LaunchTool.dIExit(fExit);

                string _sPrintArg = "";
                if (_sArg != "")
                {
                    _sPrintArg = " [" + _sExePath + " " + _sArg + "]";
                }



                if (_bLaunchDebug)
                {
                    Output.TraceAction("Debug: " + _sPath + _sPrintArg);
                }
                else
                {
                    Output.TraceAction("Run: " + _sPath + _sPrintArg);
                }

                if (_bDebug)
                {
                    //Better way?
                    string       _sCompiler = Data.fGetGlobalVar("_wToolchain");
                    string       _sPlatform = Data.fGetGlobalVar("_sConfig_Type");
                    CompilerData _oCompiler = Finder.fUseCompiler(_sCompiler, _sPlatform);
                    string       _sDebugger = _oCompiler.oGblConfigType.fGetNode(null, new string[] { "Exe", "Debugger" }, "");
                    GDB          _oGdb      = new GDB(this, oCurLaunch, _sDebugger, _sExePath, _oCompiler, _sArg); //Create debugger proxy
                }
                else
                {
                    oCurLaunch.fLaunchExe(_sExePath, _sArg);
                }


                //_oPreload.dExit = new LaunchTool.dIExit(fUrlRequestComplete);
                //	Output.TraceWarning("------------------------");

/*
 *                  oCurLaunch.oForm = this;
 *                  oCurLaunch.bSanitize = _bSanitize;
 *                  oCurLaunch.fLaunchExe(_sPath);
 */

                return(true);
            }
            else
            {
                Output.TraceError("Executable not found: " + _sPath);
            }
            //      }
            return(false);
        }
Exemplo n.º 9
0
        public static bool  fLoadModules(bool _bAutoStart = true)
        {
            bool _bFound = true;

            if (Data.oGuiConsole != null)
            {
                Data.bIWantGoToEnd  = true;
                GuiConsole.sFormCmd = "GoEnd";
                //fctbConsole.GoEnd();
            }

            nLoadModuleIndex = 0;
            foreach (string _sModule in Data.aRequiredModule)
            {
                ModuleData _oModule = ModuleData.fFindModule(_sModule);
                _oModule.fGetLocalVersions();

                //  Http.fGetHttp(  _oModule.sUrl_Project , fGetProjectData);//Get readme
                _oModule.fReadHttpModuleTags();
            }

            //Wait to finish
            while (ModuleData.nRequestTag > 0)
            {
                Thread.CurrentThread.Join(1);
            }

            List <ModuleLink> _aLink = new List <ModuleLink>();


            foreach (string _sModule in Data.aRequiredModule)
            {
                ModuleData _oModule = ModuleData.fFindModule(_sModule);
                if (_oModule.aLinkList.Count > 0)
                {
                    foreach (string _sKeyLink  in _oModule.aLinkList)
                    {
                        // Output.TraceWarning( "Recommended version:");
                        Output.TraceAction("Recommended version:" + _oModule.sName + " : " + _sKeyLink);
                        _aLink.Add(_oModule.aLink[_sKeyLink]);
                        break;
                    }
                }
                else
                {
                    Output.TraceError("Not found:" + _sModule);
                    _bFound = false;
                }
            }


            if (_aLink.Count > 0)
            {
                //   Output.TraceWarning( "Download? (yes / no)");
                Output.TraceWarning("Starting Download ... (press 'n' to cancel)");
                foreach (ModuleLink _oLink in _aLink)
                {
                    _oLink.fDownload();
                    while (_oLink.bDl_InProgress)
                    {
                        Thread.CurrentThread.Join(1);
                    }
                    _oLink.fExtract();
                    while (_oLink.oModule.bExtact_InProgress)
                    {
                        Thread.CurrentThread.Join(1);
                    }
                }
                Output.Trace("");
                Output.TraceGood("---------------- All Required Module Completed ------------------");
                foreach (ModuleLink _oLink in _aLink)
                {
                    Output.TraceAction(_oLink.oModule.sCurrFolder);
                }


                Output.TraceGood("-----------------------------------------------------------------");
                if (_bAutoStart)
                {
                    Data.sCmd = "StartBuild";
                }
            }

            return(_bFound);

            /*
             * foreach(ModuleLink _oLink in _aLink) {
             *     _oLink.fExtract();
             * }
             */

            //  Data.oMsgForm.fLoadNextModule();
        }
Exemplo n.º 10
0
        public static void CopyFolderContents(string sourceFolder, string destinationFolder, string mask = "*.*", string _sExept = "", Boolean createFolders = true, Boolean recurseFolders = true)
        {
            Output.TraceAction("Copy: " + sourceFolder + " to " + destinationFolder);

            try     {
                if (!(sourceFolder.EndsWith(@"\") || sourceFolder.EndsWith(@"/")))
                {
                    sourceFolder += @"\";
                }

                sourceFolder = Path.GetFullPath(sourceFolder);
                string _sSingleFile   = "";
                bool   _bSourceIsFile = false;
                if (!Directory.Exists(sourceFolder))
                {
                    if (File.Exists(sourceFolder))                      //It's a file from source
                    {
                        _sSingleFile   = sourceFolder.Substring(0, sourceFolder.Length - 1);
                        sourceFolder   = new FileInfo(_sSingleFile).Directory.FullName + "\\";
                        _bSourceIsFile = true;
                    }
                    else
                    {
                        return;                         //No source
                    }
                }

                string _sDestFileName = "";
                if (!_bSourceIsFile)
                {
                    if (!(destinationFolder.EndsWith(@"\") || destinationFolder.EndsWith(@"/")))
                    {
                        destinationFolder += @"\";
                    }
                }
                else                    //Source is a file
                {
                    if ((destinationFolder.EndsWith(@"\") || destinationFolder.EndsWith(@"/")))
                    {
                        destinationFolder += Path.GetFileName(sourceFolder);
                    }
                    else
                    {
                        //Debug.fTrace("destinationFolder " + destinationFolder);
                        FileInfo _oFile = new FileInfo(destinationFolder);
                        destinationFolder = _oFile.Directory.FullName + "\\";
                        //Debug.fTrace("----destinationFolder " + destinationFolder);
                        _sDestFileName = _oFile.Name;
                    }
                }

                destinationFolder = Path.GetFullPath(destinationFolder);

                var exDir = sourceFolder;
                var dir   = new DirectoryInfo(exDir);

                string [] _aSourceFile;

                if (_bSourceIsFile)
                {
                    _aSourceFile = new string[] { _sSingleFile };
                }
                else
                {
                    SearchOption so    = (recurseFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    string       _sDir = dir.ToString();
                    if (_sExept == "")
                    {
                        _aSourceFile = Directory.GetFiles(_sDir, mask, so);
                    }
                    else
                    {
                        _aSourceFile = Directory.GetFiles(_sDir, mask, so).Except(Directory.GetFiles(_sDir, _sExept, so)).ToArray();
                    }
                }

                //  foreach (string sourceFile in Directory.GetFiles(dir.ToString(), mask, so).Where(file => Regex.IsMatch(file, @"^.+\.(cpp|hpp|hxx|gcpp|icpp|c|h)$"))             )
                foreach (string sourceFile in   _aSourceFile)
                {
                    FileInfo srcFile     = new FileInfo(sourceFile);
                    string   srcFileName = srcFile.Name;

                    // Create a destination that matches the source structure
                    string _sFileRelPath = _sDestFileName;
                    if (_sDestFileName == "")
                    {
                        _sFileRelPath = srcFile.FullName.Replace(sourceFolder, "");
                    }


                    FileInfo destFile = new FileInfo(destinationFolder + _sFileRelPath);

                    if (!Directory.Exists(destFile.DirectoryName) && createFolders)
                    {
                        Directory.CreateDirectory(destFile.DirectoryName);
                    }

                    if (!destFile.Exists || srcFile.LastWriteTime > destFile.LastWriteTime)
                    {
                        File.Copy(srcFile.FullName, destFile.FullName, true);
                        Output.Trace("\f3FCopy: \f37 " + _sFileRelPath);
                    }
                }
            }
            catch (Exception ex)
            {
                //   System.Diagnostics.Debug.WriteLine(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace);
                //Debug.fTrace("Error copy: " + ex.Message + " "  + ex.StackTrace);
                Output.TraceError("Error copy: " + ex.Message + " " + ex.StackTrace);
            }
        }
Exemplo n.º 11
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("");
        }
Exemplo n.º 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();
        }