forked from ffmpeginteropx/FFmpegInteropX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-FFmpegInteropX.ps1
More file actions
187 lines (150 loc) · 5.09 KB
/
Build-FFmpegInteropX.ps1
File metadata and controls
187 lines (150 loc) · 5.09 KB
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
param(
[ValidateSet('x86', 'x64', 'ARM', 'ARM64')]
[string[]] $Platforms = ('x86', 'x64', 'ARM', 'ARM64'),
<#
Example values:
14.1
14.2
14.16
14.16.27023
14.23.27820
Note. The PlatformToolset will be inferred from this value ('v141', 'v142'...)
#>
[version] $VcVersion = '14.2',
<#
Example values:
8.1
10.0.15063.0
10.0.17763.0
10.0.18362.0
#>
[version] $WindowsTargetPlatformVersion = '10.0.18362.0',
[ValidateSet('Debug', 'Release')]
[string] $Configuration = 'Release',
[System.IO.DirectoryInfo] $VSInstallerFolder = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
# Set the search criteria for VSWHERE.EXE.
[string[]] $VsWhereCriteria = '-latest',
[switch] $ClearBuildFolders,
# If a version string is specified, a NuGet package will be created.
[string] $NugetPackageVersion = "1.0.0",
# FFmpegInteropX NuGet settings
[string] $FFmpegInteropXUrl = 'https://github.com/ffmpeginteropx/FFmpegInteropX.git',
[string] $FFmpegInteropXBranch = $(git branch --show-current),
[string] $FFmpegInteropXCommit = $(git --git-dir Libs/ffmpeg/.git rev-parse HEAD)
)
function Build-Platform {
param (
[System.IO.DirectoryInfo] $SolutionDir,
[string] $Platform,
[version] $WindowsTargetPlatformVersion,
[version] $VcVersion,
[string] $PlatformToolset,
[string] $VsLatestPath
)
$PSBoundParameters | Out-String
$hostArch = ( 'x86', 'x64' )[ [System.Environment]::Is64BitOperatingSystem ]
$targetArch = $Platform.ToLower()
Write-Host
Write-Host "Building FFmpegInteropX for Windows 10 ${Platform}..."
Write-Host
# Load environment from VCVARS.
Import-Module "$VsLatestPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Enter-VsDevShell `
-VsInstallPath $VsLatestPath `
-StartInPath "$PWD" `
-DevCmdArguments "-arch=$targetArch -host_arch=$hostArch -winsdk=$WindowsTargetPlatformVersion -vcvars_ver=$VcVersion -app_platform=UWP"
if ($ClearBuildFolders) {
# Clean platform-specific build and output dirs.
Remove-Item -Force -Recurse -ErrorAction Ignore $SolutionDir\Intermediate\FFmpegInterop\$Platform\*
Remove-Item -Force -Recurse -ErrorAction Ignore $SolutionDir\Output\FFmpegInterop\$Platform\*
}
MSBuild.exe $SolutionDir\FFmpegInterop\FFmpegInterop.vcxproj `
/restore `
/p:Configuration=$Configuration `
/p:Platform=$Platform `
/p:WindowsTargetPlatformVersion=$WindowsTargetPlatformVersion `
/p:PlatformToolset=$PlatformToolset `
/p:useenv=true
if ($lastexitcode -ne 0) { throw "Failed to build library FFmpegInterop.vcxproj." }
}
Write-Host
Write-Host "Building FFmpegInteropX..."
Write-Host
# Stop on all PowerShell command errors
$ErrorActionPreference = "Stop"
[System.IO.DirectoryInfo] $vsLatestPath = `
& "$VSInstallerFolder\vswhere.exe" `
$VsWhereCriteria `
-property installationPath `
-products * `
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
Write-Host "Visual Studio Installation folder: [$vsLatestPath]"
# 14.16.27023 => v141
$platformToolSet = "v$($VcVersion.Major)$("$($VcVersion.Minor)"[0])"
Write-Host "Platform Toolset: [$platformToolSet]"
# Export full current PATH from environment into MSYS2
$env:MSYS2_PATH_TYPE = 'inherit'
# Save orignal environment variables
$oldEnv = @{};
foreach ($item in Get-ChildItem env:)
{
$oldEnv.Add($item.Name, $item.Value);
}
$start = Get-Date
$success = 1
# Restore nuget packets for solution
nuget.exe restore ${PSScriptRoot}\FFmpegInterop.sln
foreach ($platform in $Platforms) {
try
{
Build-Platform `
-SolutionDir "${PSScriptRoot}\" `
-Platform $platform `
-WindowsTargetPlatformVersion $WindowsTargetPlatformVersion `
-VcVersion $VcVersion `
-PlatformToolset $platformToolSet `
-VsLatestPath $vsLatestPath
}
catch
{
Write-Warning "Error occured: $PSItem"
$success = 0
Break
}
finally
{
# Restore orignal environment variables
foreach ($item in $oldEnv.GetEnumerator())
{
Set-Item -Path env:"$($item.Name)" -Value $item.Value
}
foreach ($item in Get-ChildItem env:)
{
if (!$oldEnv.ContainsKey($item.Name))
{
Remove-Item -Path env:"$($item.Name)"
}
}
}
}
if ($success -and $NugetPackageVersion)
{
nuget pack .\FFmpegInteropX.nuspec `
-Properties "id=FFmpegInteropX;repositoryUrl=$FFmpegInteropXUrl;repositoryBranch=$FFmpegInteropXBranch;repositoryCommit=$FFmpegInteropXCommit" `
-Version $NugetPackageVersion `
-Symbols -SymbolPackageFormat symbols.nupkg `
-OutputDirectory "Output\NuGet"
}
Write-Host
Write-Host 'Time elapsed'
Write-Host ('{0}' -f ((Get-Date) - $start))
Write-Host
if ($success)
{
Write-Host 'Build succeeded!'
}
else
{
Write-Error 'Build failed!'
Exit 1
}