-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate.jou
64 lines (50 loc) · 1.73 KB
/
update.jou
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
# Self-update: "jou --update" updates the Jou compiler.
import "stdlib/ascii.jou"
import "stdlib/errno.jou"
import "stdlib/str.jou"
import "stdlib/io.jou"
import "stdlib/mem.jou"
import "stdlib/process.jou"
import "./paths.jou"
# TODO: add some kind of chdir to standard library
if WINDOWS:
declare _chdir(dirname: byte*) -> int
def chdir(dir: byte*) -> int:
return _chdir(dir)
else:
declare chdir(path: byte*) -> int
def fail_update() -> noreturn:
puts("")
puts("Updating Jou failed. If you need help, please create an issue on GitHub:")
puts(" https://github.com/Akuli/jou/issues/new")
exit(1)
def confirm(prompt: byte*) -> None:
printf("%s (y/n) ", prompt)
fflush(stdout)
line: byte[50] = ""
fgets(line, sizeof(line) as int, stdin)
trim_ascii_whitespace(line)
if strcmp(line, "Y") != 0 and strcmp(line, "y") != 0:
printf("Aborted.\n")
exit(1)
def update_jou_compiler() -> None:
exe = find_current_executable()
exedir = dirname(exe)
printf("Installation directory: %s\n\n", exedir)
if chdir(exedir) == -1:
fprintf(stderr, "chdir(\"%s\") failed: %s\n", exedir, strerror(get_errno()))
fail_update()
if WINDOWS:
confirm("Download and install the latest version of Jou from GitHub releases?")
if system("powershell -ExecutionPolicy bypass -File update.ps1") != 0:
fail_update()
elif NETBSD:
confirm("Run \"git pull && gmake\"?")
if system("git pull && gmake") != 0:
fail_update()
else:
confirm("Run \"git pull && make\"?")
if system("git pull && make") != 0:
fail_update()
free(exe)
printf("\n\nYou now have the latest version of Jou :)\n")