fort/deploy/setup-deployment.ps1

105 lines
3.4 KiB
PowerShell
Raw Permalink Normal View History

2017-11-21 08:32:09 +00:00
param (
[string]$TargetPath = ".\build",
2021-05-09 17:43:15 +00:00
[string]$BuildPath = "..\build",
2017-12-14 10:01:43 +00:00
[string]$RootPath = "..",
[string]$QtPath = ".\build-qt\qtbase",
[string]$Config = ""
2017-11-21 08:32:09 +00:00
)
echo "Setting up deployment files."
$json = Get-Content ".\deployment.json" -Raw | ConvertFrom-Json
$targetDirs = @($json.files.psobject.Properties.name)
for ($i = 0; $i -lt $targetDirs.length; $i++) {
$targetName = $targetDirs[$i]
2017-11-21 08:32:09 +00:00
$targetDir = $targetName -replace "/", "\"
2017-11-21 08:32:09 +00:00
$targetDir = $targetDir -replace '\${TARGET}', "$TargetPath"
if ($Config -And $targetDir.Contains('|')) {
$targetParts = $targetDir.Split('|')
$targetConf = $targetParts[1].Trim().Split(' ')
if ($targetConf -notcontains $Config) {
Write-Host -ForeGround Yellow "target: $targetDir (Skipped for $Config)"
continue
}
$targetDir = $targetParts[0].Trim()
}
2017-11-21 08:32:09 +00:00
echo "target: $targetDir"
New-Item $targetDir -ItemType directory -Force | Out-Null
$jsonTargetName = $json.files."$targetName"
$sections = @($jsonTargetName.psobject.Properties.name)
2017-11-21 08:32:09 +00:00
for ($j = 0; $j -lt $sections.length; $j++) {
$sectionName = $sections[$j]
$sectionOptional = $sectionName -match '\?$'
if ($Config -And $sectionName.Contains('|')) {
$sectionParts = $sectionName.Split('|')
$sectionConf = $sectionParts[1].Trim().Split(' ')
if ($sectionConf -notcontains $Config) {
Write-Host -ForeGround Yellow " $sectionName (Skipped for $Config)"
continue
}
}
2017-11-21 08:32:09 +00:00
echo " $sectionName"
$files = @($jsonTargetName."$sectionName")
2017-11-21 08:32:09 +00:00
for ($k = 0; $k -lt $files.Length; $k++) {
$file = $files[$k]
$file = $file -replace "/", "\"
$file = $file -replace '\${BUILD}', "$BuildPath"
2017-12-14 10:01:43 +00:00
$file = $file -replace '\${ROOT}', "$RootPath"
2017-11-21 08:32:09 +00:00
$file = $file -replace '\${QTPATH}', "$QtPath"
$file = $file -replace '\${CONFIG}', "$Config"
2017-11-21 08:32:09 +00:00
if ($file.Contains('|')) {
$fileParts = $file.Split('|')
$include = $fileParts[1].Trim().Split(' ')
$exclude = $fileParts[2].Trim().Split(' ')
$file = $fileParts[0].Trim()
if (Test-Path -Path $file) {
$dirPath = (Resolve-Path $file).path
$dirName = $dirPath.Split('\')[-1]
echo " $file ($include | $exclude)"
2017-11-21 08:32:09 +00:00
Get-ChildItem -Path $dirPath\* -Include $include -Exclude $exclude | Foreach-Object {
2017-11-21 08:32:09 +00:00
$dest = $_.FullName -replace [regex]::Escape($dirPath),"$targetDir\$dirName"
$destDir = $_.Directory.FullName -replace [regex]::Escape($dirPath),"$targetDir\$dirName"
New-Item "$destDir" -ItemType directory -Force | Out-Null
Copy-Item -Force -path $_ -destination $dest
}
}
elseif ($sectionOptional) {
Write-Host -ForeGround Yellow " $file (Optional path doesn't exist)"
}
else {
throw " $file (Required path doesn't exist)"
2017-11-21 08:32:09 +00:00
}
}
else {
echo " $file"
Copy-Item -Force "$file" $targetDir
}
}
}
}