Example #1
0
 /// <nodoc />
 public void StartBuild(BuildStartArguments buildStartArguments)
 {
     lock (m_syncLock)
     {
         if (m_currentBuild == null)
         {
             m_processIdSource          = new TaskCompletionSource <int>();
             m_buildInitiator           = new TaskCompletionSource <bool>();
             m_currentBuildCancellation = new CancellationTokenSource();
             m_currentBuildCancellation.Token.Register(() => m_buildInitiator.TrySetCanceled());
             m_currentBuild  = StartBuildCoreAsync(buildStartArguments, m_currentBuildCancellation.Token);
             BuildInProgress = true;
         }
     }
 }
Example #2
0
        /// <nodoc />
        public void StartBuild(BuildStartArguments buildStartArguments)
        {
            lock (m_syncLock)
            {
                if (m_currentBuild == null)
                {
                    m_processIdSource          = new TaskCompletionSource <int>();
                    m_buildInitiator           = new TaskCompletionSource <bool>();
                    m_currentBuildCancellation = new CancellationTokenSource();

                    // Ignoring the result because we don't need to dispose the CancellationTokenRegistration obtained from that call
                    // because the token is created from a CancellationTokenSource that won't outlive the current instance.
                    _ = m_currentBuildCancellation.Token.Register(() => m_buildInitiator.TrySetCanceled());
                    m_currentBuild  = StartBuildCoreAsync(buildStartArguments, m_currentBuildCancellation.Token);
                    BuildInProgress = true;
                }
            }
        }
Example #3
0
        private Process StartBuildProcess(BuildStartArguments buildStartArgs)
        {
            if (!File.Exists(m_ideBuildCommandPath))
            {
                m_host.WriteBuildMessage($"Warning:  Skipping build. Could not find build command file at: {m_ideBuildCommandPath}.");
                return(null);
            }

            var commandArguments = string.Format(CultureInfo.InvariantCulture, "/C \"{0}\"", m_ideBuildCommandPath);

            m_host.WriteBuildMessage($"Running command: {commandArguments}");

            var specFilters = "/f:" + string.Join(" or ", m_filtersByProject.Values);

            File.WriteAllText($"{m_ideBuildCommandPath}.rsp", specFilters);

            var process          = new Process();
            var processStartInfo = new ProcessStartInfo("cmd", commandArguments)
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
            };

            process.StartInfo           = processStartInfo;
            process.OutputDataReceived += (sender, args) => WriteBuildMessage(args.Data);
            process.ErrorDataReceived  += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(args.Data))
                {
                    m_host.WriteBuildMessage(args.Data);
                }
            };

            process.Start();

            // Start both the stream readers asynchronously
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            return(process);
        }
Example #4
0
        private async Task <bool> StartBuildCoreAsync(BuildStartArguments buildStartArgs, CancellationToken cancellationToken)
        {
            try
            {
                // This task will be triggered once the last project is building
                await m_buildInitiator.Task;

                if (string.IsNullOrEmpty(m_ideFolderPath))
                {
                    m_host.WriteBuildMessage($"Error: No IDE folder path set. Is a solution open?");
                    return(false);
                }

                var buildProcess = StartBuildProcess(buildStartArgs);
                if (buildProcess == null)
                {
                    return(true);
                }

                m_buildProcess         = buildProcess;
                using var registration = cancellationToken.Register(() => CancelBuildProcess(buildProcess));
                var result = await WaitForProcessExitAsync(buildProcess, cancellationToken);

                return(result);
            }
            catch (OperationCanceledException)
            {
                // Do nothing
                return(false);
            }
            catch (Exception ex)
            {
                m_host.WriteBuildMessage($"Error: Starting build.\n{ex.ToString()}");
                return(false);
            }
            finally
            {
                EndBuild();
            }
        }