Example #1
0
        public async Task BuildSolution(string target)
        {
            State = AppState.Building;
            BuildStarted?.Invoke(this, EventArgs.Empty);

            var results = new List <Microsoft.Build.Execution.BuildResult>();

            await Task.Factory.StartNew(() =>
            {
                ClearOutput();

                var msbuild = Microsoft.Build.Execution.BuildManager.DefaultBuildManager;
                var projs   = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;

                projs.AddToolset(new Microsoft.Build.Evaluation.Toolset("Current", Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion), projs, Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion)));

                var globalProperties = new Dictionary <string, string>()
                {
                    { "Configuration", SelectedConfiguration },
                    { "PlatformTarget", SelectedPlatform }
                };

                foreach (var proj in this.Workspace.CurrentSolution.Projects)
                {
                    projs.LoadProject(proj.FilePath);
                }

                var parameters = new Microsoft.Build.Execution.BuildParameters(projs);

                var loggers = new List <Microsoft.Build.Framework.ILogger>();
                var cl      = new Microsoft.Build.Logging.ConsoleLogger(Microsoft.Build.Framework.LoggerVerbosity.Normal, new Microsoft.Build.Logging.WriteHandler((s) => MSBuildLog(s)), new Microsoft.Build.Logging.ColorSetter((c) => MSBuildLogSetColor(c)), new Microsoft.Build.Logging.ColorResetter(() => MSBuildLogResetColor()));

                loggers.Add(cl);

                parameters.Loggers = loggers;

                msbuild.BeginBuild(parameters);

                var targets = new[] { target };

                if (!target.Equals("restore", StringComparison.OrdinalIgnoreCase) && !target.Equals("clean", StringComparison.OrdinalIgnoreCase))
                {
                    targets = new[] { "restore", target };
                }

                foreach (var p in Workspace.ProjectInstances)
                {
                    var pinstance   = new Microsoft.Build.Execution.ProjectInstance(p.FullPath, globalProperties, projs.DefaultToolsVersion, projs);
                    var requestData = new Microsoft.Build.Execution.BuildRequestData(pinstance, targets);

                    results.Add(msbuild.BuildRequest(requestData));
                }

                msbuild.EndBuild();
            });

            State = AppState.SolutionReady;
            BuildFinished?.Invoke(this, EventArgs.Empty);
            OnBuildFinished(results);
        }
Example #2
0
        /// <summary>
        /// Build this <see cref="BuildPipeline"/>.
        /// </summary>
        /// <param name="config">The <see cref="BuildConfiguration"/> used for the build.</param>
        /// <param name="progress">Optional build progress that will be displayed when executing the build.</param>
        /// <param name="mutator">Optional mutator that can be used to modify the <see cref="BuildContext"/> before building.</param>
        /// <returns>The result of building this <see cref="BuildPipeline"/>.</returns>
        public BuildPipelineResult Build(BuildConfiguration config, BuildProgress progress = null, Action <BuildContext> mutator = null)
        {
            if (EditorApplication.isCompiling)
            {
                throw new InvalidOperationException("Building is not allowed while Unity is compiling.");
            }

            if (!CanBuild(config, out var reason))
            {
                return(BuildPipelineResult.Failure(this, config, reason));
            }

            BuildStarted?.Invoke(this, config);
            using (var context = new BuildContext(this, config, progress, mutator))
            {
                var timer  = Stopwatch.StartNew();
                var result = RunBuildSteps(context);
                timer.Stop();

                result.Duration = timer.Elapsed;

                var firstFailedBuildStep = result.BuildStepsResults.FirstOrDefault(r => r.Failed);
                if (firstFailedBuildStep != null)
                {
                    result.Succeeded = false;
                    result.Message   = firstFailedBuildStep.Message;
                }

                BuildArtifacts.Store(result, context.Values.OfType <IBuildArtifact>().ToArray());
                BuildCompleted?.Invoke(result);
                return(result);
            }
        }
Example #3
0
        private static void OnPreProcessBuild(BuildInfo buildInfo)
        {
            // Raise the global event for listeners
            BuildStarted?.Invoke(buildInfo);

            // Call the pre-build action, if any
            buildInfo.PreBuildAction?.Invoke(buildInfo);
        }
Example #4
0
        /// <summary>
        /// Raise one of the events that is appropriate for the type of the BuildEventArgs
        /// </summary>
        public void Dispatch(BuildEventArgs buildEvent)
        {
            if (buildEvent is BuildMessageEventArgs)
            {
                MessageRaised?.Invoke(null, (BuildMessageEventArgs)buildEvent);
            }
            else if (buildEvent is TaskStartedEventArgs)
            {
                TaskStarted?.Invoke(null, (TaskStartedEventArgs)buildEvent);
            }
            else if (buildEvent is TaskFinishedEventArgs)
            {
                TaskFinished?.Invoke(null, (TaskFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is TargetStartedEventArgs)
            {
                TargetStarted?.Invoke(null, (TargetStartedEventArgs)buildEvent);
            }
            else if (buildEvent is TargetFinishedEventArgs)
            {
                TargetFinished?.Invoke(null, (TargetFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is ProjectStartedEventArgs)
            {
                ProjectStarted?.Invoke(null, (ProjectStartedEventArgs)buildEvent);
            }
            else if (buildEvent is ProjectFinishedEventArgs)
            {
                ProjectFinished?.Invoke(null, (ProjectFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is BuildStartedEventArgs)
            {
                BuildStarted?.Invoke(null, (BuildStartedEventArgs)buildEvent);
            }
            else if (buildEvent is BuildFinishedEventArgs)
            {
                BuildFinished?.Invoke(null, (BuildFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is CustomBuildEventArgs)
            {
                CustomEventRaised?.Invoke(null, (CustomBuildEventArgs)buildEvent);
            }
            else if (buildEvent is BuildStatusEventArgs)
            {
                StatusEventRaised?.Invoke(null, (BuildStatusEventArgs)buildEvent);
            }
            else if (buildEvent is BuildWarningEventArgs)
            {
                WarningRaised?.Invoke(null, (BuildWarningEventArgs)buildEvent);
            }
            else if (buildEvent is BuildErrorEventArgs)
            {
                ErrorRaised?.Invoke(null, (BuildErrorEventArgs)buildEvent);
            }

            AnyEventRaised?.Invoke(null, buildEvent);
        }
Example #5
0
        static BuildPipelineResult RunSteps(BuildContext context, IReadOnlyCollection <IBuildStep> steps)
        {
            if (EditorApplication.isCompiling)
            {
                throw new InvalidOperationException("Building is not allowed while Unity is compiling.");
            }

            if (context.BuildSettings == null)
            {
                throw new NullReferenceException($"{nameof(BuildSettings)} object is null in {nameof(context)}.");
            }

            if (context.BuildPipeline == null)
            {
                throw new NullReferenceException($"{nameof(BuildPipeline)} object is null in {nameof(context)}.");
            }

            // Work-around for assets that can be garbage collected during a build
            context.BuildSettings.GCPin();
            context.BuildPipeline.GCPin();

            //@TODO: It is unlikely that anything here will actually throw.
            //     We should probably review the code and ensuree that it definitely can't and remove this.
            try
            {
                BuildStarted.Invoke(context);

                var timer = Stopwatch.StartNew();
                RunBuildSteps(context, steps);
                timer.Stop();

                var status = context.BuildPipelineStatus;
                status.Duration      = timer.Elapsed;
                status.BuildSettings = context.BuildSettings;

                var failedStep = status.GetFirstFailedBuildStep();
                if (failedStep.Failed)
                {
                    status.Succeeded = false;
                    status.Message   = failedStep.Message;
                }

                BuildCompleted.Invoke(context);

                status.LogResult();
            }
            finally
            {
                // Work-around for assets that can be garbage collected during a build
                context.BuildSettings.GCUnPin();
                context.BuildPipeline.GCUnPin();
            }

            return(context.BuildPipelineStatus);
        }
Example #6
0
        private static bool Publish(BuildInfo buildInfo)
        {
            if (_buildInProgress != null)
            {
                throw new InvalidOperationException("A build is already in progress.");
            }

            _buildInProgress = buildInfo;

            try
            {
                BuildStarted?.Invoke(buildInfo);

                // Required in order to update the build tasks list
                Internal.GodotMainIteration();

                try
                {
                    RemoveOldIssuesFile(buildInfo);
                }
                catch (IOException e)
                {
                    BuildLaunchFailed?.Invoke(buildInfo, $"Cannot remove issues file: {GetIssuesFilePath(buildInfo)}");
                    Console.Error.WriteLine(e);
                }

                try
                {
                    int exitCode = BuildSystem.Publish(buildInfo, StdOutputReceived, StdErrorReceived);

                    if (exitCode != 0)
                    {
                        PrintVerbose(
                            $"dotnet publish exited with code: {exitCode}. Log file: {GetLogFilePath(buildInfo)}");
                    }

                    BuildFinished?.Invoke(exitCode == 0 ? BuildResult.Success : BuildResult.Error);

                    return(exitCode == 0);
                }
                catch (Exception e)
                {
                    BuildLaunchFailed?.Invoke(buildInfo,
                                              $"The publish method threw an exception.\n{e.GetType().FullName}: {e.Message}");
                    Console.Error.WriteLine(e);
                    return(false);
                }
            }
            finally
            {
                _buildInProgress = null;
            }
        }
Example #7
0
        public static async Task <bool> BuildAsync(BuildInfo buildInfo)
        {
            if (_buildInProgress != null)
            {
                throw new InvalidOperationException("A build is already in progress.");
            }

            _buildInProgress = buildInfo;

            try
            {
                BuildStarted?.Invoke(buildInfo);

                try
                {
                    RemoveOldIssuesFile(buildInfo);
                }
                catch (IOException e)
                {
                    BuildLaunchFailed?.Invoke(buildInfo, $"Cannot remove issues file: {GetIssuesFilePath(buildInfo)}");
                    Console.Error.WriteLine(e);
                }

                try
                {
                    int exitCode = await BuildSystem.BuildAsync(buildInfo, StdOutputReceived, StdErrorReceived);

                    if (exitCode != 0)
                    {
                        PrintVerbose($"MSBuild exited with code: {exitCode}. Log file: {GetLogFilePath(buildInfo)}");
                    }

                    BuildFinished?.Invoke(exitCode == 0 ? BuildResult.Success : BuildResult.Error);

                    return(exitCode == 0);
                }
                catch (Exception e)
                {
                    BuildLaunchFailed?.Invoke(buildInfo,
                                              $"The build method threw an exception.\n{e.GetType().FullName}: {e.Message}");
                    Console.Error.WriteLine(e);
                    return(false);
                }
            }
            finally
            {
                _buildInProgress = null;
            }
        }
        public BuildProcess BuildAsync()
        {
            string errors = null;

            if (!CanBuild(ref errors))
            {
                Debug.LogError(errors);
                return(null);
            }

            BuildStarted?.Invoke();

            m_CurrentBuildProcess = new BuildProcess(this);
            m_CurrentBuildProcess.BuildStopped += OnBuildStopped;
            return(m_CurrentBuildProcess);
        }
        /// <summary>
        /// Builds the binary for this asset
        /// </summary>
        public void BuildSync()
        {
            EditorUtility.DisplayProgressBar($"Building Kinematica Asset {name}.asset", "", 0.0f);

            using (BuildProcess buildProcess = BuildAsync())
            {
                BuildStarted?.Invoke();
                buildProcess.Builder.progressFeedback += progressInfo => EditorUtility.DisplayProgressBar($"Building Kinematica Asset {name}.asset", progressInfo.title, progressInfo.progress);

                while (!buildProcess.IsFinished)
                {
                    buildProcess.FrameUpdate();
                }

                BuildStopped?.Invoke();
            }

            EditorUtility.ClearProgressBar();
        }
Example #10
0
 private void OnBuildBegin(vsBuildScope scope, vsBuildAction action)
 {
     LastBuildTime = DateTime.Now;
     IsBuilding    = true;
     BuildStarted?.Invoke(this, EventArgs.Empty);
 }
 static void Initialize()
 {
     BuildPipeline.BuildStarted   += (pipeline, settings) => BuildStarted?.Invoke(pipeline, settings);
     BuildPipeline.BuildCompleted += (result) => BuildCompleted?.Invoke(result);
 }
Example #12
0
 protected virtual void OnBuildStarted(EventArgs args)
 {
     BuildStarted?.Invoke(this, args);
 }
 private void RaiseBuildStarted(bool started)
 {
     BuildStarted?.Invoke(this, started);
 }
 // ReSharper disable once UnusedMember.Local
 private void OnBuildStarted(BuildStartedEventArgs e)
 {
     BuildStarted?.Invoke(this, e);
 }
Example #15
0
 private void EventSourceOnBuildStarted(object sender, BuildStartedEventArgs e)
 {
     BuildStarted?.Invoke(sender, e);
 }
Example #16
0
 public void StartBuild(DateTime time)
 {
     _logger.LogDebug($"BuildProcess.StartBuild: {time}");
     StartTime = time;
     BuildStarted?.Invoke();
 }
Example #17
0
 private void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
 {
     IsBuilding = true;
     BuildStarted?.Invoke(this, EventArgs.Empty);
 }