Skip to content

Instantly share code, notes, and snippets.

@Daenks
Last active December 3, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daenks/eb6c84ee6b300292f401 to your computer and use it in GitHub Desktop.
Save Daenks/eb6c84ee6b300292f401 to your computer and use it in GitHub Desktop.
Build Script for Meridian59.NET
#Build Server Script for Meridian59 .NET client written by Daenks
#Specifications provided by ShaKrune: https://gist.github.com/cyberjunk/843df6483dbe17bf6b04
Param(
#Source Repository Paths
[string]$RootPath="C:\Meridian59-DotNet",
[string]$EnginePath="\Engine\src\",
[string]$EngineSolution="Engine.sln",
[string]$ClientPath="\",
[string]$ClientSolution="Meridian59.sln",
[string]$OgreClientPath="\Meridian59.Ogre.Client\bin\", #
[string]$ResourcePath="\resources\", #repository Resources subfolder
#Destination Client Paths
[string]$PackagePath="C:\NETClient\", #Root Path for Uncompressed Client
[string]$PackageResourcePath="resources\",
[string]$RoomTexturePath="bgfobjects\",
[string]$BGFSource="C:\Program Files\Open Meridian\Meridian 103\resource",
[string]$RSBSource="C:\Program Files\Open Meridian\Meridian 103\resource\rsc0000.rsb",
#Control Parameters
[string]$BuildID="latest",
[string]$AdditionalCompileFlags="",
[ValidateSet('build','clean','package','checkout','resources')]$Action,
[string]$Project,
[string]$Platform,
[switch]$WhatIf
)
function DisplaySyntax
{
Write-Host
Write-Host "Usage Scenarios:"
Write-Host "1) Build or Clean Project and Platform"
Write-Host " Build-Meridian59NET.ps1 -Action [build|clean] -Project [engine|client] -Platform [x86|x64]"
Write-Host
Write-Host "2) Package Client binaries for distribution"
Write-Host " Build-Meridian59NET.ps1 -Action package -Platform [x86|x64]"
Write-Host
Write-Host "3) Checkout latest code"
Write-Host " Build-Meridian59NET.ps1 -Action checkout"
Write-Host
Write-Host "4) Package graphics and resources for distribution"
Write-Host " Build-Meridian59NET.ps1 -Action resources"
Write-Host
Write-Host "Optional Parameters:"
Write-Host "-RootPath the root path to work under for all operations"
Write-Host "-EnginePath the path to the engine solution files"
Write-Host "-EngineSolution the file name of the engine solution"
Write-Host "-ClientPath the path to the client solution files"
Write-Host "-ClientSolution the file name of the client solution file"
Write-Host "-PackagePath the path to output a packaged client"
Write-Host "-ResourcePath the path to copy resources from"
Write-Host "-PackageResourcePath the path to copy resources to"
Write-Host "-RoomTexturePath the path to copy grd*.bgf"
Write-Host "-ObjectsPath the path to copy other bgf files"
Write-Host "-BGFSource the path where BGF files are copied from"
Write-Host "-BuildID used by the build server to name output files"
Write-Host "-RSBSource filepath to the rsc0000.rsb file"
Write-Host "-AdditionalCompileFlags to add compile flags to build actions"
Write-Host "-WhatIf simulates the actions and outputs resulting command to be run instead of performing said command"
Write-Host
}
########### Path Creation Code ###########
function TestRootPath
{
if (-not (Test-Path -Path $RootPath -PathType container))
{
Write-Host "$RootPath does not exist, creating"
New-Item -Path $RootPath -ItemType Directory
}
}
function TestPackagePath
{
if (-not (Test-Path -Path "$PackagePath"-PathType container))
{
Write-Host "$PackagePath does not exist, creating"
New-Item -Path "$PackagePath" -ItemType Directory
}
if (-not (Test-Path -Path "$PackagePath$Platform"-PathType container))
{
Write-Host "$PackagePath$Platform does not exist, creating"
New-Item -Path "$PackagePath$Platform" -ItemType Directory
}
}
function TestResourcesPath
{
if (-not (Test-Path -Path "$PackagePath$PackageResourcePath"-PathType container))
{
Write-Host "$PackagePath$PackageResourcePath does not exist, creating"
New-Item -Path "$PackagePath$PackageResourcePath" -ItemType Directory
}
if (-not (Test-Path -Path "$PackagePath$PackageResourcePath$RoomTexturePath"-PathType container))
{
Write-Host "$PackagePath$PackageResourcePath$RoomTexturePath does not exist, creating"
New-Item -Path "$PackagePath$PackageResourcePath$RoomTexturePath" -ItemType Directory
}
if (-not (Test-Path -Path "$PackagePath$PackageResourcePath$ObjectsPath"-PathType container))
{
Write-Host "$PackagePath$PackageResourcePath$ObjectsPath does not exist, creating"
New-Item -Path "$PackagePath$PackageResourcePath$ObjectsPath" -ItemType Directory
}
}
########### Chekout Code ###########
function CheckoutAction
{
Set-Location -Path $RootPath
TestRootPath
$Command = "git pull origin master"
if ($WhatIf) { Write-Host $Command }
else
{
Write-Host "Running: $Command"
powershell "& $Command "
}
$Command = "git submodule update --init --recursive"
if ($WhatIf) { Write-Host $Command }
else
{
Write-Host "Running: $Command"
powershell "& $Command "
}
}
########### Build Action Code ###########
function Get-Batchfile ($file) {
$cmd = "`"$file`" & set"
cmd /c $cmd | Foreach-Object {
$p, $v = $_.split('=')
Set-Item -path env:$p -value $v
}
}
function VsVars32()
{
$vs120comntools = (Get-ChildItem env:VS120COMNTOOLS).Value
$batchFile = [System.IO.Path]::Combine($vs120comntools, "vsvars32.bat")
Get-Batchfile $BatchFile
}
function BuildAction
{
CheckBuildParams
switch ($Project)
{
engine
{
switch ($Platform)
{
x86 { $Command = "msbuild $RootPath$EnginePath$EngineSolution '/p:Configuration=Release;Platform=win32' $AdditionalCompileFlags" }
x64 { $Command = "msbuild $RootPath$EnginePath$EngineSolution '/p:Configuration=Release;Platform=x64' $AdditionalCompileFlags" }
}
}
client
{
switch ($Platform)
{
x86 { $Command = "msbuild $RootPath$ClientPath$ClientSolution '/p:Configuration=Release;Platform=x86' $AdditionalCompileFlags" }
x64 { $Command = "msbuild $RootPath$ClientPath$ClientSolution '/p:Configuration=Release;Platform=x64' $AdditionalCompileFlags" }
}
}
}
if (-not ($ENV:INCLUDE)) { VsVars32 }
if ($WhatIf) { Write-Host $Command }
else
{
Write-Host "Running: $Command"
powershell "& $Command "
}
}
########### Clean Action Code ###########
function CleanAction
{
CheckBuildParams
switch ($Project)
{
engine
{
switch ($Platform)
{
x86 { $Command = "msbuild $RootPath$EnginePath$EngineSolution /t:Clean '/p:Configuration=Release;Platform=win32'" }
x64 { $Command = "msbuild $RootPath$EnginePath$EngineSolution /t:Clean '/p:Configuration=Release;Platform=x64'" }
}
}
client
{
switch ($Platform)
{
x86 { $Command = "msbuild $RootPath$ClientPath$ClientSolution /t:Clean '/p:Configuration=Release;Platform=x86'" }
x64 { $Command = "msbuild $RootPath$ClientPath$ClientSolution /t:Clean '/p:Configuration=Release;Platform=x64'" }
}
}
}
if (-not ($ENV:INCLUDE)) { VsVars32 }
if ($WhatIf) { Write-Host $Command }
else
{
Write-Host "Running: $Command"
powershell "& $Command "
}
}
########### Parameter Checking ###########
function CheckBuildParams
{
if (($Platform -ne "x86") -and ($Platform -ne "x64"))
{
Write-Error "Incorrect -Platform parameter!"
DisplaySyntax
Exit -2
}
if (($Project -ne "engine") -and ($Project -ne "client"))
{
Write-Error "Incorrect -Project parameter!"
DisplaySyntax
Exit -3
}
}
function CheckPackageParams
{
if (($Platform -ne "x86") -and ($Platform -ne "x64"))
{
Write-Error "Incorrect -Platform parameter!"
DisplaySyntax
Exit -2
}
}
########### Package Action Code ###########
function CopyFiles
{
$BinaryItems=@("D3DX9_43.dll","ikpMP3.dll","irrKlang.dll","Meridian59.AdminUI.dll","Meridian59.dll",
"msvcp120.dll","msvcr120.dll","Meridian59.Ogre.Client.exe",
"configuration.xml")
$BinarySource = "$RootPath$OgreClientPath$Platform\\Release\\"
$BinaryDestination = "$PackagePath$Platform\\"
foreach ($file in $BinaryItems)
{
Copy-Item "$BinarySource$file" -destination $BinaryDestination -Force
}
Copy-Item $RSBSource -destination $ResourceDestination
}
function SetResourcePathInConfig
{
$ConfigurationPath = "$PackagePath$Platform\\"
[xml] $xconfig = Get-Content "$ConfigurationPath\\configuration.xml"
$xconfig.SelectSingleNode("//resources").SetAttribute("path","../resources")
$xconfig.Save("$ConfigurationPath\\configuration.xml")
}
function PackageAction
{
CheckPackageParams
TestPackagePath
CopyFiles
SetResourcePathInConfig
}
########### Resources Action Code ###########
function CopyResources
{
$ResourceFolders=@("caelum","decoration","legacy","music","models","particles","roomtextures",
"rooms","shader","sky","ui")
$CreateFolders=@("mail")
$ResourceSource = "$RootPath$ResourcePath"
$ResourceDestination = "$PackagePath$PackageResourcePath"
foreach ($folder in $ResourceFolders)
{
Copy-Item "$ResourceSource$folder" -destination $ResourceDestination -Recurse -Force
}
foreach ($folder in $CreateFolders)
{
New-Item -Type Directory -Path "$ResourceDestination$folder"
}
$RoomTextures = Get-ChildItem -Path $BGFSource -Filter grd*.bgf
$RoomTextures | Copy-Item -Destination "$ResourceDestination$RoomTexturePath" -Force
$ObjectTextures = Get-ChildItem -Path $BGFSource -Exclude $RoomTextures | Where-Object {$_.Name -like "*.bgf"}
$ObjectTextures | Copy-Item -Destination "$ResourceDestination$ObjectsPath" -Force
}
function CompressAll
{
Write-Zip -OutputPath $("$PackagePath" + "latest.zip") -Path $(Get-ChildItem $PackagePath -Recurse)
}
function ResoucesAction
{
TestResourcesPath
CopyResources
CompressAll
}
########### Main Code ###########
if (($Action -ne "build") -and ($Action -ne "clean") -and ($Action -ne "package") -and ($Action -ne "checkout") -and ($Action -ne "resources") -and ($Action -ne "compress"))
{
Write-Error "Incorrect -Action parameter!"
DisplaySyntax
Exit -1
}
switch ($Action)
{
checkout { CheckoutAction }
build { BuildAction }
clean { CleanAction }
package { PackageAction }
resources { ResoucesAction }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment