forked from grantjenks/py-tree-sitter-languages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
97 lines (89 loc) · 3.32 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
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
import os
import subprocess
import sys
from tree_sitter import Language
repos = []
with open("repos.txt", "r") as file:
for line in file:
url, commit = line.split()
clone_directory = os.path.join("vendor", url.rstrip("/").split("/")[-1])
repos.append((url, commit, clone_directory))
# During the build, this script runs several times, and only needs to download
# repositories on first time.
if os.path.isdir("vendor") and len(os.listdir("vendor")) == len(repos):
print(f"{sys.argv[0]}: Language repositories have been cloned already.")
else:
os.makedirs("vendor", exist_ok=True)
for url, commit, clone_directory in repos:
print()
print(f"{sys.argv[0]}: Cloning: {url} (commit {commit}) --> {clone_directory}")
print()
if os.path.exists(clone_directory):
continue
# https://serverfault.com/a/713065
os.mkdir(clone_directory)
subprocess.check_call(["git", "init"], cwd=clone_directory)
subprocess.check_call(["git", "remote", "add", "origin", url], cwd=clone_directory)
subprocess.check_call(["git", "fetch", "--depth=1", "origin", commit], cwd=clone_directory)
subprocess.check_call(["git", "checkout", commit], cwd=clone_directory)
print()
if sys.platform == "win32":
languages_filename = "tree_sitter_languages\\languages.dll"
else:
languages_filename = "tree_sitter_languages/languages.so"
print(f"{sys.argv[0]}: Building", languages_filename)
Language.build_library(
languages_filename,
[
'vendor/tree-sitter-bash',
'vendor/tree-sitter-c',
'vendor/tree-sitter-c-sharp',
'vendor/tree-sitter-commonlisp',
'vendor/tree-sitter-cpp',
'vendor/tree-sitter-css',
'vendor/tree-sitter-dockerfile',
'vendor/tree-sitter-dot',
'vendor/tree-sitter-elisp',
'vendor/tree-sitter-elixir',
'vendor/tree-sitter-elm',
'vendor/tree-sitter-embedded-template',
'vendor/tree-sitter-erlang',
'vendor/tree-sitter-fixed-form-fortran',
'vendor/tree-sitter-fortran',
'vendor/tree-sitter-go',
'vendor/tree-sitter-go-mod',
'vendor/tree-sitter-hack',
'vendor/tree-sitter-haskell',
'vendor/tree-sitter-hcl',
'vendor/tree-sitter-html',
'vendor/tree-sitter-java',
'vendor/tree-sitter-javascript',
'vendor/tree-sitter-jsdoc',
'vendor/tree-sitter-json',
'vendor/tree-sitter-julia',
'vendor/tree-sitter-kotlin',
'vendor/tree-sitter-lua',
'vendor/tree-sitter-make',
'vendor/tree-sitter-markdown',
'vendor/tree-sitter-objc',
'vendor/tree-sitter-ocaml/ocaml',
'vendor/tree-sitter-perl',
'vendor/tree-sitter-php',
'vendor/tree-sitter-python',
'vendor/tree-sitter-ql',
'vendor/tree-sitter-r',
'vendor/tree-sitter-regex',
'vendor/tree-sitter-rst',
'vendor/tree-sitter-ruby',
'vendor/tree-sitter-rust',
'vendor/tree-sitter-scala',
'vendor/tree-sitter-sql',
'vendor/tree-sitter-sqlite',
'vendor/tree-sitter-toml',
'vendor/tree-sitter-tsq',
'vendor/tree-sitter-typescript/tsx',
'vendor/tree-sitter-typescript/typescript',
'vendor/tree-sitter-yaml',
'vendor/tree-sitter-swift'
]
)