Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }