-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_latest.py
executable file
·126 lines (107 loc) · 2.69 KB
/
fetch_latest.py
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
#!/usr/bin/env python3
import contextlib
import subprocess
import sys
from pathlib import Path
# Emacs 29.1 stable release
EMACS_SHA = "a9b28224af0f73d1fe0f422e9b318c5b91af889b"
EMACS_DIR = Path.cwd() / "emacs"
def fetch_sha():
if not (EMACS_DIR / ".git").exists():
EMACS_DIR.mkdir(exist_ok=True)
subprocess.run(["git", "init"], check=True, cwd=EMACS_DIR)
try:
current_sha = subprocess.run(
["git", "rev-parse", "HEAD"],
check=True,
cwd=EMACS_DIR,
stdout=subprocess.PIPE,
text=True,
)
current_sha_str = current_sha.stdout.strip()
if current_sha_str == EMACS_SHA:
return
except subprocess.CalledProcessError:
pass
git_remote = subprocess.run(
["git", "remote"],
check=True,
cwd=EMACS_DIR,
stdout=subprocess.PIPE,
text=True,
)
git_remote_str = git_remote.stdout.strip()
if not git_remote_str:
subprocess.run(
["git", "remote", "add", "origin", "https://github.com/emacs-mirror/emacs"],
check=True,
cwd=EMACS_DIR,
)
subprocess.run(
["git", "fetch", "origin", EMACS_SHA],
check=True,
cwd=EMACS_DIR,
)
subprocess.run(
["git", "reset", "--hard", "FETCH_HEAD"],
check=True,
cwd=EMACS_DIR,
)
def fetch_dependencies():
sentinel = Path.cwd() / ".fetched_dependencies"
if sentinel.exists():
return
if sys.platform != "darwin":
exit("Cannot install dependencies on a non-macOS system")
subprocess.run(
[
"brew",
"install",
"autoconf",
"cmake",
"gcc",
"gnutls",
"jansson",
"libgccjit",
"texinfo",
"tree-sitter",
],
check=True,
)
sentinel.touch()
def compile():
subprocess.run(
["bash", "autogen.sh"],
check=True,
cwd=EMACS_DIR,
)
subprocess.run(
[
"bash",
"configure",
"--with-cairo",
"--with-json",
"--with-native-compilation",
"--with-tree-sitter",
"--with-x",
"--without-mailutils",
"CFLAGS=-O3 -mtune=native -fomit-frame-pointer -I/opt/homebrew/include",
],
check=True,
cwd=EMACS_DIR,
)
subprocess.run(
["make"],
check=True,
cwd=EMACS_DIR,
)
subprocess.run(
["sudo", "make", "install"],
check=True,
cwd=EMACS_DIR,
)
pass
if __name__ == "__main__":
fetch_sha()
fetch_dependencies()
compile()