Beispiel #1
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();
        }
Beispiel #2
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("");
        }
Beispiel #3
0
        public void fCompleteExtractMainArgument(ModuleData _oModule = null, bool _bShowInfo = true)
        {
            Build.fEnableBuild();


            ///Check missing modules lib
            //if(Data.aCompilerData.Count == 0){


            //}

            //		fLibRtExist();
            //fGZE_Exist();

            if (Data.bModuleIsRequired || Data.bDontExecute) //Stop if we need more modules
            {
                Build.fDisableBuild();
                return;
            }


            if (_bShowInfo)
            {
                if (_oModule == null)
                {
                    Output.Trace("\f2A--Start Build--");
                }
                else
                {
                    // Output.Trace("\f27 - Build " + _oModule.sAutorName + " - " + _oModule.sCurrFolder + " - " );
                    Output.Trace("\f2B - Build " + _oModule.sAutorName + " - " + _oModule.sCurrFolder + " - ");
                }
            }

            ///////////////// Extract Compilers
            fExtractCompiler();

            if (Data.bModuleIsRequired) //For compiler with "Require" Node //TODO recursive
            {
                if (!Empty.fLoadModules(false))
                {
                    Build.fDisableBuild();
                    return;
                }

                Data.bModuleIsRequired = false;
                Data.aRequiredModule.Clear();

                //  Empty.fLoadModules(false);//Reload after download, or look for bExtracting before fGetLastVersions
                fMergeCompiler();
            }
            fExtractCompiler();



            foreach (CompilerData _oLib in  aLibList)              //TODO separate subcompiler and extract after!?
            //Console.WriteLine("Extract Lib: " + _oLib.sFullName);
            {
                Debug.fTrace("Extract Lib: " + _oLib.sFullName);
                _oLib.fExtract(this);
            }


            /////////////////////////////
            //Output.Trace("\f2A-Extracted--");

            /*
             *       foreach(CppSeq _oSeq in aCppSeq) {
             *                      sCurr_wTo = "";
             *                      foreach(CppCmd _oCmd in _oSeq.aCppCmd) {
             *                              //	_oCmd.fExtract();
             *                      }
             *              }
             */


            ArgProcess.fFinishExtractArg();
        }