-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
115 lines (93 loc) · 2.9 KB
/
build.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
112
113
114
115
param (
[string]$arg
)
function call {
param (
[string] $command,
[switch] $verbose
)
Write-Host $command
if ($verbose) {
Invoke-Expression "$command"
}
else {
Invoke-Expression "$command > `$null"
}
}
function program {
foreach ($cmd in $args) {
$cmd = Get-Command $cmd -ErrorAction SilentlyContinue
if ($null -ne $cmd) {
return '& "' + $cmd.Source + '"'
}
}
}
function require {
foreach ($cmd in $args) {
if ($null -eq $cmd) {
Write-Error "Missing required program"
exit
}
}
}
$JAVA = program "java"
$MVN = program "mvn"
$DMD = program "ldmd2"
$7z = program "7z" "C:\Program Files\7-Zip\7z.exe"
$BUILD_DIR = "build"
$ANTLR_DIR = "antlr4"
$ANTLR = "antlr4-4.9.2"
$TARGET = "$BUILD_DIR/$ANTLR/tool/resources/org/antlr/v4/tool/templates/codegen/D/"
$TEST_TEMPLATE_DIR = "$BUILD_DIR/$ANTLR/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates"
$SOURCE_FILES = Get-ChildItem -Path source -Filter *.d -Recurse | ForEach-Object {
Resolve-Path -Relative $_.FullName
}
$rules = @{
prepare_generator = {
require $7z $JAVA $MVN
if (!(Test-Path "build")) {
call "mkdir build"
}
call "cd build"
call "$7z x ../$ANTLR_DIR/$ANTLR.tar.gz -aoa"
call "$7z x $ANTLR.tar -aoa -ttar"
call "cd .."
call "cp codegen/DTarget.java $BUILD_DIR/$ANTLR/tool/src/org/antlr/v4/codegen/target"
call "mkdir -f -p $TEST_TEMPLATE_DIR"
call "cp -r -fo -co codegen/templates/ $TARGET"
call "cd $BUILD_DIR/$ANTLR"
call "`$env:MAVEN_OPTS = '-Xmx1G'"
call "$MVN -DskipTests install" -verbose
call "cd ../.."
}
build_examples = {
require $JAVA
if (!(Test-Path "$BUILD_DIR/$ANTLR/tool/target/antlr4-4.9.2-complete.jar")) {
Invoke-Command $rules.prepare_generator
}
call "$JAVA -jar $BUILD_DIR/$ANTLR/tool/target/antlr4-4.9.2-complete.jar -Dlanguage=D -atn -o $BUILD_DIR doc/examples/Expr.g4"
call "$JAVA -jar $BUILD_DIR/$ANTLR/tool/target/antlr4-4.9.2.jar -Dlanguage=D -atn -o $BUILD_DIR doc/examples/ruleTranslator/RuleTranslator.g4"
}
docs = {
require $DMD
if (!(Test-Path "build")) {
call "mkdir build"
}
call "$DMD -op -Dd$BUILD_DIR/docs -o- $SOURCE_FILES"
}
clobber = {
if (Test-Path "build") {
call "rm -r -fo build"
}
}
"" = {
Write-Host "No command specified"
Write-Host "Available rules:"
foreach ($r in $rules.Keys) {
if ($r -ne "") {
Write-Host " " $r
}
}
}
}
Invoke-Command $rules[$arg]