Exemplo n.º 1
0
        /// <summary>
        /// Run this batch job.
        /// </summary>
        public void Run(IBuildsCompleteListener onComplete = null)
        {
            var runnerJobs = new List <BuildRunner.Job>();

            foreach (var job in jobs)
            {
                if (job == null)
                {
                    continue;
                }

                if (job is BuildProfile profile)
                {
                    foreach (var target in profile.BuildTargets)
                    {
                        runnerJobs.Add(new BuildRunner.Job(profile, target));
                    }
                }
                else if (job is DistroBase distro)
                {
                    distro.AddBuildJobs(distroBuildMode, runnerJobs);
                    runnerJobs.Add(new BuildRunner.Job(distro));
                }
            }

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(runnerJobs.ToArray(), onComplete, TrimmerPrefs.RestoreActiveBuildTarget, context: this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Build the profile's targets with the given build mode.
        /// Does not run the actual distribution.
        /// </summary>
        /// <param name="buildMode">Build mode to use (must not be <see cref="DistroBuildMode.None"/>)</param>
        /// <param name="onComplete">Listener that will be called when the builds are complete</param>
        public void Build(DistroBuildMode buildMode = DistroBuildMode.BuildAll, IBuildsCompleteListener onComplete = null)
        {
            var jobs = new List <BuildRunner.Job>();

            AddBuildJobs(buildMode, jobs);

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(jobs.ToArray(), onComplete, TrimmerPrefs.RestoreActiveBuildTarget, context: this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Build a profile for its default targets and with the default build options.
        /// </summary>
        public static void Build(BuildProfile profile, IBuildsCompleteListener onComplete = null)
        {
            var targets = profile.BuildTargets.ToArray();
            var jobs    = new BuildRunner.Job[targets.Length];

            for (int i = 0; i < targets.Length; i++)
            {
                jobs[i] = new BuildRunner.Job()
                {
                    profile = profile,
                    target  = targets[i],
                };
            }

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(jobs, onComplete, TrimmerPrefs.RestoreActiveBuildTarget);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Build a specific target of a profile with the default build options.
        /// </summary>
        /// <param name="profile">Profile to build</param>
        /// <param name="target">Target to build, needs to be part of profile</param>
        public static void Build(BuildProfile profile, BuildTarget target, IBuildsCompleteListener onComplete = null)
        {
            if (profile.BuildTargets != null && profile.BuildTargets.Any() && !profile.BuildTargets.Contains(target))
            {
                var err = $"Build target {target} is not part of the build profile {profile.name}";
                if (onComplete != null)
                {
                    onComplete.OnComplete(false, new[] { ProfileBuildResult.Error(profile, err) });
                }
                else
                {
                    Debug.LogError(err);
                }
                return;
            }

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(new[] { new BuildRunner.Job(profile, target) }, onComplete, TrimmerPrefs.RestoreActiveBuildTarget);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Build the profile's targets with the given build mode.
        /// Does not run the actual distribution.
        /// </summary>
        /// <param name="buildMode">Build mode to use (must not be <see cref="DistroBuildMode.None"/>)</param>
        /// <param name="onComplete">Listener that will be called when the builds are complete</param>
        public void Build(DistroBuildMode buildMode = DistroBuildMode.BuildMissing, IBuildsCompleteListener onComplete = null)
        {
            if (buildMode == DistroBuildMode.None)
            {
                throw new ArgumentException("Invalid parameter value DistroBuildMode.None", nameof(buildMode));
            }

            var jobs = new List <BuildRunner.Job>();

            foreach (var profile in builds)
            {
                if (profile == null)
                {
                    continue;
                }
                foreach (var target in profile.BuildTargets)
                {
                    var path = profile.GetLastBuildPath(target);
                    if (buildMode == DistroBuildMode.BuildAll ||
                        string.IsNullOrEmpty(path) ||
                        (!File.Exists(path) && !Directory.Exists(path)))
                    {
                        jobs.Add(new BuildRunner.Job(profile, target));
                    }
                }
            }

            if (jobs.Count == 0)
            {
                onComplete.OnComplete(true, new ProfileBuildResult[0]);
                return;
            }

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(jobs.ToArray(), onComplete, TrimmerPrefs.RestoreActiveBuildTarget);
        }
Exemplo n.º 6
0
        public static void Build(IBuildsCompleteListener onComplete = null)
        {
            string commandLineBuildPath = null;
            string profileName          = null;
            var    buildActiveTarget    = false;

            if (Application.isBatchMode)
            {
                string[] args = Environment.GetCommandLineArgs();
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].EqualsIgnoringCase("-profileName"))
                    {
                        if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                        {
                            throw new Exception("-profileName needs to be followed by a profile name.");
                        }
                        profileName = args[++i];
                    }
                    else if (args[i].EqualsIgnoringCase("-output"))
                    {
                        if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                        {
                            throw new Exception("-output needs to be followed by a path.");
                        }
                        commandLineBuildPath = args[++i];
                    }
                    else if (args[i].EqualsIgnoringCase("-buildTarget"))
                    {
                        // Unity will validate the value of the -buildTarget option
                        buildActiveTarget = true;
                    }
                }
            }

            BuildProfile profile = null;

            if (Application.isBatchMode && profileName != null)
            {
                profile = BuildProfile.Find(profileName);
                if (profile == null)
                {
                    var err = "Build profile named '" + profileName + "' cloud not be found.";
                    if (onComplete != null)
                    {
                        onComplete.OnComplete(false, new[] { ProfileBuildResult.Error(null, err) });
                    }
                    else
                    {
                        Debug.LogError(err);
                    }
                    return;
                }

                Debug.Log("Building " + profile.name + ", selected from command line.");
            }

            if (profile == null)
            {
                if (EditorProfile.Instance.ActiveProfile == null)
                {
                    var err = "No profile specified and not active profile set: Nothing to build";
                    if (onComplete != null)
                    {
                        onComplete.OnComplete(false, new[] { ProfileBuildResult.Error(null, err) });
                    }
                    else
                    {
                        Debug.LogError(err);
                    }
                    return;
                }
                profile = EditorProfile.Instance.ActiveProfile;
                Debug.Log("Building active profile.");
            }

            // Throw if command line build failed to cause non-zero exit code
            if (Application.isBatchMode && onComplete == null)
            {
                onComplete = ScriptableObject.CreateInstance <CommandLineBuildsCompleteListener>();
            }

            BuildRunner.Job[] jobs;
            if (buildActiveTarget)
            {
                jobs = new[] {
                    new BuildRunner.Job(profile, EditorUserBuildSettings.activeBuildTarget, commandLineBuildPath)
                };
            }
            else
            {
                var targets = profile.BuildTargets.ToArray();
                jobs = new BuildRunner.Job[targets.Length];
                for (int i = 0; i < targets.Length; i++)
                {
                    jobs[i] = new BuildRunner.Job()
                    {
                        profile    = profile,
                        target     = targets[i],
                        outputPath = commandLineBuildPath,
                    };
                }
            }

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(jobs, onComplete, TrimmerPrefs.RestoreActiveBuildTarget && !Application.isBatchMode);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Run the given builds.
 /// </summary>
 public void Run(Job[] jobs, IBuildsCompleteListener listener, bool restoreActiveBuildTarget = true, UnityEngine.Object context = null)
 {
     EnsureNotRunning();
     Listener = (ScriptableObject)listener;
     Run(jobs, restoreActiveBuildTarget, context);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Run the given builds.
 /// </summary>
 public void Run(Job[] jobs, IBuildsCompleteListener listener, bool restoreActiveBuildTarget = true)
 {
     EnsureNotRunning();
     Listener = (ScriptableObject)listener;
     Run(jobs);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Process the builds of the linked Build Profiles and build the
        /// targets where no build exists.
        /// </summary>
        /// <param name="buildMode">Build mode to use</param>
        public void Distribute(DistroBuildMode buildMode = DistroBuildMode.BuildMissing, IBuildsCompleteListener onComplete = null)
        {
            var jobs      = new List <BuildRunner.Job>();
            var willBuild = AddBuildJobs(buildMode, jobs);

            jobs.Add(new BuildRunner.Job(this));

            var runner = ScriptableObject.CreateInstance <BuildRunner>();

            runner.Run(jobs.ToArray(), onComplete, willBuild && TrimmerPrefs.RestoreActiveBuildTarget, context: this);
        }