1
1
mirror of https://github.com/github/semantic.git synced 2024-12-12 04:58:02 +03:00
semantic/build/common.bzl

156 lines
4.9 KiB
Python
Raw Normal View History

2020-06-10 07:18:25 +03:00
# This file lets us share warnings and such across the project
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",
)
DEVELOPMENT_GHC_FLAGS = ["-O0"]
RELEASE_GHC_FLAGS = ["-O1"]
GHC_FLAGS = [
"-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",
] + 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-07-01 08:30:58 +03:00
# These macros declare new packages.
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.."""
http_archive(
name = name,
build_file_content = """
package(default_visibility = ["//visibility:public"])
exports_files(glob(["{}"]))
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']))
""".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)],
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."""
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
haskell_library(
name = name,
# 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.
compiler_flags = GHC_FLAGS + [
'-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes),
2020-06-26 20:39:04 +03:00
],
repl_ghci_args = GHC_FLAGS + [
2020-06-26 20:39:04 +03:00
'-DNODE_TYPES_PATH="../../../../$(rootpath {})"'.format(nodetypes),
],
srcs = srcs,
2020-07-01 06:59:18 +03:00
extra_srcs = [nodetypes, "@tree-sitter-{}//:corpus".format(ts_package)],
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",
"@stackage//:aeson",
"@stackage//:algebraic-graphs",
2020-06-25 15:56:09 +03:00
"//:containers",
"@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",
"@stackage//:tree-sitter",
"@stackage//:tree-sitter-" + language,
],
)
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
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"],
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,
],
)