Repository navigation
Expand file tree
/
Copy pathExportSourceFiles.ps1
More file actions
167 lines (147 loc) · 7.41 KB
/
Copy pathExportSourceFiles.ps1
File metadata and controls
167 lines (147 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
param (
[switch]$DryRun
)
# Mirrors the Basis Server solution into the Unity package at Basis/Packages/com.basis.server, and the
# default transport package Basis Server/Packages/com.basis.transport.litenetlib into Basis/Packages.
# The package only ships what Unity compiles (the asmdef'd assemblies) plus Docker and the licence
# files, so test projects, the dev consoles and the benchmark/compute projects stay out of it.
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
function Find-BasisFoundationDir {
param (
[string]$currentDir
)
while ($currentDir -and (Split-Path -Leaf $currentDir) -ne "Basis Foundation") {
$currentDir = Split-Path -Parent $currentDir
}
return $currentDir
}
$basisFoundationDir = Find-BasisFoundationDir -currentDir $scriptDir
if ($basisFoundationDir) {
$source = Join-Path $basisFoundationDir "Basis Unity\Basis Server"
$destination = Join-Path $basisFoundationDir "Basis Unity\Basis\Packages\com.basis.server"
}
else {
# Checkouts without the "Basis Foundation" wrapper keep both trees directly under the repo root.
$source = Join-Path $scriptDir "Basis Server"
$destination = Join-Path $scriptDir "Basis\Packages\com.basis.server"
}
if (-Not (Test-Path -Path $source)) {
Write-Host "Error: Source directory not found - $source"
exit 1
}
if (-Not (Test-Path -Path $destination)) {
Write-Host "Error: Destination directory not found - $destination"
exit 1
}
# Top-level entries the package mirrors. Anything absent here is deliberately not shipped:
# BasisServerTests, BasisRestApi.Tests, BasisBenchAgent, BasisServerBenchmark, BasisNetworkCompute,
# BasisServerConsole, BasisNetworkClientConsole, benchmark-results, the .sln and every .csproj.
$includeDirs = @("BasisNetworkClient", "BasisNetworkCore", "BasisNetworkServer", "Contrib", "Docker")
$includeFiles = @("package.json", "profile-run.sh")
# Package-side .meta, .asmdef, .gitignore, .gitattributes, LICENSE and THIRD_PARTY_NOTICES.md are
# authoritative and are never overwritten from source.
$excludeExtensions = @(".dll", ".asmdef", ".meta", ".csproj", ".sln", ".user", ".vsidx", ".cache")
$excludeFragments = @("\obj\", "\bin\", "\.vs\", "\.git\", "\Did.Tests\", "\Crypto.Tests\", "\Dns.Tests\", "PersistentKv")
function Test-Excluded {
param (
[string]$fullName
)
if ([IO.Path]::GetExtension($fullName) -in $excludeExtensions) { return $true }
foreach ($fragment in $excludeFragments) {
if ($fullName -like "*$fragment*") { return $true }
}
return $false
}
$copied = 0
$added = 0
$removed = 0
foreach ($entry in $includeDirs) {
$sourceDir = Join-Path $source $entry
$destinationDir = Join-Path $destination $entry
if (-Not (Test-Path -Path $sourceDir)) { continue }
# Drop package files whose source counterpart is gone, scoped to the mirrored subtree so
# nothing outside it is ever touched.
if (Test-Path -Path $destinationDir) {
Get-ChildItem -Path $destinationDir -Recurse -File | Where-Object { -not (Test-Excluded $_.FullName) } | ForEach-Object {
$relativePath = $_.FullName.Substring($destinationDir.Length)
if (-not (Test-Path -Path (Join-Path $sourceDir $relativePath))) {
if (-not $DryRun) {
Remove-Item -Path $_.FullName -Force
$metaPath = "$($_.FullName).meta"
if (Test-Path -Path $metaPath) { Remove-Item -Path $metaPath -Force }
}
Write-Host "DEL $entry$relativePath"
$removed++
}
}
}
Get-ChildItem -Path $sourceDir -Recurse -File | Where-Object { -not (Test-Excluded $_.FullName) } | ForEach-Object {
$relativePath = $_.FullName.Substring($sourceDir.Length)
$destinationPath = Join-Path $destinationDir $relativePath
$destinationFolder = Split-Path -Parent $destinationPath
if ((-not $DryRun) -and (-not (Test-Path -Path $destinationFolder))) { New-Item -ItemType Directory -Path $destinationFolder -Force | Out-Null }
if (-not (Test-Path -Path $destinationPath)) {
if (-not $DryRun) { Copy-Item -Path $_.FullName -Destination $destinationPath -Force }
Write-Host "ADD $entry$relativePath"
$added++
}
elseif ((Get-FileHash $_.FullName).Hash -ne (Get-FileHash $destinationPath).Hash) {
if (-not $DryRun) { Copy-Item -Path $_.FullName -Destination $destinationPath -Force }
Write-Host "SYNC $entry$relativePath"
$copied++
}
}
}
foreach ($entry in $includeFiles) {
$sourceFile = Join-Path $source $entry
$destinationFile = Join-Path $destination $entry
if (-Not (Test-Path -Path $sourceFile)) { continue }
if ((-not (Test-Path -Path $destinationFile)) -or ((Get-FileHash $sourceFile).Hash -ne (Get-FileHash $destinationFile).Hash)) {
if (-not $DryRun) { Copy-Item -Path $sourceFile -Destination $destinationFile -Force }
Write-Host "SYNC $entry"
$copied++
}
}
$transportSource = Join-Path $source "Packages\com.basis.transport.litenetlib"
$transportDestination = Join-Path (Split-Path -Parent $destination) "com.basis.transport.litenetlib"
$transportExcludeFragments = @("\Server~\", "\obj\", "\bin\", "\.git\")
function Test-TransportExcluded {
param (
[string]$fullName
)
foreach ($fragment in $transportExcludeFragments) {
if ($fullName -like "*$fragment*") { return $true }
}
return $false
}
if (Test-Path -Path $transportSource) {
if (Test-Path -Path $transportDestination) {
Get-ChildItem -Path $transportDestination -Recurse -File | Where-Object { -not (Test-TransportExcluded $_.FullName) } | ForEach-Object {
$relativePath = $_.FullName.Substring($transportDestination.Length)
if (-not (Test-Path -LiteralPath (Join-Path $transportSource $relativePath))) {
if (-not $DryRun) { Remove-Item -LiteralPath $_.FullName -Force }
Write-Host "DEL com.basis.transport.litenetlib$relativePath"
$removed++
}
}
}
Get-ChildItem -Path $transportSource -Recurse -File | Where-Object { -not (Test-TransportExcluded $_.FullName) } | ForEach-Object {
$relativePath = $_.FullName.Substring($transportSource.Length)
$destinationPath = Join-Path $transportDestination $relativePath
$destinationFolder = Split-Path -Parent $destinationPath
if ((-not $DryRun) -and (-not (Test-Path -Path $destinationFolder))) { New-Item -ItemType Directory -Path $destinationFolder -Force | Out-Null }
if (-not (Test-Path -LiteralPath $destinationPath)) {
if (-not $DryRun) { Copy-Item -LiteralPath $_.FullName -Destination $destinationPath -Force }
Write-Host "ADD com.basis.transport.litenetlib$relativePath"
$added++
}
elseif ((Get-FileHash -LiteralPath $_.FullName).Hash -ne (Get-FileHash -LiteralPath $destinationPath).Hash) {
if (-not $DryRun) { Copy-Item -LiteralPath $_.FullName -Destination $destinationPath -Force }
Write-Host "SYNC com.basis.transport.litenetlib$relativePath"
$copied++
}
}
}
Write-Host ""
Write-Host "$(if ($DryRun) { 'Dry run: ' } else { 'Export complete. ' })$added added, $copied updated, $removed removed."
Write-Host "Review 'git status' on the package before committing: work authored in the package copy is overwritten by this script."