File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ function SetOutput([string] $name, $value)
4040if (-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 }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments