| 1 |
param ( |
| 2 |
[Parameter(Mandatory, ValueFromPipeline)] |
| 3 |
[string]$Platform, |
| 4 |
|
| 5 |
[Parameter(Mandatory=$false)] |
| 6 |
[string]$OutputFolder, |
| 7 |
|
| 8 |
[Parameter(Mandatory=$false)] |
| 9 |
[switch]$SkipBuild, |
| 10 |
|
| 11 |
[Parameter(Mandatory=$false)] |
| 12 |
[switch]$GenerateSetupPackage = $true, |
| 13 |
|
| 14 |
[Parameter(Mandatory=$false)] |
| 15 |
[switch]$GeneratePortablePackage = $true |
| 16 |
) |
| 17 |
|
| 18 |
if ($SkipBuild) |
| 19 |
{ |
| 20 |
Write-Host "SkipBuild specified: Will skip the build process." |
| 21 |
} |
| 22 |
|
| 23 |
if ($null -eq $GenerateSetupPackage) |
| 24 |
{ |
| 25 |
$GenerateSetupPackage = $true |
| 26 |
} |
| 27 |
|
| 28 |
if ($null -eq $GeneratePortablePackage) |
| 29 |
{ |
| 30 |
$GeneratePortablePackage = $true |
| 31 |
} |
| 32 |
|
| 33 |
Write-Host ("Generate InnoSetup Package: {0}" -f $(if ($GenerateSetupPackage -eq $true) { "yes" } else { "no" })) |
| 34 |
Write-Host ("Generate Portable Package: {0}" -f $(if ($GeneratePortablePackage -eq $true) { "yes" } else { "no" })) |
| 35 |
|
| 36 |
$dummy = [Reflection.Assembly]::LoadWithPartialName("System.IO"); |
| 37 |
|
| 38 |
if ([string]::IsNullOrEmpty($OutputFolder) -eq $false) |
| 39 |
{ |
| 40 |
if (-not [System.IO.Directory]::Exists($OutputFolder)) |
| 41 |
{ |
| 42 |
Write-Host "The given output path $OutputFolder doesn't exist, creating..." |
| 43 |
$dummy = New-Item -Path $OutputFolder -ItemType Directory -ErrorAction Stop |
| 44 |
} |
| 45 |
|
| 46 |
Write-Host ("Will copy the resulting packages to the folder {0}" -f $OutputFolder) |
| 47 |
} |
| 48 |
|
| 49 |
# Check tool reachability |
| 50 |
if ($GenerateSetupPackage -and $null -eq (Get-Command "compil32" -ErrorAction SilentlyContinue)) |
| 51 |
{ |
| 52 |
Write-Host -ForegroundColor Red "For this script to run, please make sure that InnoSetup's compil32 is found via the PATH environment variable" |
| 53 |
return |
| 54 |
} |
| 55 |
|
| 56 |
if (-not $SkipBuild -and ($null -eq (Get-Command "msbuild" -ErrorAction SilentlyContinue))) |
| 57 |
{ |
| 58 |
Write-Host -ForegroundColor Red "For this script to run, please make sure that you've opened the corresponding studio developer command prompt." |
| 59 |
return |
| 60 |
} |
| 61 |
|
| 62 |
# ---------------------------------------------- |
| 63 |
|
| 64 |
$target = $Platform |
| 65 |
|
| 66 |
Write-Host ("Compiling for target: {0}" -f $target) |
| 67 |
|
| 68 |
$portableFilenameTemplate = "darkradiant-{0}-$target.portable.7z" |
| 69 |
$pdbFilenameTemplate = "darkradiant-{0}-$target.pdb.7z" |
| 70 |
$innoSetupFilenameTemplate = "darkradiant-{0}-$target.exe" |
| 71 |
|
| 72 |
$versionRegex = '#define RADIANT_VERSION "(.+)"' |
| 73 |
$versionIncludeFile = "..\..\include\version.h" |
| 74 |
|
| 75 |
# Extract the version string from the version.h file |
| 76 |
$content = Get-Content $versionIncludeFile |
| 77 |
$defaultVersionString = "X.Y.ZpreV" |
| 78 |
$foundVersionString = $defaultVersionString |
| 79 |
|
| 80 |
foreach ($line in $content) |
| 81 |
{ |
| 82 |
if ($line -match $versionRegex) |
| 83 |
{ |
| 84 |
$foundVersionString = $matches[1] |
| 85 |
Write-Host ("Version is {0}" -f $matches[1]) |
| 86 |
break |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
# Check the location of the VC redist folder |
| 91 |
$vcRedistFolder = $env:VCToolsRedistDir |
| 92 |
|
| 93 |
if ($null -eq $vcRedistFolder) |
| 94 |
{ |
| 95 |
Write-Host "Trying to guess the VCRedistTools folder location..." |
| 96 |
|
| 97 |
$candidate = Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\" -Recurse -Filter "Redist" | ? { (Get-ChildItem -Path $_.FullName -Filter "MSVC") } |
| 98 |
|
| 99 |
if ($null -ne $candidate) |
| 100 |
{ |
| 101 |
$candidate = Join-Path $candidate.FullName "MSVC" |
| 102 |
|
| 103 |
$candidate = Get-ChildItem -Recurse -Path $candidate -Filter $target -Depth 1 | ? { (Get-ChildItem -Path $_.FullName -Filter "Microsoft.VC143.CRT") } | Select -First 1 |
| 104 |
|
| 105 |
$vcRedistFolder = $candidate.Parent.FullName |
| 106 |
Write-Host "Guessed this path: $vcRedistFolder" |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
if ($target -eq "x86") |
| 111 |
{ |
| 112 |
$platform = "Win32" |
| 113 |
$issFile = "..\innosetup\darkradiant.iss" |
| 114 |
$portablePath = "DarkRadiant_install" |
| 115 |
$redistSource = Join-Path $vcRedistFolder "x86\Microsoft.VC143.CRT" |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
$platform = "x64" |
| 120 |
$issFile = "..\innosetup\darkradiant.x64.iss" |
| 121 |
$portablePath = "DarkRadiant_install.x64" |
| 122 |
$redistSource = Join-Path $vcRedistFolder "x64\Microsoft.VC143.CRT" |
| 123 |
} |
| 124 |
|
| 125 |
if (-not $SkipBuild) |
| 126 |
{ |
| 127 |
Start-Process "msbuild" -ArgumentList ("..\..\DarkRadiant.sln", "/p:configuration=release", "/t:rebuild", "/p:platform=$platform", "/maxcpucount:4", "/nodeReuse:false", "/p:UseSharedConfiguration=false") -NoNewWindow -Wait |
| 128 |
} |
| 129 |
|
| 130 |
# Copy files to portable files folder |
| 131 |
|
| 132 |
$pathToCheck = ".\$portablePath" |
| 133 |
$portableFilesFolder = Get-Item -Path $pathToCheck -ErrorAction SilentlyContinue |
| 134 |
|
| 135 |
if ($null -eq $portableFilesFolder) |
| 136 |
{ |
| 137 |
$portableFilesFolder = New-Item -Path $pathToCheck -ItemType Directory -ErrorAction Stop |
| 138 |
} |
| 139 |
|
| 140 |
Write-Host ("Clearing output folder {0}" -f $portableFilesFolder) |
| 141 |
Get-ChildItem -Path $portableFilesFolder | Remove-Item -Recurse -Force |
| 142 |
|
| 143 |
Write-Host ("Copying files...") |
| 144 |
|
| 145 |
$installFolder = Get-Item "..\..\install" |
| 146 |
$excludes = @('*.exp', '*.lib', '*.iobj', '*.ipdb', '*.suo', '*.pgd', '*.fbp', 'darkradiant.desktop.in', 'Tests.*') |
| 147 |
|
| 148 |
Get-ChildItem $installFolder -Recurse -Exclude $excludes | Copy-Item -Destination { Join-Path $portableFilesFolder $_.FullName.Substring($installFolder.FullName.Length) } |
| 149 |
|
| 150 |
# Copy the VC++ redist files |
| 151 |
$vcFolder = Get-Item $redistSource -Erroraction SilentlyContinue |
| 152 |
|
| 153 |
if ($null -ne $vcFolder) |
| 154 |
{ |
| 155 |
Get-ChildItem "msvcp140.dll" -Path $vcFolder | Copy-Item -Destination $portableFilesFolder |
| 156 |
Get-ChildItem "vcruntime140.dll" -Path $vcFolder | Copy-Item -Destination $portableFilesFolder |
| 157 |
Get-ChildItem "vcruntime140_1.dll" -Path $vcFolder | Copy-Item -Destination $portableFilesFolder |
| 158 |
} |
| 159 |
else |
| 160 |
{ |
| 161 |
Write-Host -ForegroundColor Yellow "Warning: cannot find the VC++ redist folder, won't copy runtime DLLs." |
| 162 |
} |
| 163 |
|
| 164 |
$portableFilename = Join-Path "..\innosetup\" ($portableFilenameTemplate -f $foundVersionString) |
| 165 |
$pdbFilename = Join-Path "..\innosetup\" ($pdbFilenameTemplate -f $foundVersionString) |
| 166 |
$innoSetupFilename = Join-Path "..\innosetup\" ($innoSetupFilenameTemplate -f $foundVersionString) |
| 167 |
|
| 168 |
if ($GenerateSetupPackage) |
| 169 |
{ |
| 170 |
# Write the version to the innosetup source file |
| 171 |
Write-Host ("Writing version {0} to InnoSetup file" -f $foundVersionString) |
| 172 |
$issContent = Get-Content $issFile |
| 173 |
$issContent = $issContent -replace '#define DarkRadiantVersion "(.+)"', ('#define DarkRadiantVersion "{0}"' -f $foundVersionString) |
| 174 |
Write-Host ("Writing redist folder {0} to InnoSetup file" -f $vcRedistFolder) |
| 175 |
$issContent = $issContent -replace '#define VCRedistDir "(.+)"', ('#define VCRedistDir "{0}"' -f $vcRedistFolder) |
| 176 |
Set-Content -Path $issFile -Value $issContent |
| 177 |
|
| 178 |
# Compile the installer package |
| 179 |
Start-Process "compil32" -ArgumentList ("/cc", $issFile) |
| 180 |
} |
| 181 |
|
| 182 |
if ($GeneratePortablePackage) |
| 183 |
{ |
| 184 |
$pathTo7z = "..\7z\7za.exe" |
| 185 |
|
| 186 |
# Compress to portable 7z package |
| 187 |
if ($null -ne (Get-ChildItem -Path $portableFilename -ErrorAction SilentlyContinue)) |
| 188 |
{ |
| 189 |
Remove-Item -Path $portableFilename |
| 190 |
} |
| 191 |
|
| 192 |
Start-Process -FilePath $pathTo7z -ArgumentList ("a", "-r", "-x!*.pdb", "-mx9", "-mmt2", $portableFilename, "$portableFilesFolder\*.*") |
| 193 |
|
| 194 |
# Compress Program Database Files |
| 195 |
if ($null -ne (Get-ChildItem -Path $pdbFilename -ErrorAction SilentlyContinue)) |
| 196 |
{ |
| 197 |
Remove-Item -Path $pdbFilename |
| 198 |
} |
| 199 |
|
| 200 |
Start-Process -FilePath $pathTo7z -ArgumentList ("a", "-r", "-mx9", "-mmt2", $pdbFilename, "$portableFilesFolder\*.pdb") -Wait |
| 201 |
} |
| 202 |
|
| 203 |
# Copy to target folder when everything is done |
| 204 |
if ([string]::IsNullOrEmpty($OutputFolder) -eq $false) |
| 205 |
{ |
| 206 |
Write-Host "Copying files to output folder $OutputFolder..." |
| 207 |
|
| 208 |
if ($GenerateSetupPackage) |
| 209 |
{ |
| 210 |
Copy-Item -Path $innoSetupFilename -Destination (Join-Path $OutputFolder ([System.IO.Path]::GetFileName($innoSetupFilename))) -Force |
| 211 |
} |
| 212 |
|
| 213 |
if ($GeneratePortablePackage) |
| 214 |
{ |
| 215 |
Copy-Item -Path $portableFilename -Destination (Join-Path $OutputFolder ([System.IO.Path]::GetFileName($portableFilename))) -Force |
| 216 |
Copy-Item -Path $pdbFilename -Destination (Join-Path $OutputFolder ([System.IO.Path]::GetFileName($pdbFilename))) -Force |
| 217 |
} |
| 218 |
} |