1
+ Function Get-LibrariesFromConfig {
2
+ <#
3
+ . SYNOPSIS
4
+ Get the Libraries from the config.w32 file
5
+ . PARAMETER Extension
6
+ Extension
7
+ . PARAMETER VsVersion
8
+ Visual Studio Version
9
+ . PARAMETER Arch
10
+ Architecture
11
+ . PARAMETER ConfigW32Content
12
+ config.w32 content
13
+ #>
14
+ [OutputType ()]
15
+ param (
16
+ [Parameter (Mandatory = $true , Position = 0 , HelpMessage = ' Extension' )]
17
+ [string ] $Extension ,
18
+ [Parameter (Mandatory = $true , Position = 1 , HelpMessage = ' Visual Studio Version' )]
19
+ [string ] $VsVersion ,
20
+ [Parameter (Mandatory = $true , Position = 2 , HelpMessage = ' Architecture' )]
21
+ [string ] $Arch ,
22
+ [Parameter (Mandatory = $true , Position = 3 , HelpMessage = ' config.w32 content' )]
23
+ [string ] $ConfigW32Content
24
+ )
25
+ begin {
26
+ $jsonPath = [System.IO.Path ]::Combine($PSScriptRoot , ' ..\config\vs.json' )
27
+ }
28
+ process {
29
+ $jsonData = (
30
+ Invoke-WebRequest - Uri " https://downloads.php.net/~windows/pecl/deps/libmapping.json"
31
+ ).Content | ConvertFrom-Json
32
+
33
+ $phpSeries = (Invoke-WebRequest - Uri " https://downloads.php.net/~windows/php-sdk/deps/$VsVersion /$Arch " ).Content.ToLower()
34
+
35
+ Function Find-Library {
36
+ param (
37
+ [Parameter (Mandatory = $true , Position = 0 )]
38
+ [string ]$MatchString ,
39
+ [Parameter (Mandatory = $true , Position = 1 )]
40
+ [string []]$VsVersions
41
+ )
42
+ foreach ($vsVersion in $VsVersions ) {
43
+ foreach ($vsVersionData in $JsonData.PSObject.Properties ) {
44
+ if ($vsVersionData.Name -eq $VsVersion ) {
45
+ foreach ($archData in $vsVersionData.Value.PSObject.Properties ) {
46
+ if ($archData.Name -eq $Arch ) {
47
+ foreach ($libs in $archData.Value.PSObject.Properties ) {
48
+ if ($libs.Value -match ($MatchString.Replace (' *' , ' .*' ))) {
49
+ $libs.Name -Match ' ^(.+?)-\d' | Out-Null
50
+ if (! $phpSeries.contains ($matches [1 ].ToLower())) {
51
+ $libs.Name -Match ' ^(.+?-\d)' | Out-Null
52
+ }
53
+ return $matches [1 ]
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return $null
62
+ }
63
+
64
+ $jsonContent = Get-Content - Path $jsonPath - Raw
65
+ $VsConfig = ConvertFrom-Json - InputObject $jsonContent
66
+ $VsVersions = @ ($VsVersion )
67
+ $VsVersions += $ ($VsConfig.vs | Get-Member - MemberType * Property).Name | Where-Object {
68
+ # vs15 and above builds are compatible.
69
+ ($_ -lt $VsVersion -and $_ -ge " vc15" )
70
+ }
71
+
72
+ $foundItems = @ ()
73
+ $libraryFilesFound = @ ()
74
+ [regex ]::Matches($ConfigW32Content , ' CHECK_LIB\(["'' ]([^"'' ]+)["'' ]|["'' ]([^"'' ]+.lib)["'' ]|(\w+\.lib)' ) | ForEach-Object {
75
+ $_.Groups [1 ].Value.Split(' ;' ) + ($_.Groups [2 ].Value -Split ' [^\w\.]' ) + ($_.Groups [3 ].Value -Split ' [^\w\.]' ) | ForEach-Object {
76
+ $libraryFilesFound += $_
77
+ }
78
+ }
79
+ $libraryFilesFound | Select-Object - Unique | ForEach-Object {
80
+ if ($_ ) {
81
+ switch ($_ ) {
82
+ libeay32.lib { $library = " openssl" }
83
+ ssleay32.lib { $library = " openssl" }
84
+ Default { $library = Find-Library $_ $VsVersions }
85
+ }
86
+ if ($library -and (-not ($foundItems.Contains ($library )))) {
87
+ $foundItems += $library.ToLower ()
88
+ }
89
+ }
90
+ }
91
+
92
+ # Exceptions
93
+ # Remove libsasl if the extension is mongodb
94
+ if ($Extension -eq " mongodb" ) {
95
+ $foundItems = $foundItems | Where-Object {$_ -notmatch " libsasl.*" }
96
+ }
97
+ # Add zlib if the extension is memcached
98
+ if ($Extension -eq " memcached" ) {
99
+ $foundItems += " zlib"
100
+ }
101
+
102
+ $highestVersions = @ {}
103
+
104
+ foreach ($item in $foundItems ) {
105
+ if ($item -match ' ^(.*?)-(\d+)$' ) {
106
+ $libraryName , $version = $matches [1 ], $matches [2 ]
107
+ if (-not $highestVersions.ContainsKey ($libraryName ) -or $highestVersions [$libraryName ] -lt $version ) {
108
+ $highestVersions [$libraryName ] = $version
109
+ }
110
+ } else {
111
+ $highestVersions [$item ] = -1
112
+ }
113
+ }
114
+
115
+ $finalItems = @ ()
116
+ foreach ($library in $highestVersions.Keys ) {
117
+ if ($highestVersions [$library ] -eq -1 ) {
118
+ $finalItems += $library
119
+ } else {
120
+ $finalItems += " $library -" + $highestVersions [$library ]
121
+ }
122
+ }
123
+
124
+ return $finalItems
125
+ }
126
+ end {
127
+ }
128
+ }
0 commit comments