diff --git a/.yamato/input-system-player-compile-checks.yml b/.yamato/input-system-player-compile-checks.yml new file mode 100644 index 0000000000..f187e288ed --- /dev/null +++ b/.yamato/input-system-player-compile-checks.yml @@ -0,0 +1,61 @@ +####################################################### +### ### +### Auto-generated by Recipe Engine, DO NOT EDIT. ### +### ### +####################################################### +# Source: InputSystem.Cookbook.Recipes.PlayerCompileChecks + +# InputSystem-PlayerCompileChecks - 6000.0 - Ubuntu2204 +inputsystem-playercompilechecks_-_6000_0_-_ubuntu2204: + name: InputSystem-PlayerCompileChecks - 6000.0 - Ubuntu2204 + agent: + image: package-ci/ubuntu-22.04:v4 + type: Unity::VM::GPU + flavor: b1.large + commands: + - command: unity-downloader-cli -u 6000.0/staging -c Editor --fast --wait + - command: mkdir -p artifacts + - command: .Editor/Unity -projectPath . -batchmode -nographics -executeMethod PlayerCompileCheck.Run -logFile artifacts/PlayerCompileCheck.log + after: + - command: bash .yamato/generated-scripts/infrastructure-instability-detection-linux.sh + artifacts: + artifacts: + paths: + - artifacts/**/* + +# InputSystem-PlayerCompileChecks - 6000.3 - Ubuntu2204 +inputsystem-playercompilechecks_-_6000_3_-_ubuntu2204: + name: InputSystem-PlayerCompileChecks - 6000.3 - Ubuntu2204 + agent: + image: package-ci/ubuntu-22.04:v4 + type: Unity::VM::GPU + flavor: b1.large + commands: + - command: unity-downloader-cli -u 6000.3/staging -c Editor --fast --wait + - command: mkdir -p artifacts + - command: .Editor/Unity -projectPath . -batchmode -nographics -executeMethod PlayerCompileCheck.Run -logFile artifacts/PlayerCompileCheck.log + after: + - command: bash .yamato/generated-scripts/infrastructure-instability-detection-linux.sh + artifacts: + artifacts: + paths: + - artifacts/**/* + +# InputSystem-PlayerCompileChecks - 6000.6 - Ubuntu2204 +inputsystem-playercompilechecks_-_6000_6_-_ubuntu2204: + name: InputSystem-PlayerCompileChecks - 6000.6 - Ubuntu2204 + agent: + image: package-ci/ubuntu-22.04:v4 + type: Unity::VM::GPU + flavor: b1.large + commands: + - command: unity-downloader-cli -u 6000.6/staging -c Editor --fast --wait + - command: mkdir -p artifacts + - command: .Editor/Unity -projectPath . -batchmode -nographics -executeMethod PlayerCompileCheck.Run -logFile artifacts/PlayerCompileCheck.log + after: + - command: bash .yamato/generated-scripts/infrastructure-instability-detection-linux.sh + artifacts: + artifacts: + paths: + - artifacts/**/* + diff --git a/.yamato/triggers.yml b/.yamato/triggers.yml index 78699de578..a8f9c65196 100644 --- a/.yamato/triggers.yml +++ b/.yamato/triggers.yml @@ -28,6 +28,9 @@ all_functional_tests: - path: .yamato/input-system-mobile-functional-tests.yml#inputsystem-mobilefunctionaltests_-_6000_6_-_android_-_il2cpp - path: .yamato/input-system-mobile-functional-tests.yml#inputsystem-mobilefunctionaltests_-_6000_6_-_android_-_mono - path: .yamato/input-system-mobile-functional-tests.yml#inputsystem-mobilefunctionaltests_-_6000_6_-_ios + - path: .yamato/input-system-player-compile-checks.yml#inputsystem-playercompilechecks_-_6000_0_-_ubuntu2204 + - path: .yamato/input-system-player-compile-checks.yml#inputsystem-playercompilechecks_-_6000_3_-_ubuntu2204 + - path: .yamato/input-system-player-compile-checks.yml#inputsystem-playercompilechecks_-_6000_6_-_ubuntu2204 - path: .yamato/input-system-standalone-functional-tests.yml#inputsystem-standalonefunctionaltests_-_6000_0_-_macos13 - path: .yamato/input-system-standalone-functional-tests.yml#inputsystem-standalonefunctionaltests_-_6000_0_-_ubuntu2204 - path: .yamato/input-system-standalone-functional-tests.yml#inputsystem-standalonefunctionaltests_-_6000_0_-_win10 diff --git a/Assets/Editor/PlayerCompileCheck.cs b/Assets/Editor/PlayerCompileCheck.cs new file mode 100644 index 0000000000..8244d6f6e0 --- /dev/null +++ b/Assets/Editor/PlayerCompileCheck.cs @@ -0,0 +1,102 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.Build.Player; +using UnityEngine; + +/// +/// Compiles the Player scripts for the active build target under several combinations of +/// development build and scripting defines. Only scripts are compiled, no Player content is built. +/// +/// +/// Test runs only build development Players, which always define DEBUG, so code that compiles only in +/// some combinations can break customer builds without failing any test job. For example, +/// UNITY_INCLUDE_TESTS without DEBUG used to fail with CS0117 on InputSystem.remoteConnection. +/// +/// CI runs this with: +/// Unity -batchmode -nographics -projectPath . -executeMethod PlayerCompileCheck.Run -logFile - +/// The Editor exits with code 1 if any combination fails to compile. +/// +internal static class PlayerCompileCheck +{ + // Add a define here when users are known to set it in their projects. + static readonly string[][] k_DefineSets = + { + new string[0], + new[] { "UNITY_INCLUDE_TESTS" }, + }; + + const string k_PackageAssembly = "Unity.InputSystem.dll"; + + public static void Run() + { + // Keep the CI log readable: the stack traces of these log lines carry no information. + Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None); + Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None); + + var target = EditorUserBuildSettings.activeBuildTarget; + var group = BuildPipeline.GetBuildTargetGroup(target); + + var failures = new List(); + foreach (var development in new[] { false, true }) + { + foreach (var defines in k_DefineSets) + { + var name = $"{(development ? "Development" : "Release")} [{string.Join(", ", defines)}]"; + if (!Compile(target, group, development, defines, name)) + failures.Add(name); + } + } + + if (failures.Count > 0) + { + Debug.LogError($"PlayerCompileCheck: {failures.Count} combination(s) failed to compile for {target}:\n {string.Join("\n ", failures)}"); + EditorApplication.Exit(1); + return; + } + + Debug.Log($"PlayerCompileCheck: all combinations compiled for {target}."); + EditorApplication.Exit(0); + } + + static bool Compile(BuildTarget target, BuildTargetGroup group, bool development, string[] defines, string name) + { + var errors = new List(); + void OnLog(string message, string stackTrace, LogType type) + { + if (type == LogType.Error && message.Contains("error CS")) + lock (errors) + errors.Add(message); + } + + var settings = new ScriptCompilationSettings + { + target = target, + group = group, + options = development ? ScriptCompilationOptions.DevelopmentBuild : ScriptCompilationOptions.None, + extraScriptingDefines = defines, + }; + + Application.logMessageReceivedThreaded += OnLog; + ScriptCompilationResult result; + try + { + result = PlayerBuildInterface.CompilePlayerScripts(settings, $"Temp/PlayerCompileCheck/{(development ? "Development" : "Release")}{defines.Length}"); + } + finally + { + Application.logMessageReceivedThreaded -= OnLog; + } + + var compiledPackage = result.assemblies != null && result.assemblies.Contains(k_PackageAssembly); + var ok = compiledPackage && errors.Count == 0; + + Debug.Log($"PlayerCompileCheck: {name}: {(ok ? "OK" : "FAILED")}"); + if (!compiledPackage) + Debug.Log($"PlayerCompileCheck: {name}: {k_PackageAssembly} was not produced."); + foreach (var error in errors.Distinct()) + Debug.Log($"PlayerCompileCheck: {name}: {error}"); + + return ok; + } +} diff --git a/Assets/Editor/PlayerCompileCheck.cs.meta b/Assets/Editor/PlayerCompileCheck.cs.meta new file mode 100644 index 0000000000..f1c352b2fc --- /dev/null +++ b/Assets/Editor/PlayerCompileCheck.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4a2101631ade545bfaa24d2ca2602e20 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tools/CI/CI-CHANGES.md b/Tools/CI/CI-CHANGES.md index a1576986d9..ad30a95e0d 100644 --- a/Tools/CI/CI-CHANGES.md +++ b/Tools/CI/CI-CHANGES.md @@ -4,6 +4,26 @@ This file documents notable changes made to the CI cookbook (`Tools/CI/`), inclu --- +## Player compile checks +**Branch:** `input/ci-player-compile-checks` +**Date:** November 2026 +**Author:** David Lo + +### Summary +All our Player test jobs go through UTR, which only builds development Players. Development builds always define `DEBUG`, so CI never compiled the package for a release Player with tests included. 1.20.0 and 1.20.1 shipped with a compile error in exactly that case: with the `UNITY_INCLUDE_TESTS` scripting define set, a non-development Player build failed with `CS0117: 'InputSystem' does not contain a definition for 'remoteConnection'`. A customer hit it in a real project. + +The new jobs compile the Player scripts, without building a Player, in release and development builds, each with and without `UNITY_INCLUDE_TESTS`. + +### Changes +- **`Assets/Editor/PlayerCompileCheck.cs`:** new Editor script. `PlayerCompileCheck.Run` calls `PlayerBuildInterface.CompilePlayerScripts` for the active build target with each combination. It logs a `PlayerCompileCheck:` line per combination and exits with code 1 if any combination fails to compile. Run it locally with `Unity -batchmode -nographics -projectPath . -executeMethod PlayerCompileCheck.Run -logFile -`. +- **`Recipes/PlayerCompileChecks.cs`:** new recipe with one Ubuntu job per editor version. It only checks `#if` logic, so one platform is enough. The Editor log is saved as `artifacts/PlayerCompileCheck.log`. +- **`Recipes/Triggers.cs`:** "All Functional Tests" (the PR gate) now depends on the new jobs. + +### Follow-up +- To check another define that users set, add it to `k_DefineSets` in `PlayerCompileCheck.cs`. + +--- + ## Gate PRs on Validate instead of Publish Dry Run **Branch:** `anthony/pr-gate-on-validate` **Date:** November 2026 diff --git a/Tools/CI/Recipes/PlayerCompileChecks.cs b/Tools/CI/Recipes/PlayerCompileChecks.cs new file mode 100644 index 0000000000..b6d141e0ec --- /dev/null +++ b/Tools/CI/Recipes/PlayerCompileChecks.cs @@ -0,0 +1,54 @@ +using InputSystem.Cookbook.Settings; +using RecipeEngine.Api.Artifacts; +using RecipeEngine.Api.Extensions; +using RecipeEngine.Api.Jobs; +using RecipeEngine.Api.Platforms; +using RecipeEngine.Modules.InfrastructureInstabilityDetection; +using RecipeEngine.Modules.Wrench.Helpers; +using RecipeEngine.Modules.Wrench.Platforms; +using RecipeEngine.Platforms; +using RecipeEngine.Unity.Abstractions.Packages; + +namespace InputSystem.Cookbook.Recipes; + +/// +/// Compiles the package's Player scripts in release and development builds, with and without +/// extra scripting defines such as UNITY_INCLUDE_TESTS, by running Assets/Editor/PlayerCompileCheck.cs. +/// Test jobs only build development Players, so they never compile the release-build combinations. +/// The check is about #if logic, not platform behavior, so it runs on one platform per editor version. +/// +public class PlayerCompileChecks : BaseRecipe +{ + public override string ProjectPath => "."; + + const EditorPlatformType k_PlatformType = EditorPlatformType.Ubuntu2204; + + public override IEnumerable GetJobs() + { + var package = Settings.InputSystemPackage; + foreach (var unityEditor in package.UnityEditors) + { + if (!unityEditor.EditorPlatforms.Items.TryGetValue(k_PlatformType, out var editorPlatform)) + continue; + + var version = unityEditor.Version.Version; + var platform = new Platform(editorPlatform.Agent, editorPlatform.System); + yield return ProduceJob(GetJobName(version, k_PlatformType), package, platform, version); + } + } + + protected override IJobBuilder ProduceJob(string jobName, Package package, Platform platform, string unityVersion) + { + var unityBranch = Settings.Wrench.EditorVersionToBranches[unityVersion]; + + return JobBuilder.Create(jobName) + .WithDescription(jobName) + .WithPlatform(platform) + .WithCommands(c => c + .Add(Utilities.GetEditorDownloadCommand(unityBranch, platform)) + .Add("mkdir -p artifacts") + .Add($".Editor/Unity -projectPath {ProjectPath} -batchmode -nographics -executeMethod PlayerCompileCheck.Run -logFile artifacts/PlayerCompileCheck.log")) + .WithArtifact(new Artifact("artifacts", "artifacts/**/*")) + .WithInfrastructureInstabilityDetection(); + } +} diff --git a/Tools/CI/Recipes/Triggers.cs b/Tools/CI/Recipes/Triggers.cs index c43d2d24a5..fa9de0ef48 100644 --- a/Tools/CI/Recipes/Triggers.cs +++ b/Tools/CI/Recipes/Triggers.cs @@ -17,6 +17,7 @@ public class Triggers : RecipeBase IEnumerable allMobileFunctionalTests = new MobileFunctionalTests().AsDependencies().Where(d => !d.JobId.Contains("TvOS")); // Run functional build jobs on TvOS for all Unity versions. IEnumerable allTvOSFunctionalBuildJobs = new MobileFunctionalBuildJobs().AsDependencies().Where(d => d.JobId.Contains("TvOS")); + IEnumerable allPlayerCompileChecks = new PlayerCompileChecks().AsDependencies(); IEnumerable allEditorPerformanceTests = new EditorPerformanceTests().AsDependencies(); IEnumerable allStandalonePerformanceTests = new StandalonePerformanceTests().AsDependencies(); @@ -59,6 +60,7 @@ private ISet GetTriggers() .WithDependencies(allStandaloneIl2CppFunctionalTests.Where(d => !d.JobId.Contains("Ubuntu"))) .WithDependencies(allMobileFunctionalTests) .WithDependencies(allTvOSFunctionalBuildJobs) + .WithDependencies(allPlayerCompileChecks) // Gate on Validate rather than on "Publish Dry Run": a dry run has the same requirements // as a real publish, so it always fails while the changelog has an [Unreleased] section. .WithDependencies(allValidationJobs)