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.68.2",
|
|
revision: "b70aa7c9658a16326a8ba3a789176fbdba39ca3b"
|
|
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: "e5f4d773ca4b20e43e9c1a28f10c3a83e3c77c36d3fde171df3bd7afa1d1a745"
|
|
sha256 cellar: :any, big_sur: "6fd7a31e4357dbbe61d188efcbb4a60a0b62dcc33d58a4d0e116cde5cd486828"
|
|
sha256 cellar: :any, catalina: "2ce2b6fd4d3f7d734cff8b5b6cd9393dec611016ec61560cb070b7fce98d571a"
|
|
sha256 cellar: :any, mojave: "a0c8483d854b8a509359bfc58158ac05284045dbeda9b5dc63b09ada32431752"
|
|
sha256 x86_64_linux: "a5149a27a6d12db6705ab02dc9010f8303a154bb37da4032c8c5da5746b7f418"
|
|
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
|
|
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/bb/80/7118945282845f8dc337c45c7d9d171a9f86d0c7650ac7e65d60995691d2/bracex-2.1.1.tar.gz"
|
|
sha256 "01f715cd0ed7a622ec8b32322e715813f7574de531f09b70f6f3b2c10f682425"
|
|
end
|
|
|
|
resource "certifi" do
|
|
url "https://files.pythonhosted.org/packages/6d/78/f8db8d57f520a54f0b8a438319c342c61c22759d8f9a1cd2e2180b5e5ea9/certifi-2021.5.30.tar.gz"
|
|
sha256 "2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee"
|
|
end
|
|
|
|
resource "charset-normalizer" do
|
|
url "https://files.pythonhosted.org/packages/eb/7f/a6c278746ddbd7094b019b08d1b2187101b1f596f35f81dc27f57d8fcf7c/charset-normalizer-2.0.6.tar.gz"
|
|
sha256 "5ec46d183433dcbd0ab716f2d7f29d8dee50505b3fdb40c6b985c7c4f5a3591f"
|
|
end
|
|
|
|
resource "click" do
|
|
url "https://files.pythonhosted.org/packages/21/83/308a74ca1104fe1e3197d31693a7a2db67c2d4e668f20f43a2fca491f9f7/click-8.0.1.tar.gz"
|
|
sha256 "8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"
|
|
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/cb/38/4c4d00ddfa48abe616d7e572e02a04273603db446975ab46bbcd36552005/idna-3.2.tar.gz"
|
|
sha256 "467fbad99067910785144ce333826c71fb0e63a425657295239737f7ecd125f3"
|
|
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
|