WinRT: added NuGet-package creation support to WinRT build script
authorDavid Ludwig <dludwig@pobox.com>
Tue, 01 Dec 2015 22:07:24 -0500
changeset 9940f2d5ed0d9686
parent 9939 6ccf11a01cb5
child 9941 d0c6d95483d9
WinRT: added NuGet-package creation support to WinRT build script
VisualC-WinRT/SDL2-WinRT.nuspec
VisualC-WinRT/SDL2-WinRT.targets
VisualC-WinRT/SDL2main-WinRT-CoreWindow.nuspec
VisualC-WinRT/SDL2main-WinRT-CoreWindow.targets
build-scripts/winrtbuild.ps1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/VisualC-WinRT/SDL2-WinRT.nuspec	Tue Dec 01 22:07:24 2015 -0500
     1.3 @@ -0,0 +1,23 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<package >
     1.6 +  <metadata>
     1.7 +    <id>SDL2-WinRT</id>
     1.8 +    <version>2.0.4-Unofficial</version>
     1.9 +    <authors>Sam Lantinga</authors>
    1.10 +    <owners>David Ludwig</owners>
    1.11 +    <licenseUrl>http://libsdl.org/license.php</licenseUrl>
    1.12 +    <projectUrl>http://libsdl.org</projectUrl>
    1.13 +    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    1.14 +    <description>Unofficial pre-release of LibSDL2, built for WinRT platforms</description>
    1.15 +    <copyright>Copyright 2015</copyright>
    1.16 +    <tags>SDL2 SDL LibSDL OpenGL C C++ nativepackage</tags>
    1.17 +  </metadata>
    1.18 +  <files>
    1.19 +    <file src="lib\**\*.dll" target="bin"/>
    1.20 +    <file src="lib\**\*.lib" target="bin"/>
    1.21 +    <file src="lib\**\*.pdb" target="bin"/>
    1.22 +    <file src="..\include\**\*.*" target="include"/>
    1.23 +    <file src="..\src\**\*.*" target="src"/>
    1.24 +    <file src="SDL2-WinRT.targets" target="build\native"/>
    1.25 +  </files>
    1.26 +</package>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/VisualC-WinRT/SDL2-WinRT.targets	Tue Dec 01 22:07:24 2015 -0500
     2.3 @@ -0,0 +1,39 @@
     2.4 +<?xml version="1.0" encoding="utf-8"?>
     2.5 +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2.6 +
     2.7 +  <PropertyGroup>
     2.8 +    <LibSDL2-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'Windows' and '$(TargetPlatformVersion)' == '8.0'">WinRT80</LibSDL2-DeviceType>
     2.9 +    <LibSDL2-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'Windows' and '$(TargetPlatformVersion)' == '8.1'">WinRT81</LibSDL2-DeviceType>
    2.10 +    <LibSDL2-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'Windows Phone' and '$(TargetPlatformVersion)' == '8.0'">WinPhone80</LibSDL2-DeviceType>
    2.11 +    <LibSDL2-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'WindowsPhoneApp' and '$(TargetPlatformVersion)' == '8.1'">WinPhone81</LibSDL2-DeviceType>
    2.12 +    <LibSDL2-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'UAP'">UWP</LibSDL2-DeviceType>
    2.13 +
    2.14 +  	<LibSDL2-BinPath>$(MSBuildThisFileDirectory)..\..\bin\$(LibSDL2-DeviceType)\$(Platform)</LibSDL2-BinPath>
    2.15 +  </PropertyGroup>
    2.16 +
    2.17 +  <Target Name="LibSDL2-DeviceType-Check" BeforeTargets="ResolveAssemblyReferences">
    2.18 +      <Error Condition="'$(LibSDL2-DeviceType)' == ''" Text="Unable to determine which version of Windows is being built-for" />
    2.19 +  </Target>
    2.20 +
    2.21 +  <ItemDefinitionGroup>
    2.22 +    <Link>
    2.23 +      <AdditionalLibraryDirectories>$(LibSDL2-BinPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    2.24 +      <AdditionalDependencies>SDL2.lib;%(AdditionalDependencies)</AdditionalDependencies>
    2.25 +    </Link>
    2.26 +  </ItemDefinitionGroup>
    2.27 +
    2.28 +  <ItemDefinitionGroup>
    2.29 +    <ClCompile>
    2.30 +      <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    2.31 +    </ClCompile>
    2.32 +  </ItemDefinitionGroup>
    2.33 +
    2.34 +  <ItemGroup Label="LibSDL2">
    2.35 +    <PackagingOutputs Include="$(LibSDL2-BinPath)\SDL2.dll">
    2.36 +        <OutputGroup>LibSDL2Binaries</OutputGroup>
    2.37 +        <ProjectName>$(ProjectName)</ProjectName>
    2.38 +        <TargetPath>%(Filename)%(Extension)</TargetPath>
    2.39 +    </PackagingOutputs>
    2.40 +  </ItemGroup>
    2.41 +
    2.42 +</Project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/VisualC-WinRT/SDL2main-WinRT-CoreWindow.nuspec	Tue Dec 01 22:07:24 2015 -0500
     3.3 @@ -0,0 +1,22 @@
     3.4 +<?xml version="1.0"?>
     3.5 +<package >
     3.6 +  <metadata>
     3.7 +    <id>SDL2main-WinRT-CoreWindow</id>
     3.8 +    <version>2.0.4-Unofficial</version>
     3.9 +    <authors>Sam Lantinga</authors>
    3.10 +    <owners>David Ludwig</owners>
    3.11 +    <licenseUrl>http://libsdl.org/license.php</licenseUrl>
    3.12 +    <projectUrl>http://libsdl.org</projectUrl>
    3.13 +    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    3.14 +    <description>WinMain() function for SDL2 + WinRT + CoreWindow (non-XAML) apps</description>
    3.15 +    <copyright>Copyright 2015</copyright>
    3.16 +    <tags>SDL2 SDL LibSDL OpenGL C C++ nativepackage</tags>
    3.17 +    <dependencies>
    3.18 +      <dependency id="SDL2-WinRT" version="2.0.4"/>
    3.19 +    </dependencies>
    3.20 +  </metadata>
    3.21 +  <files>
    3.22 +    <file src="..\src\main\winrt\SDL_winrt_main_NonXAML.cpp" target="src\main\winrt"/>
    3.23 +    <file src="SDL2main-WinRT-CoreWindow.targets" target="build\native"/>
    3.24 +  </files>
    3.25 +</package>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/VisualC-WinRT/SDL2main-WinRT-CoreWindow.targets	Tue Dec 01 22:07:24 2015 -0500
     4.3 @@ -0,0 +1,10 @@
     4.4 +<?xml version="1.0" encoding="utf-8"?>
     4.5 +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     4.6 +
     4.7 +  <ItemGroup Label="LibSDL2">
     4.8 +    <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\main\winrt\SDL_winrt_main_NonXAML.cpp">
     4.9 +      <CompileAsWinRT>true</CompileAsWinRT>
    4.10 +    </ClCompile>
    4.11 +  </ItemGroup>
    4.12 +
    4.13 +</Project>
     5.1 --- a/build-scripts/winrtbuild.ps1	Tue Dec 01 22:24:04 2015 +0100
     5.2 +++ b/build-scripts/winrtbuild.ps1	Tue Dec 01 22:07:24 2015 -0500
     5.3 @@ -38,6 +38,8 @@
     5.4  #     "ARM", or "x64" (for 64-bit x86).
     5.5  #
     5.6  
     5.7 +# Base version of SDL, used for packaging purposes
     5.8 +$SDLVersion = "2.0.4"
     5.9  
    5.10  # Gets the .bat file that sets up an MSBuild environment, given one of
    5.11  # Visual Studio's, "PlatformToolset"s.
    5.12 @@ -165,7 +167,7 @@
    5.13      $VSProjectName = Get-VS-ProjectName $VSProjectPath
    5.14  
    5.15      # Where to place output binaries (.dll, .lib, and .pdb files):
    5.16 -    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
    5.17 +    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
    5.18  
    5.19      # Where to place intermediate build files:
    5.20      $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
    5.21 @@ -206,35 +208,87 @@
    5.22  #
    5.23  # Build each variant, with corresponding .dll, .lib, and .pdb files:
    5.24  #
    5.25 -$DidAnyFail = $false
    5.26 +$DidAnyDLLBuildFail = $false
    5.27 +$DidAnyNugetBuildFail = $false
    5.28  
    5.29  # Build for Windows Phone 8.0, via VC++ 2012:
    5.30 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyFail = $true }
    5.31 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
    5.32 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyDLLBuildFail = $true }
    5.33 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyDLLBuildFail = $true }
    5.34  
    5.35  # Build for Windows Phone 8.1, via VC++ 2013:
    5.36 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyFail = $true }
    5.37 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
    5.38 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyDLLBuildFail = $true }
    5.39 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyDLLBuildFail = $true }
    5.40  
    5.41  # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
    5.42 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyFail = $true }
    5.43 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyFail = $true }
    5.44 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyFail = $true }
    5.45 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyDLLBuildFail = $true }
    5.46 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyDLLBuildFail = $true }
    5.47 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyDLLBuildFail = $true }
    5.48  
    5.49  # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
    5.50 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyFail = $true }
    5.51 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyFail = $true }
    5.52 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyFail = $true }
    5.53 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyDLLBuildFail = $true }
    5.54 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyDLLBuildFail = $true }
    5.55 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyDLLBuildFail = $true }
    5.56  
    5.57  # Build for Windows 10, via VC++ 2015
    5.58 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM"))        { $DidAnyFail = $true }
    5.59 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32"))      { $DidAnyFail = $true }
    5.60 -if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64"))        { $DidAnyFail = $true }
    5.61 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM"))        { $DidAnyDLLBuildFail = $true }
    5.62 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32"))      { $DidAnyDLLBuildFail = $true }
    5.63 +if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64"))        { $DidAnyDLLBuildFail = $true }
    5.64 +
    5.65 +# Build NuGet packages, if possible
    5.66 +if ($DidAnyDLLBuildFail -eq $true) {
    5.67 +    Write-Warning -Message "Unable to build all variants.  NuGet packages will not be built."
    5.68 +    $DidAnyNugetBuildFail = $true
    5.69 +} else {
    5.70 +    $NugetPath = (Get-Command -CommandType Application nuget.exe | %{$_.Path}) 2> $null
    5.71 +    if ("$NugetPath" -eq "") {
    5.72 +        Write-Warning -Message "Unable to find nuget.exe.  NuGet packages will not be built."
    5.73 +        $DidAnyNugetBuildFail = $true
    5.74 +    } else {
    5.75 +        Write-Host -ForegroundColor Cyan "Building SDL2 NuGet packages..."
    5.76 +        Write-Host -ForegroundColor Cyan "... via NuGet install: $NugetPath"
    5.77 +        $NugetOutputDir = "$PSScriptRoot\..\VisualC-WinRT\lib\nuget"
    5.78 +        Write-Host -ForegroundColor Cyan "...  output directory: $NugetOutputDir"
    5.79 +        $SDLHGRevision = $($(hg log -l 1 | select-string "changeset") -Replace "changeset:\W*(\d+).*",'$1') 2>$null
    5.80 +        Write-Host -ForegroundColor Cyan "...       HG Revision: $SDLHGRevision"
    5.81 +
    5.82 +        # Base options to nuget.exe
    5.83 +        $NugetOptions = @("pack", "PACKAGE_NAME_WILL_GO_HERE", "-Output", "$NugetOutputDir")
    5.84 +
    5.85 +        # Try attaching hg revision to NuGet package:
    5.86 +        $NugetOptions += "-Version"
    5.87 +        if ("$SDLHGRevision" -eq "") {
    5.88 +            Write-Warning -Message "Unable to find the Mercurial revision (maybe hg.exe can't be found?).  NuGet packages will not have this attached to their name."
    5.89 +            $NugetOptions += "$SDLVersion-Unofficial"
    5.90 +        } else {
    5.91 +            $NugetOptions += "$SDLVersion.$SDLHGRevision-Unofficial"
    5.92 +        }
    5.93 +
    5.94 +        # Create NuGet output dir, if not yet created:
    5.95 +        if ($(Test-Path "$NugetOutputDir") -eq $false) {
    5.96 +            New-Item "$NugetOutputDir" -type directory
    5.97 +        }
    5.98 +
    5.99 +        # Package SDL2:
   5.100 +        $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2-WinRT.nuspec"
   5.101 +        &"$NugetPath" $NugetOptions -Symbols
   5.102 +        if ( ! $? ) { $DidAnyNugetBuildFail = $true }
   5.103 +
   5.104 +        # Package SDL2main:
   5.105 +        $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2main-WinRT-CoreWindow.nuspec"
   5.106 +        &"$NugetPath" $NugetOptions
   5.107 +        if ( ! $? ) { $DidAnyNugetBuildFail = $true }
   5.108 +    }
   5.109 +}
   5.110 +
   5.111  
   5.112  # Let the script's caller know whether or not any errors occurred.
   5.113  # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
   5.114 -if ($DidAnyFail -eq $true) {
   5.115 +if ($DidAnyDLLBuildFail -eq $true) {
   5.116 +    Write-Error -Message "Unable to build all known variants of SDL2 for WinRT"
   5.117      exit 1
   5.118 +} elseif ($DidAnyNugetBuildFail -eq $true) {
   5.119 +    Write-Warning -Message "Unable to build NuGet packages"
   5.120 +    exit 0  # Should NuGet package build failure lead to a non-failing result code instead?
   5.121  } else {
   5.122      exit 0
   5.123  }