-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
131 lines (113 loc) · 3.89 KB
/
Build.ps1
File metadata and controls
131 lines (113 loc) · 3.89 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
$SOURCE_FILES = ".\Scripts\Source\*.psc"
$FORCE_RECOMPILE = $false
$PAPYRUS_FOLDER = ".\PAPYRUS"
$LOG_LEVEL = 1
$STATUS_COMPILED_SUCCESS = 1
$STATUS_COMPILED_FAILED = 2
$STATUS_COMPILED_SKIPPED = 3
function Log {
param (
[int] $Level,
[string] $msg,
[object] $object
)
if ($Level -ge $LOG_LEVEL) {
if($object) {
Write-Host "$msg : $object"
} else {
Write-Host $msg
}
}
}
function GenerateDiffFile {
param (
$file1,
$file2,
$diffFile
)
$process = Start-Process -Wait -NoNewWindow -PassThru -FilePath "git.exe" -ArgumentList "diff --patch --no-index --output=`"$diffFile`" `"$file1`" `"$file2`""
$ret = [PSCustomObject]@{
command = "git diff"
file = $diffFile
ExitCode = $process.ExitCode
Status = if($process.ExitCode -eq 1) {$STATUS_COMPILED_SUCCESS} else {$STATUS_COMPILED_FAILED}
}
$ret
}
function Compile {
param (
$file
)
Log -Level 1 -msg "Compile" -object $file
$filePath = $file | Split-Path -Parent
$sourceBaseDir = $filePath | Split-Path -Parent
$includeFile = $filePath + "\include.txt"
$flagsFile = Resolve-Path "$PAPYRUS_FOLDER\Flags.flg"
[string]$include = $filePath
if([System.IO.File]::Exists($includeFile)) {
$lines = Get-Content -Path $includeFile
foreach ( $line in $lines ) {
$path = Resolve-Path "$PAPYRUS_FOLDER\$line"
$include = [string]::Join(';', $include, $path)
Log -Level 0 -msg "Include " -object $path
}
}
$originalFile = $sourceBaseDir + "\source_original\" + $file.BaseName + ".psc"
if([System.IO.File]::Exists($originalFile)) {
$diffFile = $sourceBaseDir + "\source\" + $file.BaseName + ".patch";
$ret = GenerateDiffFile -file1 $originalFile -file2 $file -diffFile $diffFile
if($ret.Status -ne $STATUS_COMPILED_SUCCESS) {
return $ret
}
}
$process = Start-Process -Wait -NoNewWindow -PassThru -FilePath "$PAPYRUS_FOLDER\PapyrusCompiler.exe" -ArgumentList "`"$file`" -o=`"$sourceBaseDir`" -i=`"$include`" -optimize -f=`"$flagsFile`""
$ret = [PSCustomObject]@{
command = "PapyrusCompiler"
file = $file
ExitCode = $process.ExitCode
Status = if($process.ExitCode -eq 0) {$STATUS_COMPILED_SUCCESS} else {$STATUS_COMPILED_FAILED}
}
$ret
}
function CompileIfNewest {
param (
$file
)
$sourceBaseDir = $file | Split-Path -Parent | Split-Path -Parent
$pexFile = $sourceBaseDir + "\" + $file.BaseName + ".pex"
Log -Level 0 -msg "Pex file" -object $pexFile
if($FORCE_RECOMPILE) {
Log -Level 0 -msg "Compile by force" -object $file
Compile -file $file
} else {
if([System.IO.File]::Exists($pexFile)) {
$pexFile = Get-Item $pexFile
if ($file.LastWriteTime -gt $pexFile.LastWriteTime) {
Log -Level 0 -msg "Compile by modification date" -object $file
Compile -file $file
} else {
Log -Level 0 -msg "Skip by modification date" -object $file
[pscustomobject]@{Status = $STATUS_COMPILED_SKIPPED}
}
} else {
Log -Level 0 -msg "Compile by not compiled yet" -object $file
Compile -file $file
}
}
}
$pscFiles = Get-ChildItem -Path $SOURCE_FILES -Force -Recurse -Exclude $PAPYRUS_FOLDER
foreach ( $pscFile in $pscFiles )
{
Log -Level 0 -msg "Process" -object $pscFile
$ret = CompileIfNewest -file $pscFile
if($ret.Status -eq $STATUS_COMPILED_FAILED) {
Write-Host "---"
Write-Host "Build failed:"
Write-Host "!" $ret.file.Name
Write-Host " -" $ret.command $ret.file
Log -Level 0 -msg "Process result" -object $ret
Exit
} else {
Log -Level 0 -msg "Process result" -object $ret
}
}