Skip to content

Commit 669db4d

Browse files
committed
Improve parsing extension name from config.w32
1 parent 9662a1e commit 669db4d

3 files changed

Lines changed: 60 additions & 13 deletions

File tree

extension/BuildPhpExtension/BuildPhpExtension.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'Get-BuildDirectory',
8484
'Get-Extension',
8585
'Get-ExtensionConfig',
86+
'Get-ExtensionName',
8687
'Get-ExtensionSource',
8788
'Get-File',
8889
'Get-LibrariesFromConfig',

extension/BuildPhpExtension/private/Get-Extension.ps1

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,7 @@ function Get-Extension {
114114
Copy-Item -Path "${subDirectory}\*" -Destination $BuildDirectory -Recurse -Force
115115
Remove-Item -Path $subDirectory -Recurse -Force
116116
}
117-
$configW32Content = Get-Content -Path "config.w32"
118-
$extensionLine = $configW32Content | Select-String -Pattern '\s+(ZEND_)?EXTENSION\(' | Select-Object -Last 1
119-
if($null -eq $extensionLine) {
120-
throw "No extension found in config.w32"
121-
}
122-
$name = ($extensionLine -replace '.*EXTENSION\(([^,]+),.*', '$1') -replace '["'']', ''
123-
if($name.Contains('oci8')) {
124-
$name = 'oci8_19'
125-
} elseif ([string]$configW32Content -match ($([regex]::Escape($name)) + '\s*=\s*["''](.+?)["'']')) {
126-
if($matches[1] -ne 'no') {
127-
$name = $matches[1]
128-
}
129-
}
117+
$name = Get-ExtensionName
130118

131119
if(!$patches) {
132120
Add-Patches "${name}.ps1"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function Get-ExtensionName {
2+
<#
3+
.SYNOPSIS
4+
Get the PHP extension name.
5+
#>
6+
[OutputType()]
7+
param (
8+
)
9+
begin {
10+
}
11+
process {
12+
$configW32Content = Get-Content -Path "config.w32"
13+
$extMatch = [regex]::Matches(
14+
$configW32Content,
15+
'(?is)\b(?:ZEND_)?EXTENSION\s*\(\s*(?<arg>.*?)\s*,'
16+
) | Select-Object -Last 1
17+
18+
if (-not $extMatch) {
19+
throw "No extension found in config.w32 ($Path)"
20+
}
21+
22+
$token = $extMatch.Groups['arg'].Value.Trim()
23+
24+
if ($token.Length -ge 2 -and (
25+
($token[0] -eq "'" -and $token[-1] -eq "'") -or
26+
($token[0] -eq '"' -and $token[-1] -eq '"')
27+
)) {
28+
$name = $token.Trim('"', "'").Trim()
29+
}
30+
else {
31+
$varNameEsc = [regex]::Escape($token)
32+
33+
$assignPattern =
34+
'(?is)(?:^|[;{\s])' +
35+
'(?:(?:var|let|const)\s+)?' +
36+
$varNameEsc +
37+
'\s*=\s*(?<q>["\x27])(?<val>[^"\x27]+)\k<q>'
38+
39+
$m = [regex]::Match($configW32Content, $assignPattern)
40+
if ($m.Success) {
41+
$val = $m.Groups['val'].Value
42+
if ($val -and $val -ne 'no') {
43+
$name = $val
44+
} else {
45+
$name = $token
46+
}
47+
} else {
48+
$name = $token
49+
}
50+
}
51+
if ($name -like '*oci8*') {
52+
$name = 'oci8_19'
53+
}
54+
return $name.Trim()
55+
}
56+
end {
57+
}
58+
}

0 commit comments

Comments
 (0)