forked from Ch4nKyy/BG3WASD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
!Update.ps1
111 lines (91 loc) · 3.15 KB
/
!Update.ps1
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
#Requires -Version 5
# args
param (
[Parameter(Mandatory)][ValidateSet('SOURCEGEN', 'DISTRIBUTE')][string]$Mode,
[string]$Version,
[string]$Path,
[string]$Project
)
$ErrorActionPreference = "Stop"
$Folder = $PSScriptRoot | Split-Path -Leaf
$SourceExt = @('.c', '.cc', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.inl', 'inc', '.ixx')
$ConfigExt = @('.ini', '.json', '.toml')
$DocsExt = @('.md')
$env:ScriptCulture = (Get-Culture).Name -eq 'zh-CN'
function L {
param (
[Parameter(Mandatory)][string]$en,
[string]$zh = ''
)
process {
if ($env:ScriptCulture -and $zh) {
return $zh
}
else {
return $en
}
}
}
function Resolve-Files {
param (
[Parameter(ValueFromPipeline)][string]$a_parent = $PSScriptRoot,
[string[]]$a_directory = @('include', 'src', 'test')
)
process {
Push-Location $PSScriptRoot
$_generated = [System.Collections.ArrayList]::new()
try {
foreach ($directory in $a_directory) {
if (!$env:RebuildInvoke) {
Write-Host "`t[$a_parent/$directory]"
}
Get-ChildItem "$a_parent/$directory" -Recurse -File -ErrorAction SilentlyContinue | Where-Object {
($_.Extension -in ($SourceExt + $DocsExt)) -and
($_.Name -notmatch 'Plugin.h|Version.h')
} | Resolve-Path -Relative | ForEach-Object {
if (!$env:RebuildInvoke) {
Write-Host "`t`t<$_>"
}
$_generated.Add("`n`t`"$($_.Substring(2) -replace '\\', '/')`"") | Out-Null
}
}
Get-ChildItem "$a_parent" -File -ErrorAction SilentlyContinue | Where-Object {
($_.Extension -in ($ConfigExt + $DocsExt)) -and
($_.Name -notmatch 'cmake|vcpkg')
} | Resolve-Path -Relative | ForEach-Object {
if (!$env:RebuildInvoke) {
Write-Host "`t`t<$_>"
}
$_generated.Add("`n`t`"$($_.Substring(2) -replace '\\', '/')`"") | Out-Null
}
}
finally {
Pop-Location
}
return $_generated
}
}
Write-Host "`n`t<$Folder> [$Mode]"
# @@SOURCEGEN
if ($Mode -eq 'SOURCEGEN') {
Write-Host "`tGenerating CMake sourcelist..."
Remove-Item "$Path/sourcelist.cmake" -Force -Confirm:$false -ErrorAction Ignore
$generated = 'set(SOURCES'
$generated += $PSScriptRoot | Resolve-Files
if ($Path) {
$generated += $Path | Resolve-Files
}
$generated += "`n)"
[IO.File]::WriteAllText("$Path/sourcelist.cmake", $generated)
}
# @@DISTRIBUTE
if ($Mode -eq 'DISTRIBUTE') {
# update script to every project
Get-ChildItem "$PSScriptRoot/*/*" -Directory | Where-Object {
$_.Name -notin @('vcpkg', 'Build', '.git', '.vs') -and
(Test-Path "$_/CMakeLists.txt" -PathType Leaf)
} | ForEach-Object {
Write-Host "`tUpdated <$_>"
Robocopy.exe "$PSScriptRoot" "$_" '!Update.ps1' /MT /NJS /NFL /NDL /NJH | Out-Null
}
}