Skip to content

Commit

Permalink
fix: rolled back 'IBuildTasksContainer' implementation
Browse files Browse the repository at this point in the history
- collecting of Unity built-in tasks is moved to BuildPipelineTab
  • Loading branch information
vdenysiuk-sa committed Aug 13, 2021
1 parent 13b9909 commit 6edec44
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 68 deletions.
2 changes: 1 addition & 1 deletion com.stansassets.build/BuildPipeline/Core/BuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void OnPostProcessScene()
sceneTasksRunner.Run(s_BuildContext, postProcessSceneTasks);
}

public static IBuildTasksContainerFull GenerateBuildStepsContainer()
public static IBuildTasksContainer GenerateBuildStepsContainer()
{
var stepsProvider = CreateBuildTasksProvider();
return stepsProvider.GetBuildSteps(new UserEditorBuildSettings());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using StansAssets.Foundation;
using System;
using UnityEditor.Build;

namespace StansAssets.Build.Pipeline
{
class DefaultBuildTasksProvider : IBuildTasksProvider
{
public IBuildTasksContainerFull GetBuildSteps(IUserEditorBuildSettings buildSettings)
public IBuildTasksContainer GetBuildSteps(IUserEditorBuildSettings buildSettings)
{
var tasksContainer = new BuildTasksContainer();

CollectBuildTasks(tasksContainer);
CollectScenePostProcessTasks(tasksContainer);

CollectUnityBuildTasks<IPreprocessBuildWithReport>(tasksContainer.AddPreProcessBuildTask);
CollectUnityBuildTasks<IPostprocessBuildWithReport>(tasksContainer.AddPostProcessBuildTask);
CollectUnityBuildTasks<IProcessSceneWithReport>(tasksContainer.AddProcessSceneTask);

CollectScenePostProcessTasks(tasksContainer);

return tasksContainer;
}

Expand Down Expand Up @@ -60,19 +55,6 @@ static void CollectScenePostProcessTasks(BuildTasksContainer tasksContainer)
tasksContainer.AddScenePostProcessTask(buildStep);
}
}
}

static void CollectUnityBuildTasks<T>(Action<T> addBuildTask)
where T : class, IOrderedCallback
{
var taskTypes = ReflectionUtility.FindImplementationsOf<T>(ignoreBuiltIn: true);
foreach (var taskType in taskTypes)
{
if (ReflectionUtility.HasDefaultConstructor(taskType))
{
addBuildTask(Activator.CreateInstance(taskType) as T);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace StansAssets.Build.Pipeline
/// </summary>
public interface IBuildTasksProvider
{
IBuildTasksContainerFull GetBuildSteps(IUserEditorBuildSettings buildSettings);
IBuildTasksContainer GetBuildSteps(IUserEditorBuildSettings buildSettings);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System.Collections.Generic;
using UnityEditor.Build;

namespace StansAssets.Build.Pipeline
{
/// <summary>
/// Provides build steps. Order matters.
/// </summary>
public class BuildTasksContainer : IBuildTasksContainerFull
public class BuildTasksContainer : IBuildTasksContainer
{
readonly List<IPreprocessBuildWithReport> m_UnityPreProcessBuildTasks;
readonly List<IPostprocessBuildWithReport> m_UnityPostprocessBuildTasks;
readonly List<IProcessSceneWithReport> m_UnityProcessSceneTasks;

readonly List<IBuildTask> m_PreBuildSteps;
readonly List<IBuildTask> m_PostBuildSteps;
readonly List<IScenePostProcessTask> m_ScenePostProcessStepsTasks;
Expand All @@ -20,16 +15,8 @@ public class BuildTasksContainer : IBuildTasksContainerFull
public IReadOnlyList<IBuildTask> PostBuildTasks => m_PostBuildSteps;
public IReadOnlyList<IScenePostProcessTask> ScenePostProcessTasks => m_ScenePostProcessStepsTasks;

public IReadOnlyList<IOrderedCallback> UnityPreBuildTasks => m_UnityPreProcessBuildTasks;
public IReadOnlyList<IOrderedCallback> UnityPostBuildTasks => m_UnityPostprocessBuildTasks;
public IReadOnlyList<IOrderedCallback> UnityProcessSceneTasks => m_UnityProcessSceneTasks;

public BuildTasksContainer()
{
m_UnityPreProcessBuildTasks = new List<IPreprocessBuildWithReport>();
m_UnityPostprocessBuildTasks = new List<IPostprocessBuildWithReport>();
m_UnityProcessSceneTasks = new List<IProcessSceneWithReport>();

m_PreBuildSteps = new List<IBuildTask>();
m_PostBuildSteps = new List<IBuildTask>();
m_ScenePostProcessStepsTasks = new List<IScenePostProcessTask>();
Expand All @@ -44,15 +31,6 @@ public void AddPreProcessTask(IBuildTask step)
m_PreBuildSteps.Add(step);
}

/// <summary>
/// Registers a pre process build task.
/// </summary>
/// <param name="task">Task to be registered.</param>
public void AddPreProcessBuildTask(IPreprocessBuildWithReport task)
{
m_UnityPreProcessBuildTasks.Add(task);
}

/// <summary>
/// Registers a post process build step.
/// </summary>
Expand All @@ -62,15 +40,6 @@ public void AddPostProcessTask(IBuildTask step)
m_PostBuildSteps.Add(step);
}

/// <summary>
/// Registers a post process build step.
/// </summary>
/// <param name="task">Step to be registered.</param>
public void AddPostProcessBuildTask(IPostprocessBuildWithReport task)
{
m_UnityPostprocessBuildTasks.Add(task);
}

/// <summary>
/// Registers a post process scene step.
/// </summary>
Expand All @@ -79,14 +48,5 @@ public void AddScenePostProcessTask(IScenePostProcessTask task)
{
m_ScenePostProcessStepsTasks.Add(task);
}

/// <summary>
/// Registers a process scene step.
/// </summary>
/// <param name="task">Step to be registered.</param>
public void AddProcessSceneTask(IProcessSceneWithReport task)
{
m_UnityProcessSceneTasks.Add(task);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using JetBrains.Annotations;
using StansAssets.Build.Editor;
using StansAssets.Foundation;
using StansAssets.Plugins.Editor;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand Down Expand Up @@ -37,12 +39,17 @@ public BuildPipelineTab()
SetBuildSteps(BuildProcessor.GenerateBuildStepsContainer(), BuildProcessor.GetProviderName());
}

public void SetBuildSteps(IBuildTasksContainerFull buildTasksContainer, string providerName)
public void SetBuildSteps(IBuildTasksContainer buildTasksContainer, string providerName)
{
m_StepsProviderName.text = providerName;
RenderBuildSteps(m_PreProcessStepsContainer, buildTasksContainer.UnityPreBuildTasks, buildTasksContainer.PreBuildTasks);
RenderBuildSteps(m_ScenePostProcessStepsContainer, buildTasksContainer.UnityPostBuildTasks, buildTasksContainer.ScenePostProcessTasks);
RenderBuildSteps(m_PostProcessStepsContainer, buildTasksContainer.UnityProcessSceneTasks, buildTasksContainer.PostBuildTasks);

var unityPreBuildTasks = CollectUnityBuildTasks<IPreprocessBuildWithReport>();
var unityPostBuildTasks = CollectUnityBuildTasks<IPostprocessBuildWithReport>();
var unityProcessSceneTasks = CollectUnityBuildTasks<IProcessSceneWithReport>();

RenderBuildSteps(m_PreProcessStepsContainer, unityPreBuildTasks, buildTasksContainer.PreBuildTasks);
RenderBuildSteps(m_ScenePostProcessStepsContainer, unityPostBuildTasks, buildTasksContainer.ScenePostProcessTasks);
RenderBuildSteps(m_PostProcessStepsContainer, unityProcessSceneTasks, buildTasksContainer.PostBuildTasks);
}

static void RenderBuildSteps(VisualElement container, IReadOnlyCollection<IOrderedCallback> unityBuildSteps, IReadOnlyCollection<object> buildSteps)
Expand Down Expand Up @@ -72,6 +79,22 @@ static void RenderBuildSteps(VisualElement container, IEnumerable<object> buildS
label.AddToClassList("item-build-entity");
container.Add(label);
}
}


static List<T> CollectUnityBuildTasks<T>()
where T : class, IOrderedCallback
{
var tasks = new List<T>();
var taskTypes = ReflectionUtility.FindImplementationsOf<T>(ignoreBuiltIn: true);
foreach (var taskType in taskTypes)
{
if (ReflectionUtility.HasDefaultConstructor(taskType))
{
tasks.Add(Activator.CreateInstance(taskType) as T);
}
}
return tasks;
}
}
}

0 comments on commit 6edec44

Please sign in to comment.