-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
50 lines (38 loc) · 1.52 KB
/
build.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
# Ran when building wheel files for rsm-markup
import subprocess
import sys
from typing import Any
# All shell commands below run from this directory by default; see the cwd parameter
DEFAULT_CMD_DIR = "tree-sitter-rsm"
def run(
cmd: str,
check: bool = True,
shell: bool = True,
cwd: str = DEFAULT_CMD_DIR,
print_output: bool = False,
):
"""Run a shell command from `cwd`.
Use check=False if you don't care whether it succeeds.
"""
print(f"build.py: {cmd}", flush=True)
result = subprocess.run(
cmd, stdout=subprocess.PIPE, check=check, shell=shell, cwd=cwd
)
if print_output:
print(result.stdout.decode("utf-8"))
def build(_: Any): # one argument is passed by poetry but we don't need it
"""Install tree-sitter and build the shared object library."""
run("npm install") # Install tree-sitter and its dependencies
# 'tree-sitter test' creates the .so file; we don't care if the tests actually pass,
if sys.platform == "win32":
run("sh node_modules/.bin/tree-sitter generate")
run("sh node_modules/.bin/tree-sitter build -o build/rsm.so")
else:
run("node ./node_modules/.bin/tree-sitter generate")
run("node ./node_modules/.bin/tree-sitter build -o build/rsm.so")
fn = "rsm.dll" if sys.platform == "win32" else "rsm.so"
# watch out: tree-sitter might change this dir inadvertently...
# run(f"cp ~/.tree-sitter/bin/{fn} rsm/", cwd=".")
run(f"cp build/{fn} ../rsm/")
if __name__ == "__main__":
build(None)