Skip to content

Commit 3d85161

Browse files
committed
task: migrate to FixedMathSharp and GridForge v6
1 parent 288af0f commit 3d85161

52 files changed

Lines changed: 2668 additions & 1178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.assets/scripts/new-gridforge-ci-test-project.ps1

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,54 @@ function Get-VariantSettings {
135135
}
136136
}
137137

138+
function ConvertTo-VersionDefineExpression {
139+
param(
140+
[string]$Version,
141+
[string]$Context
142+
)
143+
144+
if ([string]::IsNullOrWhiteSpace($Version)) {
145+
throw "$Context version must be non-empty."
146+
}
147+
148+
$expression = $Version.Trim()
149+
if ($expression.StartsWith("v", [System.StringComparison]::OrdinalIgnoreCase)) {
150+
$expression = $expression.Substring(1)
151+
}
152+
153+
if ([string]::IsNullOrWhiteSpace($expression)) {
154+
throw "$Context version expression must be non-empty."
155+
}
156+
157+
return $expression
158+
}
159+
160+
function Get-DependencyVersionDefineExpression {
161+
param(
162+
[object]$PackageConfig,
163+
[hashtable]$DependencyVersions,
164+
[string]$DependencyName
165+
)
166+
167+
foreach ($dependency in @($PackageConfig.dependencies)) {
168+
$name = Get-RequiredString -Object $dependency -PropertyName "name" -Context "Dependency"
169+
if ($name -ne $DependencyName) {
170+
continue
171+
}
172+
173+
$versionKey = Get-RequiredString -Object $dependency -PropertyName "versionKey" -Context "Dependency '$name'"
174+
if (-not $DependencyVersions.ContainsKey($versionKey)) {
175+
throw "Dependency '$name' uses unknown versionKey '$versionKey'."
176+
}
177+
178+
return ConvertTo-VersionDefineExpression `
179+
-Version ([string]$DependencyVersions[$versionKey]) `
180+
-Context "Dependency '$name'"
181+
}
182+
183+
throw "Package config does not define dependency '$DependencyName'."
184+
}
185+
138186
function ConvertTo-OrderedDependencyMap {
139187
param(
140188
[object]$PackageConfig,
@@ -226,6 +274,16 @@ if (-not $manifestDependencies.Contains($variant.SwiftCollectionsPackage)) {
226274
throw "Package '$PackageName' dependencies must include '$($variant.SwiftCollectionsPackage)'."
227275
}
228276

277+
$fixedMathVersionDefineExpression = Get-DependencyVersionDefineExpression `
278+
-PackageConfig $packageConfig `
279+
-DependencyVersions $dependencyVersions `
280+
-DependencyName $variant.FixedMathPackage
281+
282+
$swiftCollectionsVersionDefineExpression = Get-DependencyVersionDefineExpression `
283+
-PackageConfig $packageConfig `
284+
-DependencyVersions $dependencyVersions `
285+
-DependencyName $variant.SwiftCollectionsPackage
286+
229287
$manifest = [ordered]@{
230288
dependencies = $manifestDependencies
231289
}
@@ -268,12 +326,12 @@ $asmdef = [ordered]@{
268326
},
269327
[ordered]@{
270328
name = $variant.FixedMathPackage
271-
expression = "5.0.0"
329+
expression = $fixedMathVersionDefineExpression
272330
define = "GRIDFORGE_CI_HAS_FIXEDMATHSHARP"
273331
},
274332
[ordered]@{
275333
name = $variant.SwiftCollectionsPackage
276-
expression = "5.0.0"
334+
expression = $swiftCollectionsVersionDefineExpression
277335
define = "GRIDFORGE_CI_HAS_SWIFTCOLLECTIONS"
278336
}
279337
)

.assets/scripts/test-update-unity-package-versions.ps1

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,22 @@ function New-TestRepo {
5959
{
6060
"name": "com.mrdav30.fixedmathsharp",
6161
"gitUrl": "https://github.com/mrdav30/FixedMathSharp-Unity.git?path=/com.mrdav30.fixedmathsharp",
62-
"versionKey": "FixedMathSharpUnity"
62+
"versionKey": "FixedMathSharpUnity",
63+
"asmdefVersionDefine": true
6364
},
6465
{
6566
"name": "com.mrdav30.swiftcollections",
6667
"gitUrl": "https://github.com/mrdav30/SwiftCollections-Unity.git?path=/com.mrdav30.swiftcollections",
67-
"versionKey": "SwiftCollectionsUnity"
68+
"versionKey": "SwiftCollectionsUnity",
69+
"asmdefVersionDefine": true
6870
}
71+
],
72+
"asmdefs": [
73+
"Runtime/GridForge.Runtime.asmdef"
74+
],
75+
"optionalAsmdefs": [
76+
"Samples/GridforgeDemo/GridForge.Samples.asmdef",
77+
"Samples/GridforgeDemo/Missing.Optional.asmdef"
6978
]
7079
},
7180
{
@@ -76,13 +85,21 @@ function New-TestRepo {
7685
{
7786
"name": "com.mrdav30.fixedmathsharp.lean",
7887
"gitUrl": "https://github.com/mrdav30/FixedMathSharp-Unity.git?path=/com.mrdav30.fixedmathsharp.lean",
79-
"versionKey": "FixedMathSharpUnity"
88+
"versionKey": "FixedMathSharpUnity",
89+
"asmdefVersionDefine": true
8090
},
8191
{
8292
"name": "com.mrdav30.swiftcollections.lean",
8393
"gitUrl": "https://github.com/mrdav30/SwiftCollections-Unity.git?path=/com.mrdav30.swiftcollections.lean",
84-
"versionKey": "SwiftCollectionsUnity"
94+
"versionKey": "SwiftCollectionsUnity",
95+
"asmdefVersionDefine": true
8596
}
97+
],
98+
"asmdefs": [
99+
"Runtime/GridForge.Lean.Runtime.asmdef"
100+
],
101+
"optionalAsmdefs": [
102+
"Samples/GridforgeDemo/GridForge.Lean.Samples.asmdef"
86103
]
87104
}
88105
]
@@ -135,6 +152,86 @@ private static readonly Dependency[] RequiredDependencies =
135152
"v4.0.0"
136153
)
137154
};
155+
'@
156+
157+
New-TestFile -Path (Join-Path $repoRoot "com.mrdav30.gridforge/Runtime/GridForge.Runtime.asmdef") -Content @'
158+
{
159+
"name": "GridForge.Runtime",
160+
"defineConstraints": [
161+
"GRIDFORGE_HAS_FIXEDMATHSHARP",
162+
"GRIDFORGE_HAS_SWIFTCOLLECTIONS"
163+
],
164+
"versionDefines": [
165+
{
166+
"name": "com.mrdav30.fixedmathsharp",
167+
"expression": "4.0.0",
168+
"define": "GRIDFORGE_HAS_FIXEDMATHSHARP"
169+
},
170+
{
171+
"name": "com.mrdav30.swiftcollections",
172+
"expression": "4.0.0",
173+
"define": "GRIDFORGE_HAS_SWIFTCOLLECTIONS"
174+
}
175+
]
176+
}
177+
'@
178+
179+
New-TestFile -Path (Join-Path $repoRoot "com.mrdav30.gridforge/Samples/GridforgeDemo/GridForge.Samples.asmdef") -Content @'
180+
{
181+
"name": "GridForge.Samples",
182+
"versionDefines": [
183+
{
184+
"name": "com.mrdav30.fixedmathsharp",
185+
"expression": "4.0.0",
186+
"define": "GRIDFORGE_HAS_FIXEDMATHSHARP"
187+
},
188+
{
189+
"name": "com.mrdav30.swiftcollections",
190+
"expression": "4.0.0",
191+
"define": "GRIDFORGE_HAS_SWIFTCOLLECTIONS"
192+
}
193+
]
194+
}
195+
'@
196+
197+
New-TestFile -Path (Join-Path $repoRoot "com.mrdav30.gridforge.lean/Runtime/GridForge.Lean.Runtime.asmdef") -Content @'
198+
{
199+
"name": "GridForge.Lean.Runtime",
200+
"defineConstraints": [
201+
"GRIDFORGE_LEAN_HAS_FIXEDMATHSHARP",
202+
"GRIDFORGE_LEAN_HAS_SWIFTCOLLECTIONS"
203+
],
204+
"versionDefines": [
205+
{
206+
"name": "com.mrdav30.fixedmathsharp.lean",
207+
"expression": "4.0.0",
208+
"define": "GRIDFORGE_LEAN_HAS_FIXEDMATHSHARP"
209+
},
210+
{
211+
"name": "com.mrdav30.swiftcollections.lean",
212+
"expression": "4.0.0",
213+
"define": "GRIDFORGE_LEAN_HAS_SWIFTCOLLECTIONS"
214+
}
215+
]
216+
}
217+
'@
218+
219+
New-TestFile -Path (Join-Path $repoRoot "com.mrdav30.gridforge.lean/Samples/GridforgeDemo/GridForge.Lean.Samples.asmdef") -Content @'
220+
{
221+
"name": "GridForge.Lean.Samples",
222+
"versionDefines": [
223+
{
224+
"name": "com.mrdav30.fixedmathsharp.lean",
225+
"expression": "4.0.0",
226+
"define": "GRIDFORGE_LEAN_HAS_FIXEDMATHSHARP"
227+
},
228+
{
229+
"name": "com.mrdav30.swiftcollections.lean",
230+
"expression": "4.0.0",
231+
"define": "GRIDFORGE_LEAN_HAS_SWIFTCOLLECTIONS"
232+
}
233+
]
234+
}
138235
'@
139236

140237
return $repoRoot
@@ -198,10 +295,22 @@ function Test-ApplyUpdatesPackageAndInstallerVersions {
198295
Assert-Contains -Text $standardInstaller -Expected "https://github.com/mrdav30/SwiftCollections-Unity.git?path=/com.mrdav30.swiftcollections" -Message "Apply should update standard SwiftCollections git URL."
199296
Assert-Contains -Text $standardInstaller -Expected '"v5.0.0"' -Message "Apply should update standard dependency versions."
200297

298+
$standardAsmdef = Get-FileText -Path (Join-Path $repoRoot "com.mrdav30.gridforge/Runtime/GridForge.Runtime.asmdef")
299+
Assert-Contains -Text $standardAsmdef -Expected '"expression": "5.0.0"' -Message "Apply should update standard asmdef dependency version defines."
300+
301+
$standardAuthoringSamplesAsmdef = Get-FileText -Path (Join-Path $repoRoot "com.mrdav30.gridforge/Samples/GridforgeDemo/GridForge.Samples.asmdef")
302+
Assert-Contains -Text $standardAuthoringSamplesAsmdef -Expected '"expression": "5.0.0"' -Message "Apply should update optional standard authoring sample asmdef dependency version defines."
303+
201304
$leanInstaller = Get-FileText -Path (Join-Path $repoRoot "com.mrdav30.gridforge.lean/Editor/Utility/DependencyInstaller/GitDependencyInstaller.cs")
202305
Assert-Contains -Text $leanInstaller -Expected "https://github.com/mrdav30/FixedMathSharp-Unity.git?path=/com.mrdav30.fixedmathsharp.lean" -Message "Apply should update lean FixedMathSharp git URL."
203306
Assert-Contains -Text $leanInstaller -Expected "https://github.com/mrdav30/SwiftCollections-Unity.git?path=/com.mrdav30.swiftcollections.lean" -Message "Apply should update lean SwiftCollections git URL."
204307
Assert-Contains -Text $leanInstaller -Expected '"v5.0.0"' -Message "Apply should update lean dependency versions."
308+
309+
$leanAsmdef = Get-FileText -Path (Join-Path $repoRoot "com.mrdav30.gridforge.lean/Runtime/GridForge.Lean.Runtime.asmdef")
310+
Assert-Contains -Text $leanAsmdef -Expected '"expression": "5.0.0"' -Message "Apply should update lean asmdef dependency version defines."
311+
312+
$leanAuthoringSamplesAsmdef = Get-FileText -Path (Join-Path $repoRoot "com.mrdav30.gridforge.lean/Samples/GridforgeDemo/GridForge.Lean.Samples.asmdef")
313+
Assert-Contains -Text $leanAuthoringSamplesAsmdef -Expected '"expression": "5.0.0"' -Message "Apply should update optional lean authoring sample asmdef dependency version defines."
205314
}
206315

207316
function Test-ValidateOnlyFailsWhenFilesDrift {

.assets/scripts/update-unity-package-versions.ps1

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ function Get-OptionalBoolean {
102102
return [bool]$property.Value
103103
}
104104

105+
function ConvertTo-UnityVersionDefineExpression {
106+
param(
107+
[string]$Version,
108+
[string]$Context
109+
)
110+
111+
if ([string]::IsNullOrWhiteSpace($Version)) {
112+
throw "$Context version must be non-empty."
113+
}
114+
115+
$expression = $Version.Trim()
116+
if ($expression.StartsWith("v", [System.StringComparison]::OrdinalIgnoreCase)) {
117+
$expression = $expression.Substring(1)
118+
}
119+
120+
if ([string]::IsNullOrWhiteSpace($expression)) {
121+
throw "$Context version expression must be non-empty."
122+
}
123+
124+
return $expression
125+
}
126+
105127
function Read-JsonFile {
106128
param([string]$Path)
107129

@@ -266,6 +288,86 @@ function Update-InstallerDependencies {
266288
}
267289
}
268290

291+
function Update-AsmdefVersionDefines {
292+
param(
293+
[string]$AsmdefPath,
294+
[object[]]$Dependencies,
295+
[hashtable]$DependencyVersions,
296+
[string]$DisplayPath,
297+
[System.Collections.Generic.List[string]]$ChangeMessages,
298+
[System.Collections.Generic.List[string]]$ValidationIssues
299+
)
300+
301+
if (-not (Test-Path -LiteralPath $AsmdefPath)) {
302+
throw "Configured asmdef does not exist: $DisplayPath"
303+
}
304+
305+
$content = Get-Content -Raw -LiteralPath $AsmdefPath
306+
$updatedContent = $content
307+
$hasChanges = $false
308+
$configuredVersionDefineCount = 0
309+
310+
foreach ($dependency in $Dependencies) {
311+
if (-not (Get-OptionalBoolean -Object $dependency -PropertyName "asmdefVersionDefine" -DefaultValue $false)) {
312+
continue
313+
}
314+
315+
$configuredVersionDefineCount++
316+
$name = Get-RequiredString -Object $dependency -PropertyName "name" -Context "Dependency in '$DisplayPath'"
317+
$versionKey = Get-RequiredString -Object $dependency -PropertyName "versionKey" -Context "Dependency '$name' in '$DisplayPath'"
318+
319+
if (-not $DependencyVersions.ContainsKey($versionKey)) {
320+
throw "Dependency '$name' in '$DisplayPath' uses unknown versionKey '$versionKey'."
321+
}
322+
323+
$desiredExpression = ConvertTo-UnityVersionDefineExpression `
324+
-Version ([string]$DependencyVersions[$versionKey]) `
325+
-Context "Dependency '$name' in '$DisplayPath'"
326+
327+
$pattern = '(?ms)(?<prefix>\{\s*"name"\s*:\s*"' +
328+
[regex]::Escape($name) +
329+
'"\s*,\s*"expression"\s*:\s*")(?<expression>[^"]+)(?<suffix>"\s*,\s*"define"\s*:\s*"[^"]+"\s*\})'
330+
331+
$match = [regex]::Match($updatedContent, $pattern)
332+
if (-not $match.Success) {
333+
throw "Could not find asmdef versionDefine for dependency '$name' in '$DisplayPath'."
334+
}
335+
336+
$currentExpression = $match.Groups["expression"].Value
337+
if ($currentExpression -eq $desiredExpression) {
338+
continue
339+
}
340+
341+
$message = "$DisplayPath $name versionDefine expression $currentExpression -> $desiredExpression"
342+
$ChangeMessages.Add($message)
343+
344+
if ($ValidateOnly) {
345+
$ValidationIssues.Add($message)
346+
}
347+
else {
348+
Write-Output "$Mode $message"
349+
}
350+
351+
$hasChanges = $true
352+
353+
if ($Apply) {
354+
$replacement = $match.Groups["prefix"].Value +
355+
$desiredExpression +
356+
$match.Groups["suffix"].Value
357+
358+
$updatedContent = $updatedContent.Remove($match.Index, $match.Length).Insert($match.Index, $replacement)
359+
}
360+
}
361+
362+
if ($configuredVersionDefineCount -eq 0) {
363+
throw "Package config lists asmdef '$DisplayPath' but no dependency has asmdefVersionDefine enabled."
364+
}
365+
366+
if ($Apply -and $hasChanges) {
367+
Set-Content -LiteralPath $AsmdefPath -Value $updatedContent -Encoding UTF8 -NoNewline
368+
}
369+
}
370+
269371
function Test-InstallerDependencySet {
270372
param(
271373
[string]$Content,
@@ -373,6 +475,37 @@ foreach ($package in @($packagesProperty.Value)) {
373475
-DisplayPath $installerDisplayPath `
374476
-ChangeMessages $changeMessages `
375477
-ValidationIssues $validationIssues
478+
479+
foreach ($asmdefGroup in @(
480+
[pscustomobject]@{ PropertyName = "asmdefs"; Required = $true },
481+
[pscustomobject]@{ PropertyName = "optionalAsmdefs"; Required = $false }
482+
)) {
483+
$asmdefsProperty = $package.PSObject.Properties[$asmdefGroup.PropertyName]
484+
if ($null -eq $asmdefsProperty -or $null -eq $asmdefsProperty.Value) {
485+
continue
486+
}
487+
488+
foreach ($asmdefRelativePath in @($asmdefsProperty.Value)) {
489+
if ([string]::IsNullOrWhiteSpace([string]$asmdefRelativePath)) {
490+
throw "Package '$packagePath' contains an empty $($asmdefGroup.PropertyName) path."
491+
}
492+
493+
$asmdefPath = Resolve-ConfiguredPath -BasePath $packageDirectory -Path ([string]$asmdefRelativePath)
494+
$asmdefDisplayPath = Get-DisplayPath -Path $asmdefPath -BasePath $repoRoot
495+
496+
if (-not $asmdefGroup.Required -and -not (Test-Path -LiteralPath $asmdefPath)) {
497+
continue
498+
}
499+
500+
Update-AsmdefVersionDefines `
501+
-AsmdefPath $asmdefPath `
502+
-Dependencies @($dependenciesProperty.Value) `
503+
-DependencyVersions $dependencyVersions `
504+
-DisplayPath $asmdefDisplayPath `
505+
-ChangeMessages $changeMessages `
506+
-ValidationIssues $validationIssues
507+
}
508+
}
376509
}
377510

378511
if ($ValidateOnly -and $validationIssues.Count -gt 0) {

0 commit comments

Comments
 (0)