Beispiel #1
0
        public void QueueBuild(BuildConfiguration config, BuildPipelineResult buildPipelineResult)
        {
            if (m_PrepareQueueBuilds == null)
            {
                m_PrepareQueueBuilds = new List <QueuedBuild>();
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            var b = new QueuedBuild();

            b.sortingIndex           = config.GetComponent <IBuildPipelineComponent>().SortingIndex;
            b.buildConfigurationGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(config));

            if (m_QueueBuilds.Count > 0)
            {
                buildPipelineResult = BuildPipelineResult.Failure(config.GetBuildPipeline(), config, "Can't queue builds while executing build.");
            }

            // If the build failed in previous step, don't execute it
            if (buildPipelineResult != null && buildPipelineResult.Failed)
            {
                b.buildFinished = true;
            }
            else
            {
                b.buildFinished = false;
            }

            b.buildPipelineResult = buildPipelineResult != null?JsonSerialization.Serialize(buildPipelineResult) : string.Empty;

            m_PrepareQueueBuilds.Add(b);
        }
Beispiel #2
0
        /// <summary>
        /// Queues and builds multiple builds. For builds requiring explicit active Editor build target, this function also switches Editor build target before starting the build.
        /// That's why there's no return result here, because the build won't be executed immediately in some cases.
        /// </summary>
        internal static void BuildAsync(BuildBatchDescription buildBatchDescription)
        {
            var buildEntities = buildBatchDescription.BuildItems;
            // ToDo: when running multiple builds, should we stop at first failure?
            var buildPipelineResults = new BuildPipelineResult[buildEntities.Length];

            for (int i = 0; i < buildEntities.Length; i++)
            {
                var config   = buildEntities[i].BuildConfiguration;
                var pipeline = config.GetBuildPipeline();
                if (!config.CanBuild(out var reason))
                {
                    buildPipelineResults[i] = BuildPipelineResult.Failure(pipeline, config, reason);
                }
                else
                {
                    buildPipelineResults[i] = null;
                }
            }

            var queue = BuildQueue.instance;

            for (int i = 0; i < buildEntities.Length; i++)
            {
                var config   = buildEntities[i].BuildConfiguration;
                var pipeline = config.GetBuildPipeline();
                queue.QueueBuild(config, buildPipelineResults[i]);
            }

            queue.FlushBuilds(buildBatchDescription.OnBuildCompleted);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Run the build pipeline.
        /// </summary>
        /// <param name="context">Context for running.</param>
        /// <returns>The result of the build.</returns>
        public BuildPipelineResult RunSteps(BuildContext context)
        {
            if (context == null)
            {
                throw new NullReferenceException(nameof(context));
            }

            if (context.BuildSettings == null)
            {
                context.BuildSettings = CreateInstance <BuildSettings>();
            }

            var previousPipeline = context.BuildPipeline;

            context.BuildPipeline = this;

            var steps = new List <IBuildStep>();

            if (!GetSteps(steps))
            {
                return(BuildPipelineResult.Failure($"Failed to get build steps from pipeline {name}."));
            }

            var result = RunSteps(context, steps);

            if (previousPipeline != null)
            {
                context.BuildPipeline = previousPipeline;
            }
            return(result);
        }
        /// <summary>
        /// Run the build pipeline of this build configuration to build the target.
        /// </summary>
        /// <returns>The result of the build pipeline build.</returns>
        public BuildPipelineResult Build()
        {
            var pipeline = GetBuildPipeline();

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

            var what = !string.IsNullOrEmpty(name) ? $" {name}" : string.Empty;

            using (var progress = new BuildProgress($"Building{what}", "Please wait..."))
            {
                return(pipeline.Build(this, progress));
            }
        }
Beispiel #6
0
 /// <summary>
 /// Construct <see cref="BuildPipelineResult"/> from this <see cref="BuildPipeline"/> that represent a failed execution.
 /// </summary>
 /// <param name="message">Message that explain why the <see cref="BuildPipeline"/> execution failed.</param>
 /// <returns>A new <see cref="BuildPipelineResult"/> instance.</returns>
 public BuildPipelineResult Failure(string message) => BuildPipelineResult.Failure(message);
 /// <summary>
 /// Get a build result representing a failure.
 /// </summary>
 /// <param name="exception">The exception that was thrown.</param>
 /// <returns>A new build result instance.</returns>
 public BuildPipelineResult Failure(Exception exception) => BuildPipelineResult.Failure(BuildPipeline, BuildConfiguration, exception);
 /// <summary>
 /// Get a build result representing a failure.
 /// </summary>
 /// <param name="reason">The reason of the failure.</param>
 /// <returns>A new build result instance.</returns>
 public BuildPipelineResult Failure(string reason) => BuildPipelineResult.Failure(BuildPipeline, BuildConfiguration, reason);