2020-06-10 07:18:25 +03:00
|
|
|
# This file lets us share warnings and such across the project
|
|
|
|
|
2020-06-25 05:16:58 +03:00
|
|
|
load(
|
|
|
|
"@rules_haskell//haskell:defs.bzl",
|
|
|
|
"haskell_library",
|
|
|
|
"haskell_test",
|
|
|
|
)
|
2020-07-01 08:30:58 +03:00
|
|
|
load(
|
|
|
|
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
|
|
|
"http_archive",
|
|
|
|
)
|
|
|
|
load(
|
|
|
|
"@bazel_tools//tools/build_defs/repo:git.bzl",
|
|
|
|
"new_git_repository",
|
|
|
|
)
|
2020-06-25 05:16:58 +03:00
|
|
|
|
2020-07-01 07:35:09 +03:00
|
|
|
DEVELOPMENT_GHC_FLAGS = ["-O0"]
|
|
|
|
RELEASE_GHC_FLAGS = ["-O1"]
|
|
|
|
|
|
|
|
GHC_FLAGS = [
|
2020-06-23 19:07:47 +03:00
|
|
|
"-v1",
|
|
|
|
"-j8",
|
|
|
|
"-fdiagnostics-color=always",
|
|
|
|
"-ferror-spans",
|
2020-06-10 07:18:25 +03:00
|
|
|
"-Weverything",
|
|
|
|
"-Wno-missing-local-signatures",
|
|
|
|
"-Wno-missing-import-lists",
|
|
|
|
"-Wno-implicit-prelude",
|
|
|
|
"-Wno-safe",
|
|
|
|
"-Wno-unsafe",
|
|
|
|
"-Wno-name-shadowing",
|
|
|
|
"-Wno-monomorphism-restriction",
|
|
|
|
"-Wno-missed-specialisations",
|
|
|
|
"-Wno-all-missed-specialisations",
|
|
|
|
"-Wno-star-is-type",
|
|
|
|
"-Wno-missing-deriving-strategies",
|
2020-07-01 09:17:39 +03:00
|
|
|
"-DBAZEL_BUILD=1",
|
2020-07-01 07:35:09 +03:00
|
|
|
] + select(
|
|
|
|
{
|
|
|
|
"//:release": RELEASE_GHC_FLAGS,
|
|
|
|
"//:development": DEVELOPMENT_GHC_FLAGS,
|
|
|
|
"//:debug": DEVELOPMENT_GHC_FLAGS,
|
|
|
|
},
|
|
|
|
)
|
2020-06-23 21:54:32 +03:00
|
|
|
|
2020-07-01 08:35:20 +03:00
|
|
|
EXECUTABLE_FLAGS = [
|
2020-06-23 21:54:32 +03:00
|
|
|
"-threaded",
|
|
|
|
]
|
2020-06-25 05:16:58 +03:00
|
|
|
|
2020-07-01 08:30:58 +03:00
|
|
|
# These macros declare new packages.
|
|
|
|
|
2020-06-26 20:07:24 +03:00
|
|
|
def tree_sitter_node_types_archive(name, version, sha256, urls = [], nodetypespath = "src/node-types.json"):
|
2020-07-01 08:30:58 +03:00
|
|
|
"""Create a package for a tree-sitter grammar and export its node-types.json file/test corpus.."""
|
2020-06-26 20:07:24 +03:00
|
|
|
http_archive(
|
|
|
|
name = name,
|
|
|
|
build_file_content = """
|
2020-07-01 01:16:25 +03:00
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
|
2020-06-26 20:07:24 +03:00
|
|
|
exports_files(glob(["{}"]))
|
2020-07-01 01:16:25 +03:00
|
|
|
|
2020-07-01 02:07:28 +03:00
|
|
|
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']))
|
2020-06-26 20:07:24 +03:00
|
|
|
""".format(nodetypespath),
|
|
|
|
strip_prefix = "{}-{}".format(name, version),
|
2020-06-26 21:14:21 +03:00
|
|
|
urls = ["https://github.com/tree-sitter/{}/archive/v{}.tar.gz".format(name, version)],
|
2020-06-26 20:07:24 +03:00
|
|
|
sha256 = sha256,
|
|
|
|
)
|
|
|
|
|
2020-07-01 08:30:58 +03:00
|
|
|
def tree_sitter_node_types_git(name, commit, shallow_since):
|
|
|
|
"""Create a package pinned off a Git repo. Prefer the node_types_archive call to this."""
|
|
|
|
new_git_repository(
|
|
|
|
name = name,
|
|
|
|
build_file_content = """
|
|
|
|
exports_files(["src/node-types.json"])
|
|
|
|
|
|
|
|
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']), visibility = ["//visibility:public"])
|
|
|
|
""",
|
|
|
|
commit = commit,
|
|
|
|
remote = "https://github.com/tree-sitter/{}.git".format(name),
|
|
|
|
shallow_since = shallow_since,
|
|
|
|
)
|
|
|
|
|
|
|
|
# These macros declare library targets inside the language packages.
|
|
|
|
|
2020-07-01 06:59:18 +03:00
|
|
|
def semantic_language_library(language, name, srcs, ts_package = "", nodetypes = "", **kwargs):
|
2020-06-25 15:56:09 +03:00
|
|
|
"""Create a new library target with dependencies needed for a language-AST project."""
|
2020-07-01 00:27:25 +03:00
|
|
|
if nodetypes == "":
|
|
|
|
nodetypes = "@tree-sitter-{}//:src/node-types.json".format(language)
|
2020-07-01 06:59:18 +03:00
|
|
|
if ts_package == "":
|
|
|
|
ts_package = language
|
2020-06-25 05:16:58 +03:00
|
|
|
haskell_library(
|
|
|
|
name = name,
|
2020-06-25 17:14:42 +03:00
|
|
|
# We can't use Template Haskell to find out the location of the
|
|
|
|
# node-types.json files, but we can pass it in as a preprocessor
|
|
|
|
# directive.
|
2020-07-01 07:35:09 +03:00
|
|
|
compiler_flags = GHC_FLAGS + [
|
2020-06-26 20:07:24 +03:00
|
|
|
'-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes),
|
2020-06-26 20:39:04 +03:00
|
|
|
],
|
2020-07-01 07:35:09 +03:00
|
|
|
repl_ghci_args = GHC_FLAGS + [
|
2020-06-26 20:39:04 +03:00
|
|
|
'-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes),
|
2020-06-25 17:14:42 +03:00
|
|
|
],
|
2020-06-25 05:16:58 +03:00
|
|
|
srcs = srcs,
|
2020-07-01 06:59:18 +03:00
|
|
|
extra_srcs = [nodetypes, "@tree-sitter-{}//:corpus".format(ts_package)],
|
2020-06-25 05:16:58 +03:00
|
|
|
deps = [
|
2020-06-25 15:56:09 +03:00
|
|
|
"//:base",
|
2020-06-27 19:47:04 +03:00
|
|
|
"//semantic-analysis",
|
|
|
|
"//semantic-ast",
|
|
|
|
"//semantic-core",
|
|
|
|
"//semantic-proto",
|
|
|
|
"//semantic-scope-graph",
|
|
|
|
"//semantic-source",
|
|
|
|
"//semantic-tags",
|
2020-06-25 05:16:58 +03:00
|
|
|
"@stackage//:aeson",
|
|
|
|
"@stackage//:algebraic-graphs",
|
2020-06-25 15:56:09 +03:00
|
|
|
"//:containers",
|
2020-06-25 05:16:58 +03:00
|
|
|
"@stackage//:fused-effects",
|
|
|
|
"@stackage//:fused-syntax",
|
|
|
|
"@stackage//:generic-lens",
|
|
|
|
"@stackage//:generic-monoid",
|
|
|
|
"@stackage//:hashable",
|
|
|
|
"@stackage//:lens",
|
|
|
|
"@stackage//:pathtype",
|
|
|
|
"@stackage//:semilattices",
|
2020-06-27 19:53:17 +03:00
|
|
|
"//:template-haskell",
|
2020-06-27 19:47:04 +03:00
|
|
|
"//:text",
|
2020-06-25 05:16:58 +03:00
|
|
|
"@stackage//:tree-sitter",
|
|
|
|
"@stackage//:tree-sitter-" + language,
|
|
|
|
],
|
|
|
|
)
|
2020-07-01 02:07:28 +03:00
|
|
|
|
2020-07-01 06:59:18 +03:00
|
|
|
def semantic_language_parsing_test(language, semantic_package = "", ts_package = ""):
|
|
|
|
if semantic_package == "":
|
|
|
|
semantic_package = language
|
|
|
|
if ts_package == "":
|
|
|
|
ts_package = language
|
2020-07-01 02:07:28 +03:00
|
|
|
haskell_test(
|
|
|
|
name = "test",
|
|
|
|
srcs = ["test/PreciseTest.hs"],
|
2020-07-01 06:59:18 +03:00
|
|
|
data = ["@tree-sitter-{}//:corpus".format(ts_package)],
|
2020-07-01 08:14:59 +03:00
|
|
|
tags = ["language-test"],
|
2020-07-01 02:07:28 +03:00
|
|
|
deps = [
|
|
|
|
":semantic-{}".format(language),
|
|
|
|
"//:base",
|
|
|
|
"//:bytestring",
|
|
|
|
"//:text",
|
|
|
|
"//semantic:fixtureshim",
|
|
|
|
"//semantic-ast",
|
|
|
|
"@stackage//:bazel-runfiles",
|
|
|
|
"@stackage//:hedgehog",
|
|
|
|
"@stackage//:pathtype",
|
|
|
|
"@stackage//:tasty",
|
|
|
|
"@stackage//:tasty-hedgehog",
|
|
|
|
"@stackage//:tasty-hunit",
|
2020-07-01 06:59:18 +03:00
|
|
|
"@stackage//:tree-sitter-" + semantic_package,
|
2020-07-01 02:07:28 +03:00
|
|
|
],
|
|
|
|
)
|