Example #1
0
        public void onFinishCompile(TCommand cmd, TCompileResult res)
        {
            lock (m_lock)
            {
                if (m_countCompile == -1)
                {
                    return;
                }

                m_countCompile++;
                CConsole.writeInfo(m_countCompile + "/" + m_totalCompile + ". " + cmd.prjName + ". Compile: " + cmd.alias);

                if (m_isVerbose && !string.IsNullOrEmpty(cmd.verboseString))
                {
                    CConsole.writeVerbose("\n" + cmd.verboseString);
                }
                if (!string.IsNullOrEmpty(res.host))
                {
                    CConsole.writeMongcc(" (" + res.host + ")");
                }

                bool success = checkProcessResult(res);

                CConsole.writeLine();
                if (!success)
                {
                    m_countCompile = -1;
                    m_batchingCompiler.signalToStop(false);
                }
            }
        }
Example #2
0
        /// <summary>
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="workingDir"></param>
        /// <returns></returns>
        public TCompileResult compile(string cmd, string workingDir)
        {
            TCompileResult res = null;

            if (!isAllowCompiling())
            {
                res = new TCompileResult(false, 1, "error: Compiling is stopped!", 0, null);
            }

            setLast(0);

            Remote remote = selectBestRemote();

            if (remote == null)
            {
                res = new TCompileResult(false, 1, "error: Overloading, current MONGCC_MAX_JOBS=" + m_config.maxJobs
                                         + ", but your own jobs is greater!", 0, null);
            }
            else
            {
                res = remote.compile(cmd, workingDir);
                if (m_config.enable && (m_config.hosts == null || m_config.hosts.Length == 0))
                {
                    res.outputText = "warning: MONGCC_HOSTS is empty!\n" + res.outputText;
                }
            }

            setLast();
            return(res);
        }
Example #3
0
        private void processStream(Stream stream)
        {
            MessageStream msgStream = new MessageStream(new StandardStream(stream));

            Message msg = msgStream.readMessage();

            if (msg == null)
            {
                return;
            }

            EMessageType mType = (EMessageType)msg.getType();

            if (mType == EMessageType.eNumber)
            {
                // End a session
                MessageNumber response = new MessageNumber(msg);
                int           sid      = response.getNumber();
                m_agent.signalToStopSession(sid);
            }
            else if (mType == EMessageType.ePidAndCompileRequest)
            {
                MessagePidAndCompileRequest request = new MessagePidAndCompileRequest(msg);
                TCompileResult cr = m_agent.compile(request.getPid(), request.getCmd(), request.getWorkingDir());

                // The output file was already saved to local disk by the agent, now respond the result only
                msg = MessageCompileResponse.createMessage(cr.wasExec, cr.exitCode, cr.outputText, null, 0);
                msgStream.writeMessage(msg);
            }
            else
            {
                // WTF???
            }
        }
Example #4
0
 private void doLocal(string cmd, string workingDir, string outputFilePath, ref int oldTick, ref TProcessResult res)
 {
     if (isAllowCompiling())
     {
         oldTick = SystemUtils.getCurrentTimeMs();
         res     = m_processHelper.execute(cmd, workingDir, outputFilePath);
     }
     else
     {
         res = new TCompileResult(false, 1, "error: Compiling is stopped!", 0, null);
     }
 }
Example #5
0
        //========================================================================================

        private void callback()
        {
            TCommand cmd;

            while ((cmd = m_commandPool.getNextCommand()) != null)
            {
                TCompileResult res = m_agent.compile(s_kSID, cmd.command, cmd.workingDir);

                if (m_notifier != null)
                {
                    m_notifier.onFinishCompile(cmd, res);
                }

                if (isForcingStop())
                {
                    break;
                }
            }

            setRunning(false);
        }
Example #6
0
        /// <summary>
        /// Make sure isCompiling() == true as setCompilingTrue() was called
        /// Make sure all parameters are not null
        /// Make sure this method is thread-safety: it cannot be called at the same time
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="workingDir"></param>
        /// <returns></returns>
        public TCompileResult compile(string cmd, string workingDir)
        {
            int oldTick = SystemUtils.getCurrentTimeMs();

            ICmdParser parser = CmdParserFactory.createCmdParser(cmd);

            List <string> inputFilePaths = null;
            string        outputFilePath = null;

            TCompileResult result = null;

            if (!isAllowCompiling())
            {
                result = new TCompileResult(false, 1, "error: Compiling is stopped!", 0, null); goto my_end;
            }

            try
            {
                parser.getInOutFilePath(workingDir, out inputFilePaths, out outputFilePath);
            }
            catch (Exception ex)
            {
                // Error
                result = new TCompileResult(false, 1, "error: " + ex.Message, 0, null);
                goto my_end;
            }

            if (inputFilePaths == null || inputFilePaths.Count == 0 || outputFilePath == null)
            {
                // Error
                result = new TCompileResult(false, 1, "error: Invalid command, input file is mandatory!", 0, null);
                goto my_end;
            }

            outputFilePath = PathUtils.combine(workingDir, outputFilePath);

            if (!isConnected())
            {
                // Local
                goto my_end;
            }

            #region Distribute

            // Send the input files to server
            foreach (string inputFilePath in inputFilePaths)
            {
                string f       = PathUtils.combine(workingDir, inputFilePath);
                string fNormal = PathUtils.normalizePath(f);
                if (!m_sentFiles.Contains(fNormal))
                {
                    if (sendFile(f))
                    {
                        m_sentFiles.Add(fNormal);
                    }
                    else
                    {
                        // Local
                        goto my_end;
                    }
                }
            }

            // Send compile request to server
            string  cmdToSend = parser.makeNetworkCmd();
            Message msg       = MessageCompileRequest.createMessage(cmdToSend);
            if (!m_messageStream.writeMessage(msg))
            {
                goto my_end;
            }

            if (!isAllowCompiling())
            {
                result = new TCompileResult(false, 1, "error: Compiling is stopped!", 0, null); goto my_end;
            }

            // Receive the compile result
            msg = m_messageStream.readMessage();
            if (msg == null)
            {
                goto my_end;
            }

            if (!isAllowCompiling())
            {
                result = new TCompileResult(false, 1, "error: Compiling is stopped!", 0, null); goto my_end;
            }

            // Parse and check the compile result
            MessageCompileResponse msgCompileRes = new MessageCompileResponse(msg);

            if (msgCompileRes.getWasExec() && msgCompileRes.getExitCode() != 0)
            {
                // Compile error
                // Nghia: TODO rem this for the hot fix
                //result = new TCompileResult(true, msgCompileRes.getExitCode(), msgCompileRes.getOutputText(), 0, m_host);
                goto my_end;
            }
            if (!msgCompileRes.getWasExec())
            {
                goto my_end;
            }

            // Compile OK by server
            // Save the file to disk
            if (!IOUtils.writeFile_Bytes(outputFilePath, msgCompileRes.getOFileData(),
                                         msgCompileRes.getOFileOffset(), msgCompileRes.getOFileSize()))
            {
                // No need to compile local as this is a serious error
                result = new TCompileResult(true, 1, "error: Could not save the output file to disk", 0, m_host);
                goto my_end;
            }

            // Everything is OK
            result = new TCompileResult(true, 0,
                                        "Remotely compiled from " + m_host + "\n" + msgCompileRes.getOutputText(), 0, m_host);

            #endregion

my_end:

            if (result == null)
            {
                // Local
                string specOutFilePath = parser.getLocalSpecificOutputFilePath();
                string specCmd         = parser.getLocalSpecificCommand();
                string specWorkingDir  = parser.getLocalSpecificWorkingDir();

                if (specOutFilePath == null)
                {
                    specOutFilePath = outputFilePath;
                }
                if (specCmd == null)
                {
                    specCmd = cmd;
                }
                if (specWorkingDir == null)
                {
                    specWorkingDir = workingDir;
                }

                specOutFilePath = PathUtils.combine(specWorkingDir, specOutFilePath);

                TProcessResult res = null;

                if (parser.needToLockLocal())
                {
                    lock (s_lock)
                    {
                        doLocal(specCmd, specWorkingDir, specOutFilePath, ref oldTick, ref res);
                    }
                }
                else
                {
                    doLocal(specCmd, specWorkingDir, specOutFilePath, ref oldTick, ref res);
                }

                result = new TCompileResult(res.wasExec, res.exitCode, "Locally compiled\n" + res.outputText, 0, null);

                if (result.wasExec && result.exitCode == 0 && specOutFilePath != outputFilePath)
                {
                    File.Move(specOutFilePath, outputFilePath);
                }
            }

            result.spentTimeMs = SystemUtils.getCurrentTimeMs() - oldTick;

            setCompiling(false);

            return(result);
        }