Migrate update libs to msbuild project

This commit is contained in:
Ted John 2016-08-26 00:45:57 +01:00
parent f416da96f4
commit ce7afb92fd
4 changed files with 57 additions and 150 deletions

View File

@ -18,6 +18,7 @@
<PropertyGroup>
<Version>0.0.5</Version>
<TargetLibsVersion>9</TargetLibsVersion>
<BUILD_SERVER Condition="'$(BUILD_SERVER)'==''">$(COMPUTERNAME)</BUILD_SERVER>
<GIT_COMMIT_SHA1_SHORT Condition="'$(GIT_COMMIT_SHA1)'!=''">$(GIT_COMMIT_SHA1.Substring(0, 7))</GIT_COMMIT_SHA1_SHORT>
@ -52,6 +53,13 @@
<UploadFilename>OpenRCT2-$(Version)$(VersionExtension)-windows</UploadFilename>
</PropertyGroup>
<!-- 3rd party libraries / dependencies -->
<PropertyGroup>
<LibsUrl>https://github.com/OpenRCT2/Dependencies/releases/download/v$(TargetLibsVersion)/openrct2-libs-vs2015.zip</LibsUrl>
<LibsPath>$(RootDir)lib\</LibsPath>
<LibsVersionPath>$(LibsPath)libversion</LibsVersionPath>
</PropertyGroup>
<ItemGroup>
<g2Inputs Include="$(RootDir)resources\g2\*" />
<SignItems Include="$(OutputExe)" />
@ -91,9 +99,36 @@
</UploadArtifacts>
</ItemGroup>
<Target Name="CheckLibs">
<!-- Get libversion file and check version -->
<Message Text="Checking if libraries need updating..." Importance="high" />
<PropertyGroup>
<CurrentLibsVersion>0</CurrentLibsVersion>
<CurrentLibsVersion Condition="Exists($(LibsVersionPath))">$([System.IO.File]::ReadAllText($(LibsVersionPath)).Trim())</CurrentLibsVersion>
<UpdateLibs Condition="$(TargetLibsVersion) &gt; $(CurrentLibsVersion)">true</UpdateLibs>
</PropertyGroup>
<Message Condition="'$(UpdateLibs)'!='true'" Text="Libraries up to date" Importance="high" />
<Message Condition="'$(UpdateLibs)'=='true'" Text="Libraries out of date, updating..." Importance="high" />
<CallTarget Condition="'$(UpdateLibs)'=='true'" Targets="DownloadLibs" />
</Target>
<Target Name="DownloadLibs">
<Message Text="Checking / downloading libraries..." Importance="high" />
<Exec Command="powershell -ExecutionPolicy Unrestricted -File scripts\ps\install.ps1 -q" StandardOutputImportance="normal" />
<PropertyGroup>
<LibsZipPath>$(LibsPath)openrct2-libs-vs2015.zip</LibsZipPath>
</PropertyGroup>
<!-- Clean libs directory -->
<RemoveDir Directories="$(LibsPath)" />
<MakeDir Directories="$(LibsPath)" />
<Message Text="Downloading libraries..." Importance="normal" />
<Exec Command="powershell -ExecutionPolicy Unrestricted -Command &quot;Invoke-WebRequest '$(LibsUrl)' -OutFile '$(LibsZipPath)'&quot;" StandardOutputImportance="low" />
<Unzip Input="$(LibsZipPath)" OutputDirectory="$(LibsPath)" />
<Delete Files="$(LibsZipPath)" ContinueOnError="true" />
<!-- Update libversion file -->
<WriteLinesToFile Lines="$(TargetLibsVersion)" File="$(LibsVersionPath)" Overwrite="true" />
</Target>
<Target Name="BeforeClean">
@ -106,7 +141,7 @@
<RemoveDir Directories="$(TargetDir)data" />
</Target>
<Target Name="BeforeBuild" BeforeTargets="InitializeBuildStatus" DependsOnTargets="DownloadLibs">
<Target Name="BeforeBuild" BeforeTargets="InitializeBuildStatus" DependsOnTargets="CheckLibs">
<PropertyGroup>
<BuildString Condition="'$(GIT_COMMIT_SHA1_SHORT)'!=''">$(GIT_COMMIT_SHA1_SHORT)</BuildString>
<BuildString Condition="'$(GIT_BRANCH)'!=''">$(BuildString) ($(GIT_BRANCH))</BuildString>

View File

@ -3,7 +3,7 @@
<!-- 7z Task -->
<UsingTask TaskName="_7z"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Inputs Required="true" ParameterType="System.String" />
<Output Required="true" ParameterType="System.String" />
@ -105,4 +105,22 @@
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="Unzip"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Input Required="true" ParameterType="System.String" />
<OutputDirectory Required="true" ParameterType="System.String" />
</ParameterGroup>
<Task>
<Reference Include="System.IO.Compression.FileSystem" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage(MessageImportance.Normal, String.Format("Extracting '{0}' to '{1}'.", Input, OutputDirectory));
System.IO.Compression.ZipFile.ExtractToDirectory(Input, OutputDirectory);
]]>
</Code>
</Task>
</UsingTask>
</Project>

View File

@ -1,83 +0,0 @@
#########################################################
# Common functions for OpenRCT2 PowerShell scripts
#########################################################
$scriptsPath = Split-Path $Script:MyInvocation.MyCommand.Path
function AppExists($app)
{
$result = (Get-Command $app -CommandType Application -ErrorAction SilentlyContinue)
return ($result -ne $null -and $result.Count -gt 0)
}
function AddPath($path)
{
$env:path = "$path;$env:path"
}
function Get-RootPath()
{
return Split-Path (Split-Path $scriptsPath)
}
function Prompt-User($message)
{
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Yes"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$choice = $host.UI.PromptForChoice("", $message, $options, 1)
return ($choice -eq 0)
}
function Resolve-PathFromBase($path)
{
$rootPath = Get-RootPath
if ($path.StartsWith($rootPath)) {
$path = $path.Remove(0, $rootPath.Length + 1)
}
return $path
}
function Symlink-or-Copy($path, $target)
{
$pathDirectory = Split-Path $path
$pathName = Split-Path $path -Leaf
$friendlyPath = Resolve-PathFromBase $path
$friendlyTarget = Resolve-PathFromBase $target
# If the path is not a symlink, copy files instead
$mustCopy = $false
if (Test-Path $path)
{
if (-not ((Get-Item $path).Attributes -band [IO.FileAttributes]::ReparsePoint))
{
$mustCopy = $true
}
}
$symlinkSuccessful = $false
if (-not $mustCopy)
{
try
{
Write-Host "Symlink $friendlyPath to $friendlyTarget..." -ForegroundColor Cyan
New-Item -Force -ItemType SymbolicLink -Path $pathDirectory -Name $pathName -Target $target -ErrorAction Stop
$symlinkSuccessful = $true
}
catch [System.Management.Automation.ParameterBindingException]
{
Write-Host " Your powershell can not create symlinks, try updating it" -ForegroundColor Red
}
catch [System.UnauthorizedAccessException]
{
Write-Host " You need to run powershell in administration mode to create symlinks" -ForegroundColor Red
}
}
if (-not $symlinkSuccessful)
{
Write-Host "Copying $friendlyTarget to $friendlyPath..." -ForegroundColor Cyan
New-Item -Force -Type Directory $path > $null
Copy-Item -Force -Recurse "$target\*" $path
}
}

View File

@ -1,63 +0,0 @@
#########################################################
# Script to install the latest dependencies for OpenRCT2
#########################################################
param (
[switch]$Force,
[switch]$Quiet
)
Write-Host "Installing OpenRCT2 development environment for Windows" -ForegroundColor Cyan
# Setup
$ErrorActionPreference = "Stop"
$scriptsPath = Split-Path $Script:MyInvocation.MyCommand.Path
Import-Module "$scriptsPath\common.psm1" -DisableNameChecking
# Constants
$libsVersion = 9
$libsUrl = "https://github.com/OpenRCT2/Dependencies/releases/download/v$libsVersion/openrct2-libs-vs2015.zip"
# Get paths
$rootPath = Get-RootPath
$libsPath = Join-Path $rootPath "lib"
$zipPath = Join-Path $libsPath "openrct2-libs-vs2015.zip"
$libsVersionPath = Join-Path $libsPath "libversion"
# Check if we need to update the dependencies
$currentLibsVersion = 0
$updateLibs = $true
if (Test-Path $libsVersionPath)
{
$currentLibsVersion = [IO.File]::ReadAllText($libsVersionPath)
}
if ($currentLibsVersion -ge $libsVersion)
{
$updateLibs = $false
}
# Check if user needs to download dependencies
$libsPathExists = Test-Path $libsPath
if ($libsPathExists -and -not $updateLibs -and -not $Force)
{
if (-not $Quiet -and (Prompt-User "Dependencies already exists, reinstall?"))
{
$updateLibs = $true
}
}
else
{
$updateLibs = $true
}
# Download latest version of the dependencies
if ($updateLibs) {
Write-Host "Updating dependencies..." -ForegroundColor Cyan
Remove-Item -Force -Recurse $libsPath -ErrorAction SilentlyContinue
New-Item -Force -ItemType Directory $libsPath > $null
Invoke-WebRequest $libsUrl -OutFile $zipPath
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') > $null
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $libsPath)
Remove-Item $zipPath -Force -ErrorAction SilentlyContinue
$libsVersion | Set-Content $libsVersionPath
}