build-scripts/winrtbuild.ps1
changeset 9217 e15f7d963d98
parent 9216 61cf772a4ed3
child 9735 35d8f8976d32
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build-scripts/winrtbuild.ps1	Mon Nov 03 13:07:51 2014 -0500
     1.3 @@ -0,0 +1,225 @@
     1.4 +#
     1.5 +# winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
     1.6 +#    across all WinRT platforms, in all of their supported, CPU architectures.
     1.7 +#
     1.8 +# Initial version written by David Ludwig <dludwig@pobox.com>
     1.9 +#
    1.10 +# This script can be launched from Windows Explorer by double-clicking
    1.11 +# on winrtbuild.bat
    1.12 +#
    1.13 +# Output will be placed in the following subdirectories of the SDL source
    1.14 +# tree:
    1.15 +#   * VisualC-WinRT\lib\  -- final .dll, .lib, and .pdb files
    1.16 +#   * VisualC-WinRT\obj\  -- intermediate build files
    1.17 +#
    1.18 +# Recommended Dependencies:
    1.19 +#   * Windows 8.1 or higher
    1.20 +#   * Powershell 4.0 or higher (included as part of Windows 8.1)
    1.21 +#   * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
    1.22 +#   * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
    1.23 +#   * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
    1.24 +#     Windows Phone 8.1, as needed
    1.25 +#
    1.26 +# Commom parameters/variables may include, but aren't strictly limited to:
    1.27 +#   * PlatformToolset: the name of one of Visual Studio's build platforms.
    1.28 +#     Different PlatformToolsets output different binaries.  One
    1.29 +#     PlatformToolset exists for each WinRT platform.  Possible values
    1.30 +#     may include:
    1.31 +#       - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
    1.32 +#       - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
    1.33 +#       - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
    1.34 +#       - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
    1.35 +#   * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
    1.36 +#   * VSProjectName: the internal name of a Visual Studio or Visual C++ project
    1.37 +#     file.  Some of Visual Studio's own build tools use this name when
    1.38 +#     calculating paths for build-output.
    1.39 +#   * Platform: a Visual Studio platform name, which often maps to a CPU
    1.40 +#     CPU architecture.  Possible values may include: "Win32" (for 32-bit x86),
    1.41 +#     "ARM", or "x64" (for 64-bit x86).
    1.42 +#
    1.43 +
    1.44 +
    1.45 +# Gets the .bat file that sets up an MSBuild environment, given one of
    1.46 +# Visual Studio's, "PlatformToolset"s.
    1.47 +function Get-MSBuild-Env-Launcher
    1.48 +{
    1.49 +    param(
    1.50 +        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
    1.51 +    )
    1.52 +
    1.53 +    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
    1.54 +        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
    1.55 +    }
    1.56 +    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
    1.57 +        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
    1.58 +    }
    1.59 +    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
    1.60 +        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    1.61 +    }
    1.62 +    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
    1.63 +        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    1.64 +    }
    1.65 +    return ""
    1.66 +}
    1.67 +
    1.68 +# Gets a string that identifies the build-variant of SDL/WinRT that is specific
    1.69 +# to a particular Visual Studio PlatformToolset.
    1.70 +function Get-SDL-WinRT-Variant-Name
    1.71 +{
    1.72 +    param(
    1.73 +        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
    1.74 +
    1.75 +        # If true, append a string to this function's output, identifying the
    1.76 +        # build-variant's minimum-supported version of Visual Studio.
    1.77 +        [switch]$IncludeVSSuffix = $false
    1.78 +    )
    1.79 +
    1.80 +    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
    1.81 +        if ($IncludeVSSuffix) {
    1.82 +            return "WinRT80_VS2012"
    1.83 +        } else {
    1.84 +            return "WinRT80"
    1.85 +        }
    1.86 +    }
    1.87 +    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
    1.88 +        if ($IncludeVSSuffix) {
    1.89 +            return "WinPhone80_VS2012"
    1.90 +        } else {
    1.91 +            return "WinPhone80"
    1.92 +        }
    1.93 +    }
    1.94 +    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
    1.95 +        if ($IncludeVSSuffix) {
    1.96 +            return "WinRT81_VS2013"
    1.97 +        } else {
    1.98 +            return "WinRT81"
    1.99 +        }
   1.100 +    }
   1.101 +    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
   1.102 +        if ($IncludeVSSuffix) {
   1.103 +            return "WinPhone81_VS2013"
   1.104 +        } else {
   1.105 +            return "WinPhone81"
   1.106 +        }
   1.107 +    }
   1.108 +    return ""
   1.109 +}
   1.110 +
   1.111 +# Returns the internal name of a Visual Studio Project.
   1.112 +#
   1.113 +# The internal name of a VS Project is encoded inside the project file
   1.114 +# itself, inside a set of <ProjectName></ProjectName> XML tags.
   1.115 +function Get-VS-ProjectName
   1.116 +{
   1.117 +    param(
   1.118 +        [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
   1.119 +    )
   1.120 +
   1.121 +    # For now, just do a regex for the project name:
   1.122 +    $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
   1.123 +    foreach ($match in $matches) {
   1.124 +        if ($match.Groups.Count -ge 1) {
   1.125 +            return $match.Groups[1].Value
   1.126 +        }
   1.127 +    }
   1.128 +    return $null
   1.129 +}
   1.130 +
   1.131 +# Build a specific variant of SDL/WinRT
   1.132 +function Build-SDL-WinRT-Variant
   1.133 +{
   1.134 +    #
   1.135 +    # Read in arguments:
   1.136 +    #
   1.137 +    param (
   1.138 +        # name of an SDL project file, minus extensions and
   1.139 +        # platform-identifying suffixes
   1.140 +        [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
   1.141 +
   1.142 +        [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
   1.143 +
   1.144 +        [Parameter(Mandatory=$true,Position=3)][string]$Platform
   1.145 +    )
   1.146 +
   1.147 +    #
   1.148 +    # Derive other properties from read-in arguments:
   1.149 +    #
   1.150 +
   1.151 +    # The .bat file to setup a platform-appropriate MSBuild environment:
   1.152 +    $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
   1.153 +
   1.154 +    # The full path to the VS Project that'll be built:
   1.155 +    $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
   1.156 +
   1.157 +    # The internal name of the VS Project, used in some post-build steps:
   1.158 +    $VSProjectName = Get-VS-ProjectName $VSProjectPath
   1.159 +
   1.160 +    # Where to place output binaries (.dll, .lib, and .pdb files):
   1.161 +    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
   1.162 +
   1.163 +    # Where to place intermediate build files:
   1.164 +    $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
   1.165 +
   1.166 +    #
   1.167 +    # Build the VS Project:
   1.168 +    #
   1.169 +    cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
   1.170 +    $BuildResult = $?
   1.171 +
   1.172 +    #
   1.173 +    # Move .dll files into place.  This fixes a problem whereby MSBuild may
   1.174 +    # put output files into a sub-directory of $OutDir, rather than $OutDir
   1.175 +    # itself.
   1.176 +    #
   1.177 +    if (Test-Path "$OutDir\$VSProjectName\") {
   1.178 +        Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
   1.179 +    }
   1.180 +
   1.181 +    #
   1.182 +    # Clean up unneeded files in $OutDir:
   1.183 +    #
   1.184 +    if (Test-Path "$OutDir\$VSProjectName\") {
   1.185 +        Remove-Item -Recurse "$OutDir\$VSProjectName"
   1.186 +    }
   1.187 +    Remove-Item "$OutDir\*.exp"
   1.188 +    Remove-Item "$OutDir\*.ilk"
   1.189 +    Remove-Item "$OutDir\*.pri"
   1.190 +
   1.191 +    #
   1.192 +    # All done.  Indicate success, or failure, to the caller:
   1.193 +    #
   1.194 +    #echo "RESULT: $BuildResult" | Out-Host
   1.195 +    return $BuildResult
   1.196 +}
   1.197 +
   1.198 +
   1.199 +#
   1.200 +# Build each variant, with corresponding .dll, .lib, and .pdb files:
   1.201 +#
   1.202 +$DidAnyFail = $false
   1.203 +
   1.204 +# Build for Windows Phone 8.0, via VC++ 2012:
   1.205 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyFail = $true }
   1.206 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
   1.207 +
   1.208 +# Build for Windows Phone 8.1, via VC++ 2013:
   1.209 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyFail = $true }
   1.210 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
   1.211 +
   1.212 +# Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
   1.213 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyFail = $true }
   1.214 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyFail = $true }
   1.215 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyFail = $true }
   1.216 +
   1.217 +# Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
   1.218 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyFail = $true }
   1.219 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyFail = $true }
   1.220 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyFail = $true }
   1.221 +
   1.222 +# Let the script's caller know whether or not any errors occurred.
   1.223 +# Exit codes compatible with Buildbot are used (1 for error, 0 for success).
   1.224 +if ($DidAnyFail -eq $true) {
   1.225 +    exit 1
   1.226 +} else {
   1.227 +    exit 0
   1.228 +}