/// <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); }
/// <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); }
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); }