forked from kevinmehall/rust-peg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
46 lines (36 loc) · 1.44 KB
/
bootstrap.ps1
File metadata and controls
46 lines (36 loc) · 1.44 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
# Translated from bootstrap.sh
# Have not tested it yet
function Invoke-NativeCommand() {
# A handy way to run a command, and automatically throw an error if the
# exit code is non-zero.
if ($args.Count -eq 0) {
throw "Must supply some arguments."
}
$command = $args[0]
$commandArgs = @()
if ($args.Count -gt 1) {
$commandArgs = $args[1..($args.Count - 1)]
}
$output = (& $command $commandArgs) | Out-String
$result = $LASTEXITCODE
if ($result -ne 0) {
throw "$command $commandArgs exited with code $result."
}
return $output
}
$output = Invoke-NativeCommand "cargo" "run" "-p" "peg-macros" "--" "peg-macros/grammar.rustpeg"
Out-File -FilePath "peg-macros/grammar_new.rs" -InputObject $output
Move-Item -Path "peg-macros/grammar.rs" -Destination "peg-macros/grammar_old.rs"
Copy-Item -Path "peg-macros/grammar_new.rs" -Destination "peg-macros/grammar.rs"
cargo run -p "peg-macros" -- "peg-macros/grammar.rustpeg" > peg-macros/grammar_new.rs
if ($LASTEXITCODE -eq 0) {
Compare-Object -ReferenceObject (Get-Content -Path peg-macros/grammar.rs) -DifferenceObject (Get-Content -Path peg-macros/grammar_new.rs)
rustfmt "peg-macros/grammar.rs"
$remove = Read-Host "Want to remove old grammar? [Y/n]"
if ($remove -eq "Y") {
Remove-Item -Path "peg-macros/grammar_old.rs"
Remove-Item -Path "peg-macros/grammar_new.rs"
}
} else {
Write-Output "Failed"
}