build-scripts/winrtbuild.ps1
author David Ludwig <dludwig@pobox.com>
Mon, 03 Nov 2014 13:07:51 -0500
changeset 9217 e15f7d963d98
parent 9216 build-scripts/winrt-build.ps1@61cf772a4ed3
child 9735 35d8f8976d32
permissions -rw-r--r--
WinRT: removed '-' from build script file names

Most of the other build scripts don't include a '-' in their file names. This
change makes the WinRT build scripts use the same convention.
     1 #
     2 # winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
     3 #    across all WinRT platforms, in all of their supported, CPU architectures.
     4 #
     5 # Initial version written by David Ludwig <dludwig@pobox.com>
     6 #
     7 # This script can be launched from Windows Explorer by double-clicking
     8 # on winrtbuild.bat
     9 #
    10 # Output will be placed in the following subdirectories of the SDL source
    11 # tree:
    12 #   * VisualC-WinRT\lib\  -- final .dll, .lib, and .pdb files
    13 #   * VisualC-WinRT\obj\  -- intermediate build files
    14 #
    15 # Recommended Dependencies:
    16 #   * Windows 8.1 or higher
    17 #   * Powershell 4.0 or higher (included as part of Windows 8.1)
    18 #   * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
    19 #   * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
    20 #   * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
    21 #     Windows Phone 8.1, as needed
    22 #
    23 # Commom parameters/variables may include, but aren't strictly limited to:
    24 #   * PlatformToolset: the name of one of Visual Studio's build platforms.
    25 #     Different PlatformToolsets output different binaries.  One
    26 #     PlatformToolset exists for each WinRT platform.  Possible values
    27 #     may include:
    28 #       - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
    29 #       - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
    30 #       - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
    31 #       - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
    32 #   * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
    33 #   * VSProjectName: the internal name of a Visual Studio or Visual C++ project
    34 #     file.  Some of Visual Studio's own build tools use this name when
    35 #     calculating paths for build-output.
    36 #   * Platform: a Visual Studio platform name, which often maps to a CPU
    37 #     CPU architecture.  Possible values may include: "Win32" (for 32-bit x86),
    38 #     "ARM", or "x64" (for 64-bit x86).
    39 #
    40 
    41 
    42 # Gets the .bat file that sets up an MSBuild environment, given one of
    43 # Visual Studio's, "PlatformToolset"s.
    44 function Get-MSBuild-Env-Launcher
    45 {
    46     param(
    47         [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
    48     )
    49 
    50     if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
    51         return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
    52     }
    53     if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
    54         return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
    55     }
    56     if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
    57         return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    58     }
    59     if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
    60         return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    61     }
    62     return ""
    63 }
    64 
    65 # Gets a string that identifies the build-variant of SDL/WinRT that is specific
    66 # to a particular Visual Studio PlatformToolset.
    67 function Get-SDL-WinRT-Variant-Name
    68 {
    69     param(
    70         [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
    71 
    72         # If true, append a string to this function's output, identifying the
    73         # build-variant's minimum-supported version of Visual Studio.
    74         [switch]$IncludeVSSuffix = $false
    75     )
    76 
    77     if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
    78         if ($IncludeVSSuffix) {
    79             return "WinRT80_VS2012"
    80         } else {
    81             return "WinRT80"
    82         }
    83     }
    84     if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
    85         if ($IncludeVSSuffix) {
    86             return "WinPhone80_VS2012"
    87         } else {
    88             return "WinPhone80"
    89         }
    90     }
    91     if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
    92         if ($IncludeVSSuffix) {
    93             return "WinRT81_VS2013"
    94         } else {
    95             return "WinRT81"
    96         }
    97     }
    98     if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
    99         if ($IncludeVSSuffix) {
   100             return "WinPhone81_VS2013"
   101         } else {
   102             return "WinPhone81"
   103         }
   104     }
   105     return ""
   106 }
   107 
   108 # Returns the internal name of a Visual Studio Project.
   109 #
   110 # The internal name of a VS Project is encoded inside the project file
   111 # itself, inside a set of <ProjectName></ProjectName> XML tags.
   112 function Get-VS-ProjectName
   113 {
   114     param(
   115         [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
   116     )
   117 
   118     # For now, just do a regex for the project name:
   119     $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
   120     foreach ($match in $matches) {
   121         if ($match.Groups.Count -ge 1) {
   122             return $match.Groups[1].Value
   123         }
   124     }
   125     return $null
   126 }
   127 
   128 # Build a specific variant of SDL/WinRT
   129 function Build-SDL-WinRT-Variant
   130 {
   131     #
   132     # Read in arguments:
   133     #
   134     param (
   135         # name of an SDL project file, minus extensions and
   136         # platform-identifying suffixes
   137         [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
   138 
   139         [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
   140 
   141         [Parameter(Mandatory=$true,Position=3)][string]$Platform
   142     )
   143 
   144     #
   145     # Derive other properties from read-in arguments:
   146     #
   147 
   148     # The .bat file to setup a platform-appropriate MSBuild environment:
   149     $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
   150 
   151     # The full path to the VS Project that'll be built:
   152     $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
   153 
   154     # The internal name of the VS Project, used in some post-build steps:
   155     $VSProjectName = Get-VS-ProjectName $VSProjectPath
   156 
   157     # Where to place output binaries (.dll, .lib, and .pdb files):
   158     $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
   159 
   160     # Where to place intermediate build files:
   161     $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
   162 
   163     #
   164     # Build the VS Project:
   165     #
   166     cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
   167     $BuildResult = $?
   168 
   169     #
   170     # Move .dll files into place.  This fixes a problem whereby MSBuild may
   171     # put output files into a sub-directory of $OutDir, rather than $OutDir
   172     # itself.
   173     #
   174     if (Test-Path "$OutDir\$VSProjectName\") {
   175         Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
   176     }
   177 
   178     #
   179     # Clean up unneeded files in $OutDir:
   180     #
   181     if (Test-Path "$OutDir\$VSProjectName\") {
   182         Remove-Item -Recurse "$OutDir\$VSProjectName"
   183     }
   184     Remove-Item "$OutDir\*.exp"
   185     Remove-Item "$OutDir\*.ilk"
   186     Remove-Item "$OutDir\*.pri"
   187 
   188     #
   189     # All done.  Indicate success, or failure, to the caller:
   190     #
   191     #echo "RESULT: $BuildResult" | Out-Host
   192     return $BuildResult
   193 }
   194 
   195 
   196 #
   197 # Build each variant, with corresponding .dll, .lib, and .pdb files:
   198 #
   199 $DidAnyFail = $false
   200 
   201 # Build for Windows Phone 8.0, via VC++ 2012:
   202 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyFail = $true }
   203 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
   204 
   205 # Build for Windows Phone 8.1, via VC++ 2013:
   206 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyFail = $true }
   207 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
   208 
   209 # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
   210 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyFail = $true }
   211 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyFail = $true }
   212 if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyFail = $true }
   213 
   214 # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
   215 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyFail = $true }
   216 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyFail = $true }
   217 if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyFail = $true }
   218 
   219 # Let the script's caller know whether or not any errors occurred.
   220 # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
   221 if ($DidAnyFail -eq $true) {
   222     exit 1
   223 } else {
   224     exit 0
   225 }