// TODO: We shouldn't be assuming that the namedBuildTarget can be extracted from the // active settings. This should be passed through the callstack instead when building. // We will need to use BuildTargetSelection (BuildTarget + Subtarget) that is in the cpp side. // For now this fixes an issue where Dedicated Server compiles with the Standalone settings. internal static NamedBuildTarget FromActiveSettings(BuildTarget target) { var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target); if (buildTargetGroup == BuildTargetGroup.Standalone && (StandaloneBuildSubtarget)EditorUserBuildSettings.GetActiveSubtargetFor(target) == StandaloneBuildSubtarget.Server) { return(NamedBuildTarget.Server); } return(NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup)); }
internal PlayerLauncherBuildOptions GetBuildOptions(string scenePath) { var buildOnly = false; var runSettings = m_OverloadTestRunSettings as PlayerLauncherTestRunSettings; if (runSettings != null) { buildOnly = runSettings.buildOnly; } var buildOptions = new BuildPlayerOptions(); var scenes = new List <string>() { scenePath }; scenes.AddRange(EditorBuildSettings.scenes.Select(x => x.path)); buildOptions.scenes = scenes.ToArray(); buildOptions.options |= BuildOptions.Development | BuildOptions.ConnectToHost | BuildOptions.IncludeTestAssemblies | BuildOptions.StrictMode; buildOptions.target = m_TargetPlatform; #if UNITY_2021_2_OR_NEWER buildOptions.subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(m_TargetPlatform); #endif if (EditorUserBuildSettings.waitForPlayerConnection) { buildOptions.options |= BuildOptions.WaitForPlayerConnection; } if (EditorUserBuildSettings.allowDebugging) { buildOptions.options |= BuildOptions.AllowDebugging; } if (EditorUserBuildSettings.installInBuildFolder) { buildOptions.options |= BuildOptions.InstallInBuildFolder; } else if (!buildOnly) { buildOptions.options |= BuildOptions.AutoRunPlayer; } var buildTargetGroup = EditorUserBuildSettings.activeBuildTargetGroup; //Check if Lz4 is supported for the current buildtargetgroup and enable it if need be if (PostprocessBuildPlayer.SupportsLz4Compression(buildTargetGroup, m_TargetPlatform)) { if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4) { buildOptions.options |= BuildOptions.CompressWithLz4; } else if (EditorUserBuildSettings.GetCompressionType(buildTargetGroup) == Compression.Lz4HC) { buildOptions.options |= BuildOptions.CompressWithLz4HC; } } string buildLocation; if (buildOnly) { buildLocation = buildOptions.locationPathName = runSettings.buildOnlyLocationPath; } else { var reduceBuildLocationPathLength = false; //Some platforms hit MAX_PATH limits during the build process, in these cases minimize the path length if ((m_TargetPlatform == BuildTarget.WSAPlayer) #if !UNITY_2021_1_OR_NEWER || (m_TargetPlatform == BuildTarget.XboxOne) #endif ) { reduceBuildLocationPathLength = true; } var uniqueTempPathInProject = FileUtil.GetUniqueTempPathInProject(); var playerDirectoryName = "PlayerWithTests"; //Some platforms hit MAX_PATH limits during the build process, in these cases minimize the path length if (reduceBuildLocationPathLength) { playerDirectoryName = "PwT"; uniqueTempPathInProject = Path.GetTempFileName(); File.Delete(uniqueTempPathInProject); Directory.CreateDirectory(uniqueTempPathInProject); } var tempPath = Path.GetFullPath(uniqueTempPathInProject); buildLocation = Path.Combine(tempPath, playerDirectoryName); // iOS builds create a folder with Xcode project instead of an executable, therefore no executable name is added if (m_TargetPlatform == BuildTarget.iOS) { buildOptions.locationPathName = buildLocation; } else { string extensionForBuildTarget = PostprocessBuildPlayer.GetExtensionForBuildTarget(buildTargetGroup, buildOptions.target, buildOptions.options); var playerExecutableName = "PlayerWithTests"; if (!string.IsNullOrEmpty(extensionForBuildTarget)) { playerExecutableName += $".{extensionForBuildTarget}"; } buildOptions.locationPathName = Path.Combine(buildLocation, playerExecutableName); } } return(new PlayerLauncherBuildOptions { BuildPlayerOptions = ModifyBuildOptions(buildOptions), PlayerDirectory = buildLocation, }); }