-
Notifications
You must be signed in to change notification settings - Fork 24
/
atalanta_podem_build.swift
executable file
·91 lines (71 loc) · 2.06 KB
/
atalanta_podem_build.swift
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
#!/usr/bin/env swift
import Foundation
extension String {
func sh() -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = ["sh", "-c", self]
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
}
func main() -> Int32 {
let apt = "which apt-get".sh()
if apt == 0 {
let _ = "sudo apt-get install -y make flex bison libreadline-dev libncurses5-dev libncursesw5-dev ".sh()
}
let env = ProcessInfo.processInfo.environment
let execPrefix = env["EXEC_PREFIX"] ?? "/usr/local/bin"
let previousCWD = env["PWD"]!
let atalanta = installAtalanta(execPrefix: execPrefix, previousCWD: previousCWD)
if atalanta != 0 {
let _ = "echo Failed to install Atalanta".sh()
return atalanta
}
let podem = installPODEM(execPrefix: execPrefix, previousCWD: previousCWD)
if podem != 0 {
let _ = "echo Failed to install PODEM".sh()
return podem
}
return EX_OK
}
func installAtalanta(execPrefix: String, previousCWD: String) -> Int32 {
defer {
chdir(previousCWD)
}
let downloadAndExtract = "curl -sL https://github.com/hsluoyz/Atalanta/archive/master.tar.gz | tar -xzf -".sh()
if downloadAndExtract != 0 {
return downloadAndExtract
}
chdir("Atalanta-master")
let make = "make".sh()
if make != 0 {
return make
}
let copy = "sudo cp atalanta \(execPrefix)".sh()
if copy != 0 {
return copy
}
return EX_OK
}
func installPODEM(execPrefix: String, previousCWD: String) -> Int32 {
defer {
chdir(previousCWD)
}
let downloadAndExtract = "curl -sL http://tiger.ee.nctu.edu.tw/course/Testing2018/assignments/hw0/podem.tgz | tar -xzf -".sh()
if downloadAndExtract != 0 {
return downloadAndExtract
}
chdir("podem")
let make = "make".sh()
if make != 0 {
return make
}
let copy = "sudo cp atpg \(execPrefix)".sh()
if copy != 0 {
return copy
}
return EX_OK
}
exit(main())