Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
 internal BuildContext(BuildPipeline pipeline, BuildConfiguration config, BuildProgress progress = null, Action <BuildContext> mutator = null) :
     base(pipeline, config)
 {
     BuildPipelineStatus = BuildPipelineResult.Success(pipeline, config);
     BuildProgress       = progress;
     mutator?.Invoke(this);
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        internal BuildContext(BuildPipeline pipeline, BuildConfiguration config, BuildProgress progress = null, Action <BuildContext> mutator = null)
        {
            BuildPipeline       = pipeline ?? throw new NullReferenceException(nameof(pipeline));
            BuildConfiguration  = config ?? BuildConfiguration.CreateInstance();
            BuildProgress       = progress;
            BuildPipelineStatus = BuildPipelineResult.Success(pipeline, BuildConfiguration);

            mutator?.Invoke(this);

            // Work-around for assets that can be garbage collected during a build
            BuildConfiguration.GCPin();
            BuildPipeline.GCPin();
        }
        /// <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));
            }
        }
Ejemplo n.º 8
0
        static void SetArtifactData(BuildPipelineResult result, IBuildArtifact[] artifacts)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result.BuildConfiguration == null)
            {
                throw new ArgumentNullException(nameof(result.BuildConfiguration));
            }

            if (artifacts == null)
            {
                throw new ArgumentNullException(nameof(artifacts));
            }

            var name = GetBuildConfigurationName(result.BuildConfiguration);

            if (!s_ArtifactDataCache.TryGetValue(name, out var artifactData) || artifactData == null)
            {
                artifactData = new ArtifactData();
                s_ArtifactDataCache.Add(name, artifactData);
            }

            artifactData.Result    = result;
            artifactData.Artifacts = artifacts;

            var assetPath = GetArtifactsPath(name);
            var assetDir  = Path.GetDirectoryName(assetPath);

            if (!Directory.Exists(assetDir))
            {
                Directory.CreateDirectory(assetDir);
            }

            var json = JsonSerialization.Serialize(artifactData, new BuildJsonVisitor());

            File.WriteAllText(assetPath, json);
        }
        static void SetArtifactData(BuildPipelineResult result, IBuildArtifact[] artifacts)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result.BuildConfiguration == null)
            {
                throw new ArgumentNullException(nameof(result.BuildConfiguration));
            }

            if (artifacts == null)
            {
                throw new ArgumentNullException(nameof(artifacts));
            }

            var name = GetBuildConfigurationName(result.BuildConfiguration);

            if (!s_ArtifactDataCache.TryGetValue(name, out var artifactData) || artifactData == null)
            {
                artifactData = new ArtifactData();
                s_ArtifactDataCache.Add(name, artifactData);
            }

            artifactData.Result    = result;
            artifactData.Artifacts = artifacts.ToList();

            var assetPath = GetArtifactsPath(name);
            var file      = new FileInfo(assetPath);

            file.WriteAllText(JsonSerialization.ToJson(artifactData, new JsonSerializationParameters
            {
                DisableRootAdapters = true,
                SerializedType      = typeof(ArtifactData)
            }));
        }
Ejemplo n.º 10
0
 internal static void Store(BuildPipelineResult result, IBuildArtifact[] artifacts) => SetArtifactData(result, artifacts);
Ejemplo n.º 11
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);
Ejemplo n.º 12
0
 /// <summary>
 /// Construct <see cref="BuildPipelineResult"/> from this <see cref="BuildPipeline"/> that represent a successful execution.
 /// </summary>
 /// <returns>A new <see cref="BuildPipelineResult"/> instance.</returns>
 public BuildPipelineResult Success() => BuildPipelineResult.Success();
Ejemplo n.º 13
0
 /// <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);
Ejemplo n.º 14
0
 /// <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);
Ejemplo n.º 15
0
 /// <summary>
 /// Get a build result representing a success.
 /// </summary>
 /// <returns>A new build result instance.</returns>
 public BuildPipelineResult Success() => BuildPipelineResult.Success(BuildPipeline, BuildConfiguration);