* Drop legacy binding updates * templates: Properly replace author email * templates: Update npm packages * bindings: Improve cmake file * cmake: Support amalgamated build * cmake: Correct library scopes * make: Fix tree-sitter.pc generation - update to 0.24.1: * fix(generate): move generated header files into the generate crate - update do 0.24.0: * docs: add Kotlin to the playground * fix(generate): remove necessary files from gitignore template * feat(generate): bump tree-sitter dev dependency to 0.23 * fix(cli): remove conflicting short flags in the fuzz subcommand * feat(bindings): bump go-tree-sitter version * docs(changelog): add 0.23.0 release notes * feat: add an API to time out query executions * fix(generate): disallow inline variables referencing themselves * fix(rust): add missing TSNode functions * fix(lib): correct extra node creation from non-zero root-alias cursors * fix(test): exit with an error if a test marked with :error has no error * fix(test): retain attributes when running test -u * feat(language): derive Clone and Copy on LanguageFn * fix(lib): backtrack to the last relevant iterator if no child was found * fix(generate): add tree-sitter to the dev-dependencies of the Cargo.toml * fix(binding_web): correct edit signature * build(lib): build using cmake * fix(cli): keep skipped tests unchanged in the test/corpus OBS-URL: https://build.opensuse.org/package/show/editors/tree-sitter?expand=0&rev=31
94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
#!/usr/bin/python3
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# SPDX-FileCopyrightText: 2024 Björn Bidar
|
|
|
|
"""Generate compile commands by reading binding.gyp"""
|
|
|
|
# pylint: disable=invalid-name
|
|
# pylint: disable=too-many-branches
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
from typing import List, Dict, Optional
|
|
import ast
|
|
from copy import copy
|
|
|
|
parser = argparse.ArgumentParser(prog = Path(__file__).name,
|
|
description = "Generate compile commands by reading binding.gyp")
|
|
parser.add_argument('-b', '--binding', dest = "binding",
|
|
action="store", help="Path to binding file")
|
|
parser.add_argument('-g', '--grammar', dest = "grammars",
|
|
action= "append",
|
|
required = False,
|
|
help="Specify grammars in case binding file contains more than one grammar")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.binding:
|
|
binding_gyp = Path(args.binding)
|
|
else:
|
|
binding_gyp = Path("binding.gyp")
|
|
|
|
if not binding_gyp.exists():
|
|
raise FileNotFoundError(f"bindings {binding_gyp.absolute()} not found")
|
|
|
|
|
|
with open(binding_gyp, 'r', encoding='utf8') as binding_raw:
|
|
binding = ast.literal_eval(binding_raw.read())
|
|
|
|
targets = binding['targets'][0]
|
|
|
|
def buildCompileCommand(target: Dict, grammars: Optional[List[str]] = None) -> Dict[
|
|
str,
|
|
List
|
|
]:
|
|
"""Generate compile commands from TARGET supplied found in GRAMMARS or src"""
|
|
cc = 'cc'
|
|
cflags_c = []
|
|
cflags_cc = []
|
|
commands = {}
|
|
base_command = [ cc, '-shared', '-fPIC']
|
|
suffixes_cc = ['cc', 'cxx', 'cpp']
|
|
if 'cflags_c' in target:
|
|
cflags_c = target['cflags_c']
|
|
if 'clfags_cc' in target:
|
|
cflags_cc = target['cflags_cc']
|
|
|
|
include_dirs = []
|
|
for include_dir in target['include_dirs']:
|
|
# Don't include any node commands
|
|
if not include_dir.startswith('<!'):
|
|
include_dirs+=[ include_dir ]
|
|
|
|
if not grammars:
|
|
grammars = { "src" }
|
|
for _grammar in grammars:
|
|
command = copy(base_command)
|
|
for include_dir in include_dirs:
|
|
command += '-I', include_dir
|
|
for source in target['sources']:
|
|
source = Path(source)
|
|
# We don't need node bindings
|
|
if source.parts[0] == "node":
|
|
continue
|
|
if not source.parts[0] == _grammar:
|
|
continue
|
|
for suffix_cc in suffixes_cc:
|
|
if source.name.endswith(suffix_cc):
|
|
command+= '-xc++', source
|
|
break
|
|
if source.name.endswith('.c'):
|
|
command+= '-xc', source
|
|
for flag in cflags_c, cflags_cc:
|
|
if flag:
|
|
command += flag
|
|
commands[_grammar] = command
|
|
return commands
|
|
|
|
if not args.grammars:
|
|
args.grammars = ["src"]
|
|
|
|
cc_cmd = buildCompileCommand(targets, args.grammars)
|
|
for grammar in args.grammars:
|
|
print(*cc_cmd[grammar])
|