public override BuildStepResult RunBuildStep(BuildContext context) { m_TemporaryFileTracker = new TemporaryFileTracker(); // Delete SubScenes build folder defensively (Eg. if unity crashes during build) var streamingAssetsSubscenes = "Assets/StreamingAssets/SubScenes"; FileUtil.DeleteFileOrDirectory(streamingAssetsSubscenes); m_TemporaryFileTracker.CreateDirectory(streamingAssetsSubscenes); List <(string sourceFile, string destinationFile)> filesToCopy = new List <(string sourceFile, string destinationFile)>(); void RegisterFileCopy(string sourceFile, string destinationFile) { filesToCopy.Add((sourceFile, destinationFile)); } SubSceneBuildCode.PrepareAdditionalFiles(BuildContextInternals.GetBuildConfigurationGUID(context), type => GetRequiredComponent(context, type), RegisterFileCopy, Application.streamingAssetsPath, $"Library/SubsceneBundles"); foreach (var(sourceFile, targetFile) in filesToCopy) { m_TemporaryFileTracker.TrackFile(targetFile); File.Copy(sourceFile, targetFile, true); } return(Success()); }
public override BuildStepResult CleanupBuildStep(BuildContext context) { m_TemporaryFileTracker.Dispose(); return(Success()); }
public IEnumerable <IBuildComponent> GetRequiredComponents(BuildContext context, Type type) => throw null;
public IEnumerable <T> GetRequiredComponents <T>(BuildContext context) where T : IBuildComponent => throw null;
public IBuildComponent GetRequiredComponent(BuildContext context, Type type) => throw null;
public T GetRequiredComponent <T>(BuildContext context) where T : IBuildComponent => throw null;
public bool HasRequiredComponent(BuildContext context, Type type) => throw null;
public virtual BuildStepResult CleanupBuildStep(BuildContext context) => throw null;
public abstract BuildStepResult RunBuildStep(BuildContext context);
public virtual bool IsEnabled(BuildContext context) => throw null;
BuildPipelineResult RunBuildSteps(BuildContext context) { var timer = new Stopwatch(); var status = context.BuildPipelineStatus; var title = context.BuildProgress?.Title ?? string.Empty; // Setup build steps list var cleanupSteps = new Stack <BuildStep>(); var enabledSteps = EnumerateBuildSteps().Where(step => step.IsEnabled(context)).ToArray(); // Run build steps and stop on first failure of any kind for (var i = 0; i < enabledSteps.Length; ++i) { var step = enabledSteps[i]; // Update build progress var cancelled = context.BuildProgress?.Update($"{title} (Step {i + 1} of {enabledSteps.Length})", step.Description + "...", (float)i / enabledSteps.Length) ?? false; if (cancelled) { status.Succeeded = false; status.Message = $"{title} was cancelled."; break; } // Add step to cleanup stack only if it overrides implementation if (step.GetType().GetMethod(nameof(BuildStep.CleanupBuildStep)).DeclaringType != typeof(BuildStep)) { cleanupSteps.Push(step); } // Run build step try { timer.Restart(); var result = step.RunBuildStep(context); timer.Stop(); // Update build step duration result.Duration = timer.Elapsed; // Add build step result to pipeline status status.BuildStepsResults.Add(result); // Stop execution for normal build steps after failure if (!result.Succeeded) { break; } } catch (Exception exception) { // Add build step exception to pipeline status, and stop executing build steps status.BuildStepsResults.Add(BuildStepResult.Failure(step, exception)); break; } } // Execute cleanup even if there are failures in build steps. // * In opposite order of build steps that ran // * Can't be cancelled; cleanup step must run foreach (var step in cleanupSteps) { // Update build progress context.BuildProgress?.Update($"{title} (Cleanup)", step.Description + "...", 1.0F); // Run cleanup step try { timer.Restart(); var result = step.CleanupBuildStep(context); timer.Stop(); // Update cleanup step duration result.Duration = timer.Elapsed; // Add cleanup step result to pipeline status status.BuildStepsResults.Add(result); } catch (Exception exception) { // Add cleanup step exception to pipeline status (not stopping execution) status.BuildStepsResults.Add(BuildStepResult.Failure(step, exception)); } } return(status); }