Skip to content

Commit 0f3b085

Browse files
CHANGE: Add CI job to check Editor references in Runtime code (#2413)
Co-authored-by: u-pr[bot] <205906871+u-pr[bot]@users.noreply.github.com>
1 parent 3e301f9 commit 0f3b085

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check Editor references in Runtime code
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
branches: [ "develop" ]
10+
11+
workflow_dispatch:
12+
13+
jobs:
14+
check-runtime-editor-refs:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Check Runtime code has no Editor namespace references
20+
run: bash check-runtime-editor-refs.sh

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemEditorInitializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ private static void RegisterAssetDatabaseHooks()
277277
InputManager.s_GetProjectWideActions = () => ProjectWideActionsBuildProvider.actionsToIncludeInPlayerBuild;
278278

279279
InputActionReference.s_CheckImmutableReference = CheckImmutableInputActionReference;
280+
281+
InputSettings.s_GetIsInspectorIndented = () => EditorGUI.indentLevel > 0;
280282
}
281283

282284
/// <summary>

Packages/com.unity.inputsystem/InputSystem/Runtime/InputSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,10 @@ public enum InputActionPropertyDrawerMode
988988
/// * support inspector view which only work in IMGUI for now.
989989
/// * prevent the UI to be rendered in IMGUI and UI Toolkit in the Input Actions Editor window.
990990
/// </summary>
991-
public bool useIMGUIEditorForAssets => UnityEditor.EditorGUI.indentLevel > 0 || IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets);
991+
public bool useIMGUIEditorForAssets =>
992+
(s_GetIsInspectorIndented?.Invoke() == true) || IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets);
993+
994+
internal static Func<bool> s_GetIsInspectorIndented;
992995
#endif
993996

994997
private static bool CompareFloats(float a, float b)

check-runtime-editor-refs.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
[ -n "$BASH_VERSION" ] || { echo "ERROR: This script requires bash. Run with: bash $0" >&2; exit 1; }
3+
set -euo pipefail
4+
5+
RUNTIME_DIR="Packages/com.unity.inputsystem/InputSystem/Runtime"
6+
7+
# POSIX ERE patterns for grep -E, compatible with macOS (BSD grep) and Ubuntu (GNU grep).
8+
# No \b word boundaries — not portable across both. False positive risk is negligible
9+
# since no real identifiers contain these namespace roots as substrings.
10+
# (\.[A-Za-z0-9_]+)* covers sub-namespaces (UnityEditor.UI, …Editor.Tools, …).
11+
# Add more lines as needed, e.g. 'UnityEditorInternal(\.[A-Za-z0-9_]+)*'
12+
FORBIDDEN_REGEX=(
13+
'UnityEditor(\.[A-Za-z0-9_]+)*'
14+
'UnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*'
15+
)
16+
17+
RED=$'\033[0;31m'
18+
GREEN=$'\033[0;32m'
19+
NC=$'\033[0m'
20+
21+
INCLUDE_COMMENTS=false
22+
for arg in "$@"; do
23+
case "$arg" in
24+
--include-comments) INCLUDE_COMMENTS=true ;;
25+
--help)
26+
cat <<EOF
27+
Usage: $(basename "$0") [OPTIONS]
28+
29+
Check that Runtime code has no Editor namespace dependencies.
30+
Edit FORBIDDEN_REGEX in this script to add patterns.
31+
32+
Options:
33+
--include-comments Also flag references inside XML doc and // comments
34+
--help Show this help
35+
EOF
36+
exit 0 ;;
37+
*) echo "Unknown option: $arg"; exit 1 ;;
38+
esac
39+
done
40+
41+
[ -d "$RUNTIME_DIR" ] || { echo "${RED}ERROR: Runtime directory not found: $RUNTIME_DIR${NC}" >&2; exit 1; }
42+
43+
COMBINED=$(IFS='|'; echo "${FORBIDDEN_REGEX[*]}")
44+
45+
GREP_OUTPUT=$(grep -rnw --include='*.cs' --color=never -E "$COMBINED" "$RUNTIME_DIR" || true)
46+
47+
if [ "$INCLUDE_COMMENTS" = false ]; then
48+
VIOLATIONS=$(echo "$GREP_OUTPUT" | grep -Ev ':[0-9]+:[[:space:]]*//' || true)
49+
else
50+
VIOLATIONS="$GREP_OUTPUT"
51+
fi
52+
53+
if [ -z "$VIOLATIONS" ]; then
54+
echo "${GREEN}PASS: No Editor namespace references found in Runtime code.${NC}"
55+
exit 0
56+
fi
57+
58+
VIOLATION_COUNT=$(echo "$VIOLATIONS" | wc -l | tr -d ' ')
59+
echo "${RED}FAIL: Found $VIOLATION_COUNT Editor namespace reference(s) in Runtime code:${NC}"
60+
echo ""
61+
echo "$VIOLATIONS"
62+
echo ""
63+
echo "${RED}Active patterns:${NC}"
64+
for re in "${FORBIDDEN_REGEX[@]}"; do
65+
printf ' \033[0;31m%s\033[0m\n' "$re"
66+
done
67+
exit 1

0 commit comments

Comments
 (0)