Skip to content

Commit 2a46b78

Browse files
Copilotvaind
andcommitted
Address review comments: optimize CMake detection and handle quoted GIT_TAG values
Co-authored-by: vaind <[email protected]>
1 parent 8755268 commit 2a46b78

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

updater/scripts/update-dependency.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function SetOutput([string] $name, $value)
4040
if (-not $isSubmodule)
4141
{
4242
$isScript = $Path -match '\.(ps1|sh)$'
43-
$isCMake = $Path -match '\.(cmake|txt)$' -or ((Test-Path $Path -PathType Leaf) -and ((Get-Content $Path -Raw -ErrorAction SilentlyContinue) -match 'FetchContent_Declare'))
43+
$isCMake = $Path -match '\.(cmake|txt)$' -or ((Test-Path $Path -PathType Leaf) -and $Path -notmatch '\.(ps1|sh)$' -and ((Get-Content $Path -Raw -ErrorAction SilentlyContinue) -match 'FetchContent_Declare'))
4444
function DependencyConfig ([Parameter(Mandatory = $true)][string] $action, [string] $value = $null)
4545
{
4646
if ($isScript)
@@ -76,9 +76,13 @@ if (-not $isSubmodule)
7676
'get-version'
7777
{
7878
$content = Get-Content $Path -Raw
79-
if ($content -match '(?m)^\s*GIT_TAG\s+([^\s#]+)')
79+
if ($content -match '(?m)^\s*GIT_TAG\s+(?:"([^"]+)"|([^\s#]+))')
8080
{
81-
return $Matches[1]
81+
if ($Matches[1]) {
82+
return $Matches[1]
83+
} else {
84+
return $Matches[2]
85+
}
8286
}
8387
throw "Could not find GIT_TAG in CMake file $Path"
8488
}
@@ -97,9 +101,17 @@ if (-not $isSubmodule)
97101
$updated = $false
98102
for ($i = 0; $i -lt $content.Length; $i++)
99103
{
100-
if ($content[$i] -match '^(\s*GIT_TAG\s+)[^\s#]+(.*)$')
104+
if ($content[$i] -match '^(\s*GIT_TAG\s+)(")([^"]+)(".*)$')
105+
{
106+
# Quoted version - preserve quotes
107+
$content[$i] = $Matches[1] + $Matches[2] + $value + $Matches[4]
108+
$updated = $true
109+
break
110+
}
111+
elseif ($content[$i] -match '^(\s*GIT_TAG\s+)([^\s#]+)(.*)$')
101112
{
102-
$content[$i] = $Matches[1] + $value + $Matches[2]
113+
# Unquoted version
114+
$content[$i] = $Matches[1] + $value + $Matches[3]
103115
$updated = $true
104116
break
105117
}

updater/tests/update-dependency.Tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,5 +346,19 @@ switch ($action)
346346
$content = Get-Content $testFile
347347
$content[4] | Should -Match "GIT_TAG $currentVersion"
348348
}
349+
350+
It 'handles quoted GIT_TAG values' {
351+
$testFile = "$testDir/test.cmake"
352+
@(
353+
'FetchContent_Declare(',
354+
' dependency',
355+
" GIT_REPOSITORY $repoUrl",
356+
' GIT_TAG "v0.0.1"',
357+
')'
358+
) | Out-File $testFile
359+
UpdateDependency $testFile
360+
$content = Get-Content $testFile
361+
$content[3] | Should -Match "GIT_TAG `"$currentVersion`""
362+
}
349363
}
350364
}

0 commit comments

Comments
 (0)