-
Notifications
You must be signed in to change notification settings - Fork 51
/
build.ps1
198 lines (172 loc) · 5.39 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Script that builds libfsntfs
#
# Version: 20230411
Param (
[string]$Configuration = ${Env:Configuration},
[string]$Platform = ${Env:Platform},
[string]$PlatformToolset = "",
[string]$PythonPath = "C:\Python311",
[string]$VisualStudioVersion = "",
[string]$VSToolsOptions = "--extend-with-x64",
[string]$VSToolsPath = "..\vstools"
)
$ExitSuccess = 0
$ExitFailure = 1
$Python = "${PythonPath}\python.exe"
$Git = "git"
$GitUrl = "https://github.com/libyal/vstools.git"
$MSVSCppConvert = "${VSToolsPath}\scripts\msvscpp-convert.py"
If (-Not (Test-Path $Python))
{
Write-Host "Missing Python: ${Python}" -foreground Red
Exit ${ExitFailure}
}
If (-Not (Test-Path ${VSToolsPath}))
{
# PowerShell will raise NativeCommandError if git writes to stdout or stderr
# therefore 2>&1 is added and the output is stored in a variable.
$Output = Invoke-Expression -Command "${Git} clone ${GitUrl} ${VSToolsPath} 2>&1" | %{ "$_" }
}
Else
{
Push-Location "${VSToolsPath}"
Try
{
# Make sure vstools are up to date.
$Output = Invoke-Expression -Command "${Git} pull 2>&1" | %{ "$_" }
}
Finally
{
Pop-Location
}
}
If (-Not (Test-Path ${MSVSCppConvert}))
{
Write-Host "Missing msvscpp-convert.py: ${MSVSCppConvert}" -foreground Red
Exit ${ExitFailure}
}
If (-Not ${VisualStudioVersion})
{
$VisualStudioVersion = "2022"
Write-Host "Visual Studio version not set defauting to: ${VisualStudioVersion}" -foreground Red
}
If ((${VisualStudioVersion} -ne "2008") -And (${VisualStudioVersion} -ne "2010") -And (${VisualStudioVersion} -ne "2012") -And (${VisualStudioVersion} -ne "2013") -And (${VisualStudioVersion} -ne "2015") -And (${VisualStudioVersion} -ne "2017") -And (${VisualStudioVersion} -ne "2019") -And (${VisualStudioVersion} -ne "2022"))
{
Write-Host "Unsupported Visual Studio version: ${VisualStudioVersion}" -foreground Red
Exit ${ExitFailure}
}
$MSBuild = ""
If (${VisualStudioVersion} -eq "2008")
{
$MSBuild = "C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
}
ElseIf ((${VisualStudioVersion} -eq "2010") -Or (${VisualStudioVersion} -eq "2012"))
{
$MSBuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
}
ElseIf (${VisualStudioVersion} -eq "2013")
{
$MSBuild = "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
}
ElseIf (${VisualStudioVersion} -eq "2015")
{
$MSBuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
}
ElseIf (${VisualStudioVersion} -eq "2017")
{
$Results = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\${VisualStudioVersion}\*\MSBuild\15.0\Bin\MSBuild.exe" -Recurse -ErrorAction SilentlyContinue -Force
If ($Results.Count -eq 0)
{
$Results = Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio\${VisualStudioVersion}\*\MSBuild\15.0\Bin\MSBuild.exe" -Recurse -ErrorAction SilentlyContinue -Force
}
If ($Results.Count -gt 0)
{
$MSBuild = $Results[0].FullName
}
}
ElseIf (${VisualStudioVersion} -eq "2019" -Or ${VisualStudioVersion} -eq "2022")
{
$Results = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\${VisualStudioVersion}\*\MSBuild\Current\Bin\MSBuild.exe" -Recurse -ErrorAction SilentlyContinue -Force
If ($Results.Count -eq 0)
{
$Results = Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio\${VisualStudioVersion}\*\MSBuild\Current\Bin\MSBuild.exe" -Recurse -ErrorAction SilentlyContinue -Force
}
If ($Results.Count -gt 0)
{
$MSBuild = $Results[0].FullName
}
}
If (-Not ${MSBuild})
{
Write-Host "Unable to determine path to msbuild.exe" -foreground Red
Exit ${ExitFailure}
}
ElseIf (-Not (Test-Path ${MSBuild}))
{
Write-Host "Missing msbuild.exe: ${MSBuild}" -foreground Red
Exit ${ExitFailure}
}
If (${VisualStudioVersion} -eq "2008")
{
$VSSolutionPath = "msvscpp"
}
Else
{
$VSSolutionPath = "vs${VisualStudioVersion}"
If (-Not (Test-Path "${VSSolutionPath}"))
{
${Env:PYTHONPATH} = ${VSToolsPath}
Invoke-Expression -Command "& '${Python}' ${MSVSCppConvert} --output-format ${VisualStudioVersion} ${VSToolsOptions} msvscpp\libfsntfs.sln 2>&1" | %{ "$_" }
}
}
$VSSolutionFile = "${VSSolutionPath}\libfsntfs.sln"
If (-Not (Test-Path "${VSSolutionFile}"))
{
Write-Host "Missing Visual Studio ${VisualStudioVersion} solution file: ${VSSolutionFile}" -foreground Red
Exit ${ExitFailure}
}
If (-Not ${Configuration})
{
$Configuration = "Release"
Write-Host "Configuration not set defauting to: ${Configuration}"
}
If (-Not ${Platform})
{
$Platform = "Win32"
Write-Host "Platform not set defauting to: ${Platform}"
}
$PlatformToolset = ""
If (-Not ${PlatformToolset})
{
If (${VisualStudioVersion} -eq "2015")
{
$PlatformToolset = "v140"
}
ElseIf (${VisualStudioVersion} -eq "2017")
{
$PlatformToolset = "v141"
}
ElseIf (${VisualStudioVersion} -eq "2019")
{
$PlatformToolset = "v142"
}
ElseIf (${VisualStudioVersion} -eq "2022")
{
$PlatformToolset = "v143"
}
Write-Host "PlatformToolset not set defauting to: ${PlatformToolset}"
}
$MSBuildOptions = "/verbosity:quiet /target:Build /property:Configuration=${Configuration},Platform=${Platform}"
If (${PlatformToolset})
{
$MSBuildOptions = "${MSBuildOptions} /property:PlatformToolset=${PlatformToolset}"
}
If (${Env:APPVEYOR} -eq "True")
{
Invoke-Expression -Command "& '${MSBuild}' ${MSBuildOptions} ${VSSolutionFile} /logger:'C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll' 2>&1" | %{ "$_" }
}
Else
{
Invoke-Expression -Command "& '${MSBuild}' ${MSBuildOptions} ${VSSolutionFile} 2>&1" | %{ "$_" }
}
Exit ${ExitSuccess}