From cac967e87f9496ed901eba70780f7904952818b9 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 24 Jun 2020 22:16:58 -0400 Subject: [PATCH] Create a macro to define language packages quickly. --- build/common.bzl | 40 +++++++++++++++++++++++++++++++++++++ semantic-codeql/BUILD.bazel | 2 +- semantic-go/BUILD.bazel | 33 +++--------------------------- semantic-java/BUILD.bazel | 33 +++--------------------------- semantic-json/BUILD.bazel | 34 ++++++------------------------- semantic-php/BUILD.bazel | 40 +++---------------------------------- semantic-python/BUILD.bazel | 40 +++---------------------------------- semantic-ruby/BUILD.bazel | 40 +++---------------------------------- semantic-tsx/BUILD.bazel | 40 +++---------------------------------- 9 files changed, 65 insertions(+), 237 deletions(-) diff --git a/build/common.bzl b/build/common.bzl index bc8e9d64f..b4480b955 100644 --- a/build/common.bzl +++ b/build/common.bzl @@ -1,5 +1,12 @@ # This file lets us share warnings and such across the project +load( + "@rules_haskell//haskell:defs.bzl", + "haskell_library", + "haskell_test", + "haskell_toolchain_library", +) + STANDARD_GHC_WARNINGS = [ "-O0", "-v1", @@ -23,3 +30,36 @@ STANDARD_GHC_WARNINGS = [ STANDARD_EXECUTABLE_FLAGS = [ "-threaded", ] + +def semantic_language_library(language, name, srcs, **kwargs): + haskell_library( + name = name, + compiler_flags = STANDARD_GHC_WARNINGS, + srcs = srcs, + extra_srcs = ["//vendor:" + language + "-node-types.json"], + deps = [ + ":base", + "//semantic-analysis:lib", + "//semantic-ast:lib", + "//semantic-core:lib", + "//semantic-proto:lib", + "//semantic-scope-graph:lib", + "//semantic-source:lib", + "//semantic-tags:lib", + "@stackage//:aeson", + "@stackage//:algebraic-graphs", + "@stackage//:containers", + "@stackage//:fused-effects", + "@stackage//:fused-syntax", + "@stackage//:generic-lens", + "@stackage//:generic-monoid", + "@stackage//:hashable", + "@stackage//:lens", + "@stackage//:pathtype", + "@stackage//:semilattices", + "@stackage//:template-haskell", + "@stackage//:text", + "@stackage//:tree-sitter", + "@stackage//:tree-sitter-" + language, + ], + ) diff --git a/semantic-codeql/BUILD.bazel b/semantic-codeql/BUILD.bazel index e2b37897e..a7363152d 100644 --- a/semantic-codeql/BUILD.bazel +++ b/semantic-codeql/BUILD.bazel @@ -23,7 +23,7 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. +# Not using semantic_language_library because of naming irregularities haskell_library( name = "lib", srcs = glob(["src/**/*.hs"]), diff --git a/semantic-go/BUILD.bazel b/semantic-go/BUILD.bazel index 9ad538ff9..cdf38722b 100644 --- a/semantic-go/BUILD.bazel +++ b/semantic-go/BUILD.bazel @@ -15,7 +15,7 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,35 +23,8 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:go-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-go", - ], + language = "go", ) diff --git a/semantic-java/BUILD.bazel b/semantic-java/BUILD.bazel index 8a3dc495b..f81d30b31 100644 --- a/semantic-java/BUILD.bazel +++ b/semantic-java/BUILD.bazel @@ -15,7 +15,7 @@ load( ) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,35 +23,8 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:java-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-java", - ], + language = "java", ) diff --git a/semantic-json/BUILD.bazel b/semantic-json/BUILD.bazel index 91c425bed..373906413 100644 --- a/semantic-json/BUILD.bazel +++ b/semantic-json/BUILD.bazel @@ -13,40 +13,18 @@ load( "haskell_cabal_binary", "haskell_cabal_library", ) +load( + "//:build/common.bzl", + "semantic_language_library", +) # haskell_toolchain_library can access builtin GHC packages # and assign them a bazel target name, so that they # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - extra_srcs = ["//vendor:json-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-json", - ], + language = "json", ) diff --git a/semantic-php/BUILD.bazel b/semantic-php/BUILD.bazel index 4b2d80cb8..4abf616b8 100644 --- a/semantic-php/BUILD.bazel +++ b/semantic-php/BUILD.bazel @@ -4,18 +4,11 @@ package(default_visibility = ["//visibility:public"]) # Load rules_haskell rules. load( "@rules_haskell//haskell:defs.bzl", - "haskell_binary", - "haskell_library", "haskell_toolchain_library", ) -load( - "@rules_haskell//haskell:cabal.bzl", - "haskell_cabal_binary", - "haskell_cabal_library", -) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,35 +16,8 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:php-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-php", - ], + language = "php", ) diff --git a/semantic-python/BUILD.bazel b/semantic-python/BUILD.bazel index fc8333c92..8dc1e3613 100644 --- a/semantic-python/BUILD.bazel +++ b/semantic-python/BUILD.bazel @@ -4,18 +4,11 @@ package(default_visibility = ["//visibility:public"]) # Load rules_haskell rules. load( "@rules_haskell//haskell:defs.bzl", - "haskell_binary", - "haskell_library", "haskell_toolchain_library", ) -load( - "@rules_haskell//haskell:cabal.bzl", - "haskell_cabal_binary", - "haskell_cabal_library", -) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,8 +16,7 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob( include = ["src/**/*.hs"], @@ -33,31 +25,5 @@ haskell_library( "src/Language/Python/ScopeGraph.hs", ], ), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:python-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-python", - ], + language = "python", ) diff --git a/semantic-ruby/BUILD.bazel b/semantic-ruby/BUILD.bazel index 4d56be495..dcb2cb1bc 100644 --- a/semantic-ruby/BUILD.bazel +++ b/semantic-ruby/BUILD.bazel @@ -4,18 +4,11 @@ package(default_visibility = ["//visibility:public"]) # Load rules_haskell rules. load( "@rules_haskell//haskell:defs.bzl", - "haskell_binary", - "haskell_library", "haskell_toolchain_library", ) -load( - "@rules_haskell//haskell:cabal.bzl", - "haskell_cabal_binary", - "haskell_cabal_library", -) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,35 +16,8 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:ruby-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-ruby", - ], + language = "ruby", ) diff --git a/semantic-tsx/BUILD.bazel b/semantic-tsx/BUILD.bazel index d1eb760f8..49597bf0c 100644 --- a/semantic-tsx/BUILD.bazel +++ b/semantic-tsx/BUILD.bazel @@ -4,18 +4,11 @@ package(default_visibility = ["//visibility:public"]) # Load rules_haskell rules. load( "@rules_haskell//haskell:defs.bzl", - "haskell_binary", - "haskell_library", "haskell_toolchain_library", ) -load( - "@rules_haskell//haskell:cabal.bzl", - "haskell_cabal_binary", - "haskell_cabal_library", -) load( "//:build/common.bzl", - "STANDARD_GHC_WARNINGS", + "semantic_language_library", ) # haskell_toolchain_library can access builtin GHC packages @@ -23,35 +16,8 @@ load( # can be referenced as dependencies. haskell_toolchain_library(name = "base") -# You can add your own libraries with haskell_library. -haskell_library( +semantic_language_library( name = "lib", srcs = glob(["src/**/*.hs"]), - compiler_flags = STANDARD_GHC_WARNINGS, - extra_srcs = ["//vendor:tsx-node-types.json"], - deps = [ - ":base", - "//semantic-analysis:lib", - "//semantic-ast:lib", - "//semantic-core:lib", - "//semantic-proto:lib", - "//semantic-scope-graph:lib", - "//semantic-source:lib", - "//semantic-tags:lib", - "@stackage//:aeson", - "@stackage//:algebraic-graphs", - "@stackage//:containers", - "@stackage//:fused-effects", - "@stackage//:fused-syntax", - "@stackage//:generic-lens", - "@stackage//:generic-monoid", - "@stackage//:hashable", - "@stackage//:lens", - "@stackage//:pathtype", - "@stackage//:semilattices", - "@stackage//:template-haskell", - "@stackage//:text", - "@stackage//:tree-sitter", - "@stackage//:tree-sitter-tsx", - ], + language = "tsx", )