BUILD 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
  5. package(default_visibility = ["//bazel/check_deps:__pkg__"])
  6. # See README.md for instructions on tree-sitter setup and use. These rules are
  7. # manual because the tree-sitter invocation is non-hermetic, and most developers
  8. # won't have it installed; we don't want to break "bazel test //..." if we can
  9. # avoid it.
  10. #
  11. # We use tree-sitter non-hermetically for two key reasons:
  12. #
  13. # - The main way of hermetically using npms in bazel, `aspect_rules_js`, uses
  14. # declare_symlink; we disallow that for important compatibility reasons.
  15. # - When generated, src/parser.c is over 500 KB, which is larger than we want to
  16. # check in. It should also be expected to grow if the grammar becomes more complete.
  17. # Convenience target for running all tests, including manual tests.
  18. test_suite(
  19. name = "tests",
  20. tags = ["manual"],
  21. tests = [
  22. ":string_fail_tests",
  23. ":string_tests",
  24. ":toolchain_testdata_tests",
  25. ],
  26. )
  27. # Call tree-sitter to generate parser files.
  28. genrule(
  29. name = "parser_files",
  30. srcs = ["grammar.js"],
  31. outs = [
  32. "src/parser.c",
  33. "src/tree_sitter/parser.h",
  34. ],
  35. cmd = "tree-sitter generate $(location grammar.js) &&\n" +
  36. "cp src/parser.c $(location src/parser.c) &&\n" +
  37. "cp src/tree_sitter/parser.h $(location src/tree_sitter/parser.h)",
  38. tags = ["manual"],
  39. )
  40. cc_library(
  41. name = "parser",
  42. srcs = [
  43. "src/scanner.c",
  44. ":src/parser.c",
  45. ],
  46. hdrs = [":src/tree_sitter/parser.h"],
  47. copts = ["-Wno-missing-prototypes"],
  48. tags = ["manual"],
  49. deps = ["@tree-sitter-bazel//:tree-sitter"],
  50. )
  51. cc_binary(
  52. name = "test_runner",
  53. testonly = 1,
  54. srcs = ["test_runner.cpp"],
  55. tags = ["manual"],
  56. deps = [
  57. ":parser",
  58. "//testing/base:file_helpers",
  59. ],
  60. )
  61. # TODO: This test is expected to fail. tree-sitter support has fallen
  62. # significantly behind the toolchain. Anybody looking at this can still use
  63. # these tests to work on improving support, but also, it may be worth improving
  64. # the test setup to:
  65. # - Support file_test's split files.
  66. # - Better understand when the toolchain doesn't expect a test file to parse.
  67. cc_test(
  68. name = "toolchain_testdata_tests",
  69. size = "small",
  70. srcs = ["test_runner.cpp"],
  71. args = ["$(locations //toolchain/testing:all_testdata)"],
  72. data = ["//toolchain/testing:all_testdata"],
  73. tags = ["manual"],
  74. deps = [
  75. ":parser",
  76. "//testing/base:file_helpers",
  77. ],
  78. )
  79. filegroup(
  80. name = "string_testdata",
  81. srcs = glob(
  82. ["testdata/string/*.carbon"],
  83. exclude = ["testdata/string/fail_*.carbon"],
  84. ),
  85. )
  86. filegroup(
  87. name = "string_fail_testdata",
  88. srcs = glob(["testdata/string/fail_*.carbon"]),
  89. )
  90. cc_test(
  91. name = "string_tests",
  92. size = "small",
  93. srcs = ["test_runner.cpp"],
  94. args = ["$(locations :string_testdata)"],
  95. data = [":string_testdata"],
  96. tags = ["manual"],
  97. deps = [
  98. ":parser",
  99. "//testing/base:file_helpers",
  100. ],
  101. )
  102. cc_test(
  103. name = "string_fail_tests",
  104. size = "small",
  105. srcs = ["test_runner.cpp"],
  106. args = ["$(locations :string_fail_testdata)"],
  107. data = [":string_fail_testdata"],
  108. env = {
  109. "FAIL_TESTS": "1",
  110. },
  111. tags = ["manual"],
  112. deps = [
  113. ":parser",
  114. "//testing/base:file_helpers",
  115. ],
  116. )