211 lines
8.7 KiB
Ruby
211 lines
8.7 KiB
Ruby
class Semgrep < Formula
|
|
include Language::Python::Virtualenv
|
|
|
|
desc "Easily detect and prevent bugs and anti-patterns in your codebase"
|
|
homepage "https://semgrep.dev"
|
|
url "https://github.com/returntocorp/semgrep.git",
|
|
tag: "v0.70.0",
|
|
revision: "0acf0158796b0244a24623f3ee9d6ea0d9ac2dad"
|
|
license "LGPL-2.1-only"
|
|
head "https://github.com/returntocorp/semgrep.git", branch: "develop"
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_big_sur: "7655b45f87adcf6746abc73f36b4d581a6bf3f62b18cf26cec6fdbf495af8b76"
|
|
sha256 cellar: :any, big_sur: "c1ba5e8c2cbd8344c6fddc47af2960b7c0709072cced99d81191c6d6b9ed53ca"
|
|
sha256 cellar: :any, catalina: "a001c7cec9effd55f780e30e2db57c01c871760951f1220487cf9b5e9ffbdb1b"
|
|
sha256 cellar: :any, mojave: "6ae74f296dd8ec58010e069b389f523fa3af1d1b8c655153406902bb46ef50ae"
|
|
sha256 x86_64_linux: "b99357d0ebd92cd3e938b441b9e049d4e51e56726940bed272bc52e3c9c0e37f"
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "coreutils"=> :build
|
|
depends_on "dune" => :build
|
|
depends_on "ocaml" => :build
|
|
depends_on "opam" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "pcre"
|
|
depends_on "python@3.9"
|
|
depends_on "tree-sitter"
|
|
|
|
uses_from_macos "rsync" => :build
|
|
|
|
on_linux do
|
|
depends_on "gcc" => [:build, :test]
|
|
end
|
|
|
|
fails_with gcc: "5"
|
|
|
|
resource "attrs" do
|
|
url "https://files.pythonhosted.org/packages/ed/d6/3ebca4ca65157c12bd08a63e20ac0bdc21ac7f3694040711f9fd073c0ffb/attrs-21.2.0.tar.gz"
|
|
sha256 "ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"
|
|
end
|
|
|
|
resource "bracex" do
|
|
url "https://files.pythonhosted.org/packages/10/d5/0f2fa4d62d905c159ad3f81fb3b0446d5ef5a900ca942d2995f441b5c440/bracex-2.2.tar.gz"
|
|
sha256 "8230f3a03f1f76c192a7844377124300fbaec83870a728b629dfabd9be9e83d0"
|
|
end
|
|
|
|
resource "certifi" do
|
|
url "https://files.pythonhosted.org/packages/6c/ae/d26450834f0acc9e3d1f74508da6df1551ceab6c2ce0766a593362d6d57f/certifi-2021.10.8.tar.gz"
|
|
sha256 "78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"
|
|
end
|
|
|
|
resource "charset-normalizer" do
|
|
url "https://files.pythonhosted.org/packages/9f/c5/334c019f92c26e59637bb42bd14a190428874b2b2de75a355da394cf16c1/charset-normalizer-2.0.7.tar.gz"
|
|
sha256 "e019de665e2bcf9c2b64e2e5aa025fa991da8720daa3c1138cadd2fd1856aed0"
|
|
end
|
|
|
|
resource "click" do
|
|
url "https://files.pythonhosted.org/packages/f4/09/ad003f1e3428017d1c3da4ccc9547591703ffea548626f47ec74509c5824/click-8.0.3.tar.gz"
|
|
sha256 "410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"
|
|
end
|
|
|
|
resource "click-option-group" do
|
|
url "https://files.pythonhosted.org/packages/3c/86/5de6d909d9dcc85627a178788ec3e8c3ef81cda175badb48ad0bb582628d/click-option-group-0.5.3.tar.gz"
|
|
sha256 "a6e924f3c46b657feb5b72679f7e930f8e5b224b766ab35c91ae4019b4e0615e"
|
|
end
|
|
|
|
resource "colorama" do
|
|
url "https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz"
|
|
sha256 "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"
|
|
end
|
|
|
|
resource "idna" do
|
|
url "https://files.pythonhosted.org/packages/62/08/e3fc7c8161090f742f504f40b1bccbfc544d4a4e09eb774bf40aafce5436/idna-3.3.tar.gz"
|
|
sha256 "9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"
|
|
end
|
|
|
|
resource "jsonschema" do
|
|
url "https://files.pythonhosted.org/packages/69/11/a69e2a3c01b324a77d3a7c0570faa372e8448b666300c4117a516f8b1212/jsonschema-3.2.0.tar.gz"
|
|
sha256 "c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"
|
|
end
|
|
|
|
resource "packaging" do
|
|
url "https://files.pythonhosted.org/packages/df/86/aef78bab3afd461faecf9955a6501c4999933a48394e90f03cd512aad844/packaging-21.0.tar.gz"
|
|
sha256 "7dc96269f53a4ccec5c0670940a4281106dd0bb343f47b7471f779df49c2fbe7"
|
|
end
|
|
|
|
resource "peewee" do
|
|
url "https://files.pythonhosted.org/packages/c9/51/3b2ded25a1cd51d1096bda8e0d1474712fe71efd374ae39b86c73a83d648/peewee-3.14.4.tar.gz"
|
|
sha256 "9e356b327c2eaec6dd42ecea6f4ddded025793dba906a3d065a0452e726c51a2"
|
|
end
|
|
|
|
resource "pyparsing" do
|
|
url "https://files.pythonhosted.org/packages/c1/47/dfc9c342c9842bbe0036c7f763d2d6686bcf5eb1808ba3e170afdb282210/pyparsing-2.4.7.tar.gz"
|
|
sha256 "c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"
|
|
end
|
|
|
|
resource "pyrsistent" do
|
|
url "https://files.pythonhosted.org/packages/f4/d7/0fa558c4fb00f15aabc6d42d365fcca7a15fcc1091cd0f5784a14f390b7f/pyrsistent-0.18.0.tar.gz"
|
|
sha256 "773c781216f8c2900b42a7b638d5b517bb134ae1acbebe4d1e8f1f41ea60eb4b"
|
|
end
|
|
|
|
resource "requests" do
|
|
url "https://files.pythonhosted.org/packages/e7/01/3569e0b535fb2e4a6c384bdbed00c55b9d78b5084e0fb7f4d0bf523d7670/requests-2.26.0.tar.gz"
|
|
sha256 "b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"
|
|
end
|
|
|
|
resource "ruamel.yaml" do
|
|
url "https://files.pythonhosted.org/packages/71/81/f597606e81f53eb69330e3f8287e9b5a3f7ed0481824036d550da705cd82/ruamel.yaml-0.17.16.tar.gz"
|
|
sha256 "1a771fc92d3823682b7f0893ad56cb5a5c87c48e62b5399d6f42c8759a583b33"
|
|
end
|
|
|
|
resource "ruamel.yaml.clib" do
|
|
url "https://files.pythonhosted.org/packages/8b/25/08e5ad2431a028d0723ca5540b3af6a32f58f25e83c6dda4d0fcef7288a3/ruamel.yaml.clib-0.2.6.tar.gz"
|
|
sha256 "4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd"
|
|
end
|
|
|
|
resource "six" do
|
|
url "https://files.pythonhosted.org/packages/71/39/171f1c67cd00715f190ba0b100d606d440a28c93c7714febeca8b79af85e/six-1.16.0.tar.gz"
|
|
sha256 "1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"
|
|
end
|
|
|
|
resource "tqdm" do
|
|
url "https://files.pythonhosted.org/packages/e3/c1/b3e42d5b659ca598508e2a9ef315d5eef0a970f874ef9d3b38d4578765bd/tqdm-4.62.3.tar.gz"
|
|
sha256 "d359de7217506c9851b7869f3708d8ee53ed70a1b8edbba4dbcb47442592920d"
|
|
end
|
|
|
|
resource "urllib3" do
|
|
url "https://files.pythonhosted.org/packages/80/be/3ee43b6c5757cabea19e75b8f46eaf05a2f5144107d7db48c7cf3a864f73/urllib3-1.26.7.tar.gz"
|
|
sha256 "4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece"
|
|
end
|
|
|
|
resource "wcmatch" do
|
|
url "https://files.pythonhosted.org/packages/47/63/88168196fdcd77e012944bb83ab589a9d53336b8094703a64567f0bf218c/wcmatch-8.2.tar.gz"
|
|
sha256 "4d54ddb506c90b5a5bba3a96a1cfb0bb07127909e19046a71d689ddfb18c3617"
|
|
end
|
|
|
|
def install
|
|
ENV.deparallelize
|
|
Dir.mktmpdir("opamroot") do |opamroot|
|
|
ENV["OPAMROOT"] = opamroot
|
|
ENV["OPAMYES"] = "1"
|
|
|
|
# Officially suggested workaround for breaking change in setuptools v50.0.0
|
|
# See: https://sourceforge.net/p/ruamel-yaml/tickets/356/
|
|
# Relevant Issue: https://github.com/pypa/setuptools/issues/2355
|
|
ENV["SETUPTOOLS_USE_DISTUTILS"] = "stdlib"
|
|
|
|
system "opam", "init", "--no-setup", "--disable-sandboxing"
|
|
ENV.deparallelize { system "opam", "switch", "create", "ocaml-base-compiler.4.12.0" }
|
|
|
|
# Manually run steps from `opam exec -- make setup` to link Homebrew's tree-sitter
|
|
system "opam", "update", "-y"
|
|
|
|
# We pass --no-depexts so as to disable the check for pkg-config.
|
|
# It seems to not be found when building on ubuntu
|
|
# See discussion on https://github.com/Homebrew/homebrew-core/pull/82693
|
|
system "opam", "install", "-y", "--deps-only", "--no-depexts", "./semgrep-core/src/pfff"
|
|
system "opam", "install", "-y", "--deps-only", "--no-depexts", "./semgrep-core/src/ocaml-tree-sitter-core"
|
|
system "opam", "install", "-y", "--deps-only", "--no-depexts", "./semgrep-core"
|
|
|
|
# Install semgrep-core and spacegrep
|
|
cd "semgrep-core" do
|
|
system "opam", "install", "--deps-only", "-y", "."
|
|
system "opam", "exec", "--", "make", "all"
|
|
system "opam", "exec", "--", "make", "install"
|
|
bin.install "_build/install/default/bin/semgrep-core" => "semgrep-core"
|
|
bin.install "_build/install/default/bin/spacegrep" => "spacegrep"
|
|
end
|
|
end
|
|
|
|
ENV["SEMGREP_SKIP_BIN"] = "1"
|
|
python_path = "semgrep"
|
|
cd python_path do
|
|
venv = virtualenv_create(libexec, Formula["python@3.9"].bin/"python3.9")
|
|
venv.pip_install resources.reject { |r| r.name == "ocaml-tree-sitter" }
|
|
venv.pip_install_and_link buildpath/python_path
|
|
end
|
|
end
|
|
|
|
test do
|
|
system "#{bin}/semgrep", "--help"
|
|
(testpath/"script.py").write <<~EOS
|
|
def silly_eq(a, b):
|
|
return a + b == a + b
|
|
EOS
|
|
|
|
output = shell_output("#{bin}/semgrep script.py -l python -e '$X == $X'")
|
|
assert_match "a + b == a + b", output
|
|
|
|
(testpath/"script.ts").write <<~EOS
|
|
function test_equal() {
|
|
a = 1;
|
|
b = 2;
|
|
//ERROR: match
|
|
if (a + b == a + b)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
EOS
|
|
|
|
output = shell_output("#{bin}/semgrep script.ts -l ts -e '$X == $X'")
|
|
assert_match "a + b == a + b", output
|
|
end
|
|
end
|