From 88eb365c05a6dfc84ad2a26df8ab21ee92ce471d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 14 Sep 2026 13:57:03 +0200 Subject: [PATCH] Check bridge declarations, not file names; strip manifest BOMs build-unity-package.ps1 read the bridge's file names to decide whether it re-declared core CultMath sources. It now parses declarations: core type names come from src/CultMath (comments stripped), and every bridge source may declare types only in CultMath.UnityBridge and never a core type name. Probed by injecting "struct float3" into UnityConversions.cs: the script throws. Strips the UTF-8 BOMs this branch added to both Unity package.json files. Co-Authored-By: Claude Opus 5 --- .../cultmath/scripts/build-unity-package.ps1 | 31 +++++++++++++++---- .../unity/org.gamecult.cultmath/package.json | 2 +- .../Assets/Caching/package.json | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/cultmath/scripts/build-unity-package.ps1 b/packages/cultmath/scripts/build-unity-package.ps1 index 7bc3da7c..7db1fbda 100644 --- a/packages/cultmath/scripts/build-unity-package.ps1 +++ b/packages/cultmath/scripts/build-unity-package.ps1 @@ -110,13 +110,32 @@ foreach ($pair in @(@($freshAssembly, $trackedAssembly), @($freshSymbols, $track } } -$coreSourceNames = @(Get-ChildItem -LiteralPath (Join-Path $repoRoot "src\CultMath") -File -Filter "*.cs" | ForEach-Object Name) $trackedSourceFiles = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -File -Filter "*.cs") -$strayOrCoreSources = @($trackedSourceFiles | Where-Object { - $_.DirectoryName -ne $bridgeRoot -or $coreSourceNames -contains $_.Name -}) -if ($trackedSourceFiles.Count -eq 0 -or $strayOrCoreSources.Count -ne 0) { - throw "CultMath Unity package may compile only bridge sources under Runtime\UnityBridge, never core sources: $($strayOrCoreSources.FullName -join ', ')" +$straySources = @($trackedSourceFiles | Where-Object { $_.DirectoryName -ne $bridgeRoot }) +if ($trackedSourceFiles.Count -eq 0 -or $straySources.Count -ne 0) { + throw "CultMath Unity package may compile only bridge sources under Runtime\UnityBridge: $($straySources.FullName -join ', ')" +} + +# Check what the bridge declares, not what its files are called: it may declare types only in +# CultMath.UnityBridge and never a type name the core CultMath sources declare. +$declarationPattern = '\b(?:struct|class|enum|interface|record|delegate\s+[\w<>.,\s]+?)\s+(\w+)' +function Get-CodeWithoutComments([string]$path) { + $text = Get-Content -LiteralPath $path -Raw + return [regex]::Replace($text, '(?s)/\*.*?\*/|//[^\r\n]*', '') +} +$coreTypeNames = @(Get-ChildItem -LiteralPath (Join-Path $repoRoot "src\CultMath") -File -Filter "*.cs" | ForEach-Object { + [regex]::Matches((Get-CodeWithoutComments $_.FullName), $declarationPattern) | ForEach-Object { $_.Groups[1].Value } +} | Sort-Object -Unique) +if ($coreTypeNames -notcontains "float3" -or $coreTypeNames -notcontains "math") { + throw "Could not read CultMath core type declarations; the bridge check would be vacuous" +} +foreach ($source in $trackedSourceFiles) { + $code = Get-CodeWithoutComments $source.FullName + $redeclared = @([regex]::Matches($code, $declarationPattern) | ForEach-Object { $_.Groups[1].Value } | Where-Object { $coreTypeNames -contains $_ }) + $foreignNamespaces = @([regex]::Matches($code, '\bnamespace\s+([\w.]+)') | ForEach-Object { $_.Groups[1].Value } | Where-Object { $_ -ne "CultMath.UnityBridge" }) + if ($redeclared.Count -ne 0 -or $foreignNamespaces.Count -ne 0) { + throw "CultMath.UnityBridge source $($source.Name) re-declares core types [$($redeclared -join ', ')] or uses namespaces [$($foreignNamespaces -join ', ')]; the precompiled DLL owns CultMath's types" + } } New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null diff --git a/packages/cultmath/unity/org.gamecult.cultmath/package.json b/packages/cultmath/unity/org.gamecult.cultmath/package.json index 302eb481..c09bf6bb 100644 --- a/packages/cultmath/unity/org.gamecult.cultmath/package.json +++ b/packages/cultmath/unity/org.gamecult.cultmath/package.json @@ -1,4 +1,4 @@ -{ +{ "name": "org.gamecult.cultmath", "displayName": "CultMath", "version": "0.2.0", diff --git a/src/GameCult.Unity/Assets/Caching/package.json b/src/GameCult.Unity/Assets/Caching/package.json index 560600a9..9f3df603 100644 --- a/src/GameCult.Unity/Assets/Caching/package.json +++ b/src/GameCult.Unity/Assets/Caching/package.json @@ -1,4 +1,4 @@ -{ +{ "name": "org.gamecult.caching.unity", "displayName": "GameCult CultCache Unity Tools", "version": "1.1.0",