Skip to content

Commit fd068f6

Browse files
committed
Use Add-PhpDeps for overrideable dependency resolution
1 parent bc50a8a commit fd068f6

File tree

10 files changed

+206
-103
lines changed

10 files changed

+206
-103
lines changed

.github/workflows/test-php-libs-from-source.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,12 @@ jobs:
8787
}
8888
$phpVersion = [regex]::Match($zip.Name, '^php-(.+?)-(?:nts-)?Win32-v[sc]\d+-').Groups[1].Value
8989
90-
$pv = $phpVersion
91-
if($phpVersion -ne 'master') {
92-
$pv = $phpVersion.Split('.')[0..1] -join '.'
93-
}
94-
$libsBuildRunsKey = 'default'
95-
$libsBuildRuns = @('${{ inputs.libs-build-runs }}' -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }) -join ','
96-
if ($libsBuildRuns) {
97-
$libsBuildRunsKey = [System.Convert]::ToHexString(
98-
[System.Security.Cryptography.SHA256]::HashData(
99-
[System.Text.Encoding]::UTF8.GetBytes($libsBuildRuns)
100-
)
101-
).ToLowerInvariant().Substring(0, 16)
102-
}
103-
$vsVersion = (Get-Content -Raw -Path (Join-Path $(pwd).Path '\php\BuildPhp\config\vs.json') | ConvertFrom-Json).php.$pv
104-
$packagesListUrl = "https://downloads.php.net/~windows/php-sdk/deps/series/packages-$pv-$vsVersion-${{ matrix.arch }}-staging.txt"
105-
Invoke-WebRequest -OutFile packages.txt -Uri $packagesListUrl
90+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
91+
$cacheInfo = Get-DepsCacheInfo -PhpVersion $phpVersion -Arch '${{ matrix.arch }}' -LibsBuildRuns '${{ inputs.libs-build-runs }}' -IncludeDefaultRunsKey
92+
Set-Content -Path packages.txt -Value ($cacheInfo.Packages -join "`n")
10693
Add-Content -Value "php-version=$phpVersion" -Path $env:GITHUB_OUTPUT
107-
Add-Content -Value "cache-key=deps-$pv-${{ matrix.arch }}-$libsBuildRunsKey" -Path $env:GITHUB_OUTPUT
108-
Add-Content -Value "cache-dir=C:\deps-$pv-${{ matrix.arch }}" -Path $env:GITHUB_OUTPUT
94+
Add-Content -Value "cache-key=$($cacheInfo.CacheKey)" -Path $env:GITHUB_OUTPUT
95+
Add-Content -Value "cache-dir=$($cacheInfo.CacheDir)" -Path $env:GITHUB_OUTPUT
10996
11097
- name: Cache Deps
11198
id: cache-deps

.github/workflows/test-php-libs.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,11 @@ jobs:
6565
- name: Get Cache Key
6666
id: cache-key
6767
run: |
68-
$pv = '${{inputs.php-version}}'
69-
if('${{inputs.php-version}}' -ne 'master') {
70-
$pv = '${{inputs.php-version}}'.Split('.')[0..1] -join '.'
71-
}
72-
$libsBuildRunsKey = 'default'
73-
$libsBuildRuns = @('${{ inputs.libs-build-runs }}' -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }) -join ','
74-
if ($libsBuildRuns) {
75-
$libsBuildRunsKey = [System.Convert]::ToHexString(
76-
[System.Security.Cryptography.SHA256]::HashData(
77-
[System.Text.Encoding]::UTF8.GetBytes($libsBuildRuns)
78-
)
79-
).ToLowerInvariant().Substring(0, 16)
80-
}
81-
$vsVersion = (Get-Content -Raw -Path (Join-Path $(pwd).Path '\php\BuildPhp\config\vs.json') | ConvertFrom-Json).php.$pv
82-
$packagesListUrl = "https://downloads.php.net/~windows/php-sdk/deps/series/packages-$pv-$vsVersion-${{ matrix.arch }}-staging.txt"
83-
Invoke-WebRequest -OutFile packages.txt -Uri $packagesListUrl
84-
Add-Content -Value "cache-key=deps-$pv-${{ matrix.arch }}-$libsBuildRunsKey" -Path $env:GITHUB_OUTPUT
85-
Add-Content -Value "cache-dir=C:\deps-$pv-${{ matrix.arch }}" -Path $env:GITHUB_OUTPUT
68+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
69+
$cacheInfo = Get-DepsCacheInfo -PhpVersion '${{inputs.php-version}}' -Arch '${{ matrix.arch }}' -LibsBuildRuns '${{ inputs.libs-build-runs }}' -IncludeDefaultRunsKey
70+
Set-Content -Path packages.txt -Value ($cacheInfo.Packages -join "`n")
71+
Add-Content -Value "cache-key=$($cacheInfo.CacheKey)" -Path $env:GITHUB_OUTPUT
72+
Add-Content -Value "cache-dir=$($cacheInfo.CacheDir)" -Path $env:GITHUB_OUTPUT
8673
8774
- name: Cache Deps
8875
id: cache-deps

php/BuildPhp/BuildPhp.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767
'Add-PhpDeps',
6868
'Add-TestRequirements',
6969
'Add-Vs',
70+
'Get-DepsCacheInfo',
7071
'Get-File',
7172
'Get-LibsBuildDeps',
7273
'Get-OciSdk',
74+
'Get-PhpDepsPackages',
7375
'Get-PhpBuild',
7476
'Get-PhpSdk',
7577
'Get-PhpSrc',
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"8.2": {
3+
"maxVersion": "8.2.30",
4+
"libraries": {
5+
"libcurl": "8.19.0"
6+
}
7+
},
8+
"8.3": {
9+
"maxVersion": "8.3.30",
10+
"libraries": {
11+
"libcurl": "8.19.0"
12+
}
13+
},
14+
"8.4": {
15+
"maxVersion": "8.4.20",
16+
"libraries": {
17+
"libcurl": "8.19.0"
18+
}
19+
},
20+
"8.5": {
21+
"maxVersion": "8.5.5",
22+
"libraries": {
23+
"libcurl": "8.19.0-1"
24+
}
25+
}
26+
}

php/BuildPhp/private/Add-PhpDeps.ps1

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,15 @@ function Add-PhpDeps {
3636
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
3737
}
3838

39-
$depsPhpVersion = $PhpVersion
40-
if ($PhpVersion -ne 'master') {
41-
$versionParts = $PhpVersion.Split('.')
42-
if ($versionParts.Count -ge 2) {
43-
$depsPhpVersion = $versionParts[0..1] -join '.'
44-
}
45-
}
46-
4739
$downloadedLibs = @()
4840
if ($env:LIBS_BUILD_RUNS) {
4941
$downloadedLibs = Get-LibsBuildDeps -Arch $Arch -Destination $Destination
5042
}
5143

52-
$seriesUrl = "$baseurl/series/packages-$depsPhpVersion-$VsVersion-$Arch-staging.txt"
53-
Write-Host "Fetching series listing: $seriesUrl"
54-
$series = Invoke-WebRequest -Uri $seriesUrl -UseBasicParsing -ErrorAction Stop
55-
$lines = @()
56-
if ($series -and $series.Content) {
57-
$lines = $series.Content -split "[\r\n]+" | Where-Object { $_ -and $_.Trim().Length -gt 0 }
44+
$packageData = Get-PhpDepsPackages -PhpVersion $PhpVersion -VsVersion $VsVersion -Arch $Arch
45+
$lines = @($packageData.Packages)
46+
if ($packageData.OverrideLibraries.Count -ne 0) {
47+
$downloadedLibs = @($downloadedLibs | Where-Object { $packageData.OverrideLibraries -notcontains $_ })
5848
}
5949

6050
foreach ($line in $lines) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
function Get-DepsCacheInfo {
2+
<#
3+
.SYNOPSIS
4+
Get dependency cache metadata for a PHP build.
5+
.PARAMETER PhpVersion
6+
PHP version (e.g., 8.4.18 or master).
7+
.PARAMETER Arch
8+
Target architecture: x86 or x64.
9+
.PARAMETER LibsBuildRuns
10+
Optional comma-separated workflow run IDs used for library overrides.
11+
.PARAMETER IncludeDefaultRunsKey
12+
Append "default" to the cache key when no workflow run IDs are provided.
13+
#>
14+
[CmdletBinding()]
15+
[OutputType([PSCustomObject])]
16+
param(
17+
[Parameter(Mandatory=$true)]
18+
[ValidateNotNullOrEmpty()]
19+
[string] $PhpVersion,
20+
[Parameter(Mandatory=$true)]
21+
[ValidateSet('x86','x64')]
22+
[string] $Arch,
23+
[Parameter(Mandatory=$false)]
24+
[string] $LibsBuildRuns = '',
25+
[Parameter(Mandatory=$false)]
26+
[switch] $IncludeDefaultRunsKey
27+
)
28+
29+
process {
30+
$depsPhpVersion = $PhpVersion
31+
if ($PhpVersion -ne 'master') {
32+
$versionParts = $PhpVersion.Split('.')
33+
if ($versionParts.Count -ge 2) {
34+
$depsPhpVersion = $versionParts[0..1] -join '.'
35+
}
36+
}
37+
38+
$runsKey = ''
39+
$normalizedRuns = @($LibsBuildRuns -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }) -join ','
40+
if ($normalizedRuns) {
41+
$runsKey = [System.Convert]::ToHexString(
42+
[System.Security.Cryptography.SHA256]::HashData(
43+
[System.Text.Encoding]::UTF8.GetBytes($normalizedRuns)
44+
)
45+
).ToLowerInvariant().Substring(0, 16)
46+
} elseif ($IncludeDefaultRunsKey) {
47+
$runsKey = 'default'
48+
}
49+
50+
$vsVersion = (Get-VsVersion -PhpVersion $PhpVersion).vs
51+
$packageData = Get-PhpDepsPackages -PhpVersion $PhpVersion -VsVersion $vsVersion -Arch $Arch
52+
53+
$cacheKey = "deps-$depsPhpVersion-$Arch"
54+
if ($runsKey) {
55+
$cacheKey += "-$runsKey"
56+
}
57+
58+
return [PSCustomObject]@{
59+
PhpVersion = $PhpVersion
60+
DepsPhpVersion = $depsPhpVersion
61+
VsVersion = $vsVersion
62+
CacheKey = $cacheKey
63+
CacheDir = "C:\deps-$depsPhpVersion-$Arch"
64+
Packages = @($packageData.Packages)
65+
OverrideLibraries = @($packageData.OverrideLibraries)
66+
}
67+
}
68+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
function Get-PhpDepsPackages {
2+
<#
3+
.SYNOPSIS
4+
Get PHP dependency packages, applying configured library overrides when required.
5+
.PARAMETER PhpVersion
6+
PHP version (e.g., 8.4.18, 8.4, or master).
7+
.PARAMETER VsVersion
8+
Visual Studio toolset version (e.g., vs16, vs17).
9+
.PARAMETER Arch
10+
Target architecture: x86 or x64.
11+
#>
12+
[CmdletBinding()]
13+
[OutputType([PSCustomObject])]
14+
param(
15+
[Parameter(Mandatory=$true)]
16+
[ValidateNotNullOrEmpty()]
17+
[string] $PhpVersion,
18+
[Parameter(Mandatory=$true)]
19+
[ValidateNotNullOrEmpty()]
20+
[string] $VsVersion,
21+
[Parameter(Mandatory=$true)]
22+
[ValidateSet('x86','x64')]
23+
[string] $Arch
24+
)
25+
26+
begin {
27+
$baseurl = 'https://downloads.php.net/~windows/php-sdk/deps'
28+
$configPath = Join-Path $PSScriptRoot '..\config\deps-overrides.json'
29+
}
30+
31+
process {
32+
$depsPhpVersion = $PhpVersion
33+
if ($PhpVersion -ne 'master') {
34+
$versionParts = $PhpVersion.Split('.')
35+
if ($versionParts.Count -ge 2) {
36+
$depsPhpVersion = $versionParts[0..1] -join '.'
37+
}
38+
}
39+
40+
$seriesUrl = "$baseurl/series/packages-$depsPhpVersion-$VsVersion-$Arch-staging.txt"
41+
Write-Host "Fetching series listing: $seriesUrl"
42+
$series = Invoke-WebRequest -Uri $seriesUrl -UseBasicParsing -ErrorAction Stop
43+
$packages = @()
44+
if ($series -and $series.Content) {
45+
$packages = $series.Content -split "[\r\n]+" | Where-Object { $_ -and $_.Trim().Length -gt 0 }
46+
}
47+
48+
$overrideLibraries = @()
49+
if ((Test-Path -LiteralPath $configPath) -and $PhpVersion -match '^\d+\.\d+\.\d+$') {
50+
$config = Get-Content -LiteralPath $configPath -Raw | ConvertFrom-Json
51+
$seriesConfigProperty = $config.PSObject.Properties[$depsPhpVersion]
52+
if ($null -ne $seriesConfigProperty) {
53+
$seriesConfig = $seriesConfigProperty.Value
54+
if ([version]$PhpVersion -le [version]$seriesConfig.maxVersion) {
55+
foreach ($libraryProperty in $seriesConfig.libraries.PSObject.Properties) {
56+
$libraryName = $libraryProperty.Name
57+
$overrideConfig = $libraryProperty.Value
58+
$package = $null
59+
if ($overrideConfig -is [string]) {
60+
$package = "$libraryName-$overrideConfig-$VsVersion-$Arch.zip"
61+
} elseif ($overrideConfig.PSObject.Properties.Name -contains 'package') {
62+
$package = $overrideConfig.package
63+
} elseif ($overrideConfig.PSObject.Properties.Name -contains 'version') {
64+
$package = "$libraryName-$($overrideConfig.version)-$VsVersion-$Arch.zip"
65+
}
66+
67+
if ([string]::IsNullOrWhiteSpace($package)) {
68+
continue
69+
}
70+
71+
$overrideLibraries += $libraryName
72+
$packagePattern = '^' + [regex]::Escape($libraryName) + '-\d'
73+
$packages = $packages | ForEach-Object {
74+
if ($_ -match $packagePattern) {
75+
$package
76+
} else {
77+
$_
78+
}
79+
}
80+
81+
if (-not ($packages -contains $package)) {
82+
$packages += $package
83+
}
84+
}
85+
}
86+
}
87+
}
88+
89+
return [PSCustomObject]@{
90+
Packages = @($packages)
91+
OverrideLibraries = @($overrideLibraries | Select-Object -Unique)
92+
}
93+
}
94+
}

php/BuildPhp/public/Invoke-PhpBuild.ps1

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ function Invoke-PhpBuild {
6767
Set-Location "$buildPath"
6868
New-Item (Join-Path $buildParent 'obj') -ItemType "directory" -Force > $null 2>&1
6969
Copy-Item -Path $configBatch -Destination (Join-Path $buildPath "config.$Ts.bat") -Force
70-
71-
if(-not [string]::IsNullOrWhiteSpace($env:LIBS_BUILD_RUNS)) {
72-
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsConfig.vs -Arch $Arch -Destination (Join-Path $buildParent 'deps')
73-
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts.bat"
74-
} else {
75-
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts-with-deps.bat"
76-
}
70+
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsConfig.vs -Arch $Arch -Destination (Join-Path $buildParent 'deps')
71+
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts.bat"
7772

7873
$task = [System.IO.Path]::GetFileName($taskTemplate)
7974
Copy-Item -Path $taskTemplate -Destination $task -Force

php/BuildPhp/runner/task-nts-with-deps.bat

Lines changed: 0 additions & 23 deletions
This file was deleted.

php/BuildPhp/runner/task-ts-with-deps.bat

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)