//FIXME: Check whether autogen.sh is required or not
		protected override BuildResult Build (IProgressMonitor monitor, SolutionEntityItem entry, ConfigurationSelector configuration)
		{
			Project project = entry as Project;
			if (project == null)
				return base.Build (monitor, entry, configuration);

			MakefileData data = project.ExtendedProperties ["MonoDevelop.Autotools.MakefileInfo"] as MakefileData;
			if (data == null || !data.SupportsIntegration || String.IsNullOrEmpty (data.BuildTargetName))
				return base.Build (monitor, entry, configuration);

			//FIXME: Gen autofoo ? autoreconf?

			string output = String.Empty;
			int exitCode = 0;
			monitor.BeginTask (GettextCatalog.GetString ("Building {0}", project.Name), 1);
			try {
				string baseDir = project.BaseDirectory;
				StringBuilder args = new StringBuilder ();
				
				if (data.RelativeMakeCommand.EndsWith ("make", StringComparison.OrdinalIgnoreCase))
					args.AppendFormat (" -j {0}", data.ParallelProcesses, data.BuildTargetName);
				args.AppendFormat (" {0}", data.BuildTargetName);
	
				StringWriter swOutput = new StringWriter ();
				LogTextWriter chainedOutput = new LogTextWriter ();
				chainedOutput.ChainWriter (monitor.Log);
				chainedOutput.ChainWriter (swOutput);
				
				ProcessWrapper process = Runtime.ProcessService.StartProcess (data.AbsoluteMakeCommand, 
						args.ToString (), 
						baseDir, 
						chainedOutput, 
						chainedOutput, 
						null);
				process.WaitForOutput ();

				exitCode = process.ExitCode;
				output = swOutput.ToString ();
				chainedOutput.Close ();
				swOutput.Close ();
				monitor.Step (1);
			} catch (Exception e) {
				monitor.ReportError (GettextCatalog.GetString ("Project could not be built: "), e);
				return null;
			} finally {
				monitor.EndTask ();
			}

			TempFileCollection tf = new TempFileCollection ();
			Regex regexError = data.GetErrorRegex (false);
			Regex regexWarning = data.GetWarningRegex (false);

			BuildResult cr = ParseOutput (tf, output, project.BaseDirectory, regexError, regexWarning);
			if (exitCode != 0 && cr.FailedBuildCount == 0)
				cr.AddError (GettextCatalog.GetString ("Build failed. See Build Output panel."));
			else
				entry.SetNeedsBuilding (false, configuration);

			return cr;
		}
		//copied from MoonlightBuildExtension
		public static int ExecuteCommand (IProgressMonitor monitor, System.Diagnostics.ProcessStartInfo startInfo, out string errorOutput)
		{
			startInfo.UseShellExecute = false;
			startInfo.RedirectStandardError = true;
			startInfo.RedirectStandardOutput = true;
			
			errorOutput = string.Empty;
			int exitCode = -1;
			
			var swError = new StringWriter ();
			var chainedError = new LogTextWriter ();
			chainedError.ChainWriter (monitor.Log);
			chainedError.ChainWriter (swError);
			
			var operationMonitor = new AggregatedOperationMonitor (monitor);
			
			try {
				var p = Runtime.ProcessService.StartProcess (startInfo, monitor.Log, chainedError, null);
				operationMonitor.AddOperation (p); //handles cancellation
				
				p.WaitForOutput ();
				errorOutput = swError.ToString ();
				exitCode = p.ExitCode;
				p.Dispose ();
				
				if (monitor.IsCancelRequested) {
					monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
					monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
					if (exitCode == 0)
						exitCode = -1;
				}
			} finally {
				chainedError.Close ();
				swError.Close ();
				operationMonitor.Dispose ();
			}
			
			return exitCode;
		}
示例#3
0
        /// <summary>
        /// Executes a file and reports events related to the execution to the 'monitor' passed in the parameters.
        /// </summary>
        static int ExecuteCommand(
            string command,
            string args,
            string baseDirectory,

            IProgressMonitor monitor,
            out string errorOutput,
            out string programOutput)
        {
            errorOutput = string.Empty;
            int exitCode = -1;

            var swError = new StringWriter ();
            var swOutput = new StringWriter ();

            var chainedError = new LogTextWriter ();
            chainedError.ChainWriter (monitor.Log);
            chainedError.ChainWriter (swError);

            var chainedOutput = new LogTextWriter ();
            chainedOutput.ChainWriter (monitor.Log);
            chainedOutput.ChainWriter (swOutput);

            monitor.Log.WriteLine ("{0} {1}", command, args);

            var operationMonitor = new AggregatedOperationMonitor (monitor);
            var p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, chainedOutput, chainedError, null);
            operationMonitor.AddOperation (p); //handles cancellation

            p.WaitForOutput ();
            errorOutput = swError.ToString ();
            programOutput = swOutput.ToString ();
            exitCode = p.ExitCode;
            p.Dispose ();

            if (monitor.IsCancelRequested) {
                monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
                monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
                if (exitCode == 0)
                    exitCode = -1;
            }
            {
                chainedError.Close ();
                swError.Close ();
                operationMonitor.Dispose ();
            }

            return exitCode;
        }
示例#4
0
        /// <summary>
        /// Executes a file and reports events related to the execution to the 'monitor' passed in the parameters.
        /// </summary>
        public static int ExecuteCommand(
            string command,
            string args,
            string baseDirectory,

            IProgressMonitor monitor,
            out string errorOutput,
            out string programOutput)
        {
            bool useMonitor = monitor != null;
            errorOutput = string.Empty;
            int exitCode = -1;

            var swError = new StringWriter ();
            var swOutput = new StringWriter ();

            var chainedError = new LogTextWriter ();
            chainedError.ChainWriter (swError);

            var chainedOutput = new LogTextWriter ();
            chainedOutput.ChainWriter (swOutput);

            if (useMonitor) {
                chainedError.ChainWriter (monitor.Log);
                chainedOutput.ChainWriter (monitor.Log);
                monitor.Log.WriteLine ("{0} {1}", command, args);
            }

            // Workaround for not handling %PATH% env var expansion properly
            if (!command.Contains(Path.DirectorySeparatorChar))
                command = TryExpandPathEnvVariable(command, baseDirectory);

            var operationMonitor = useMonitor ? new AggregatedOperationMonitor (monitor) : null;
            var p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, chainedOutput, chainedError, null);
            if(useMonitor)
                operationMonitor.AddOperation (p); //handles cancellation

            p.WaitForOutput ();
            swError.Flush ();
            swOutput.Flush ();
            errorOutput = swError.ToString ();
            programOutput = swOutput.ToString ();
            exitCode = p.ExitCode;
            p.Dispose ();

            if (useMonitor) {
                if (monitor.IsCancelRequested) {
                    monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
                    monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
                    if (exitCode == 0)
                        exitCode = -1;
                }

                operationMonitor.Dispose ();
            }

            chainedError.Close ();
            swOutput.Close ();
            swError.Close ();

            return exitCode;
        }