|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Guards the published shape of the com.immutable.audience package. |
| 4 | +# |
| 5 | +# When the package is installed from a git URL, Unity copies the folder into an |
| 6 | +# immutable PackageCache verbatim. Every asset there must have a .meta companion |
| 7 | +# or the asset is dropped, which turns into a fatal error on device builds. |
| 8 | +# Non-Unity tooling files (csproj, props, sln) have no place in the package and |
| 9 | +# trip the same failure because their .meta files are intentionally gitignored. |
| 10 | +# |
| 11 | +# This check fails the build if either problem is reintroduced. |
| 12 | + |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +PKG="src/Packages/Audience" |
| 16 | +status=0 |
| 17 | + |
| 18 | +# Files that should never ship inside the package. |
| 19 | +forbidden=$(git ls-files "$PKG" \ |
| 20 | + | grep -E '\.(csproj|sln)$|/Directory\.Build\.(props|targets)$' || true) |
| 21 | +if [ -n "$forbidden" ]; then |
| 22 | + echo "ERROR: non-Unity tooling files tracked inside $PKG (move them out of the package):" |
| 23 | + while IFS= read -r f; do |
| 24 | + printf ' %s\n' "$f" |
| 25 | + done <<< "$forbidden" |
| 26 | + status=1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Every tracked asset must have a tracked .meta companion. Dotfiles and dot |
| 30 | +# folders are ignored by Unity, so they are exempt. |
| 31 | +missing="" |
| 32 | +while IFS= read -r f; do |
| 33 | + case "$f" in |
| 34 | + *.meta) continue ;; |
| 35 | + */.*) continue ;; |
| 36 | + .*) continue ;; |
| 37 | + esac |
| 38 | + if ! git ls-files --error-unmatch "$f.meta" >/dev/null 2>&1; then |
| 39 | + missing="$missing $f"$'\n' |
| 40 | + fi |
| 41 | +done < <(git ls-files "$PKG") |
| 42 | + |
| 43 | +if [ -n "$missing" ]; then |
| 44 | + echo "ERROR: assets in $PKG are missing a committed .meta companion:" |
| 45 | + printf '%s' "$missing" |
| 46 | + status=1 |
| 47 | +fi |
| 48 | + |
| 49 | +# Every tracked .meta must have a matching asset. The asset is either a tracked |
| 50 | +# file or, for Unity folder metas, a directory that holds tracked files. An |
| 51 | +# orphan meta left behind by `git rm`-ing an asset keeps a stale GUID around. |
| 52 | +orphan="" |
| 53 | +while IFS= read -r m; do |
| 54 | + base="${m%.meta}" |
| 55 | + if git ls-files --error-unmatch "$base" >/dev/null 2>&1; then |
| 56 | + continue |
| 57 | + fi |
| 58 | + if [ -n "$(git ls-files "$base/")" ]; then |
| 59 | + continue |
| 60 | + fi |
| 61 | + orphan="$orphan $m"$'\n' |
| 62 | +done < <(git ls-files "$PKG" | grep -E '\.meta$' || true) |
| 63 | + |
| 64 | +if [ -n "$orphan" ]; then |
| 65 | + echo "ERROR: orphan .meta files in $PKG (no matching asset, stale GUID):" |
| 66 | + printf '%s' "$orphan" |
| 67 | + status=1 |
| 68 | +fi |
| 69 | + |
| 70 | +if [ "$status" -eq 0 ]; then |
| 71 | + echo "OK: $PKG is meta-complete and free of non-Unity tooling files." |
| 72 | +fi |
| 73 | +exit "$status" |
0 commit comments