/// <summary> /// Request the active build process to update. /// Returns <see langword="true"/> to indicate that it must be called again, otherwise <see langword="false"/> to indicate that the build has completed. /// </summary> /// <returns><see langword="true"/> if <see cref="Update"/> must be called again, otherwise <see langword="false"/>.</returns> public bool Update() { if (IsCompleted) { return(false); } if (!m_Timer.IsRunning) { m_Timer.Restart(); } try { Result = m_OnBuild(m_Context); } catch (Exception exception) { Result = m_Context.Failure(exception); } if (!IsCompleted) { return(true); } m_Timer.Stop(); Result.Duration = m_Timer.Elapsed; BuildArtifacts.Store(Result, m_Context.Values.OfType <IBuildArtifact>().ToArray()); return(false); }
/// <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); } }