Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring changes to build.py #103

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def build(repositories, output_path="libjava-tree-sitter", system=None, arch=Non
if arch and system == "Darwin":
arch = "arm64" if "aarch64" in arch else arch

output_path = f"{output_path}.{'dylib' if system == 'Darwin' else 'so'}"
output_extension = "dylib" if system == "Darwin" else "so"
output_path = f"{output_path}.{output_extension}"
env = ""
if arch:
env += (
Expand All @@ -41,23 +42,30 @@ def build(repositories, output_path="libjava-tree-sitter", system=None, arch=Non
else f"CFLAGS='-m{arch}' LDFLAGS='-m{arch}'"
)

cmd(f"make -C \"{path(here, 'tree-sitter')}\" clean {'> /dev/null' if not verbose else ''}")
cmd(f"{env} make -C \"{path(here, 'tree-sitter')}\" {'> /dev/null' if not verbose else ''}")
tree_sitter = path(here, "tree-sitter")
redirect = "> /dev/null" if not verbose else ""
cmd(f"make -C \"{tree_sitter}\" clean {redirect}")
cmd(f"{env} make -C \"{tree_sitter}\" {redirect}")

source_paths = find(path(here, "lib", "*.cc"))

compiler = new_c_compiler()
for repository in repositories:
repository_name = split_path(repository.rstrip('/'))[1]
repository_language = repository_name.split('tree-sitter-')[-1]
repository_name = split_path(repository.rstrip("/"))[1]
repository_language = repository_name.split("tree-sitter-")[-1]
repository_macro = f"TS_LANGUAGE_{repository_language.replace('-', '_').upper()}"
compiler.define_macro(repository_macro, "1")
if repository_name in ["tree-sitter-dtd", "tree-sitter-markdown", "tree-sitter-xml"]:
src_path = path(repository, repository_name, "src")
elif repository_name in ["tree-sitter-ocaml", "tree-sitter-tsx", "tree-sitter-typescript"]:
src_path = path(repository, repository_language, "src")
else:
src_path = path(repository, "src")
match repository_name:
case "tree-sitter-dtd" |\
"tree-sitter-markdown" |\
"tree-sitter-xml":
src_path = path(repository, repository_name, "src")
case "tree-sitter-ocaml" |\
"tree-sitter-tsx" |\
"tree-sitter-typescript":
src_path = path(repository, repository_language, "src")
case _:
src_path = path(repository, "src")
source_paths.append(path(src_path, "parser.c"))
scanner_c = path(src_path, "scanner.c")
scanner_cc = path(src_path, "scanner.cc")
Expand Down