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.107.0", revision: "f44a61db8359a8ec4fa265ec3dce3a157b08aff1" 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_monterey: "03d7837ee10c4cb49853029905026c25dedd9cad7c8f4cb39c87ef0048a1ab51" sha256 cellar: :any, arm64_big_sur: "74c6bfd37533538b16d323d488b4c489a25e316758e52c5180ee27bfcd4efa46" sha256 cellar: :any, monterey: "532971286a41f469ed56c0597735cc544cb9d16ef464a630697a5bb0df51ba9e" sha256 cellar: :any, big_sur: "458cfaa068101b7e648560e0dd6b5cf26b270c28bb9ecf5a2e84567dd222dc77" sha256 cellar: :any, catalina: "02fef83c45c7e71a956d854ad3dc7144971fb8e390cf51117e09e2b3ba2b50c1" sha256 x86_64_linux: "a31842f3fa8b8aa7b84179bc06d08dbfd90f2144cd51b87d80c836847c1eb196" end depends_on "cmake" => :build depends_on "coreutils"=> :build depends_on "dune" => :build depends_on "ocaml" => :build depends_on "opam" => :build depends_on "pipenv" => :build depends_on "pkg-config" => :build depends_on "pcre" depends_on "python@3.10" depends_on "tree-sitter" uses_from_macos "rsync" => :build on_linux do depends_on "gcc" end fails_with gcc: "5" resource "attrs" do url "https://files.pythonhosted.org/packages/d7/77/ebb15fc26d0f815839ecd897b919ed6d85c050feeb83e100e020df9153d2/attrs-21.4.0.tar.gz" sha256 "626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd" end resource "boltons" do url "https://files.pythonhosted.org/packages/ad/1f/6c0608d86e0fc77c982a2923ece80eef85f091f2332fc13cbce41d70d502/boltons-21.0.0.tar.gz" sha256 "65e70a79a731a7fe6e98592ecfb5ccf2115873d01dbc576079874629e5c90f13" end resource "bracex" do url "https://files.pythonhosted.org/packages/b3/96/d53e290ddf6215cfb24f93449a1835eff566f79a1f332cf046a978df0c9e/bracex-2.3.post1.tar.gz" sha256 "e7b23fc8b2cd06d3dec0692baabecb249dda94e06a617901ff03a6c56fd71693" end resource "certifi" do url "https://files.pythonhosted.org/packages/cc/85/319a8a684e8ac6d87a1193090e06b6bbb302717496380e225ee10487c888/certifi-2022.6.15.tar.gz" sha256 "84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d" end resource "charset-normalizer" do url "https://files.pythonhosted.org/packages/93/1d/d9392056df6670ae2a29fcb04cfa5cee9f6fbde7311a1bb511d4115e9b7a/charset-normalizer-2.1.0.tar.gz" sha256 "575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413" end resource "click" do url "https://files.pythonhosted.org/packages/59/87/84326af34517fca8c58418d148f2403df25303e02736832403587318e9e8/click-8.1.3.tar.gz" sha256 "7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e" 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/2b/65/24d033a9325ce42ccbfa3ca2d0866c7e89cc68e5b9d92ecaba9feef631df/colorama-0.4.5.tar.gz" sha256 "e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4" end resource "defusedxml" do url "https://files.pythonhosted.org/packages/0f/d5/c66da9b79e5bdb124974bfe172b4daf3c984ebd9c2a06e2b8a4dc7331c72/defusedxml-0.7.1.tar.gz" sha256 "1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69" end resource "face" do url "https://files.pythonhosted.org/packages/ae/ab/2b18c4815f3db1e04bce325271fefda55d0893738ea84e3a655218944b03/face-20.1.1.tar.gz" sha256 "7d59ca5ba341316e58cf72c6aff85cca2541cf5056c4af45cb63af9a814bed3e" end resource "glom" do url "https://files.pythonhosted.org/packages/3f/d1/69432deefa6f5283ec75b246d0540097ae26f618b915519ee3824c4c5dd6/glom-22.1.0.tar.gz" sha256 "1510c6587a8f9c64a246641b70033cbc5ebde99f02ad245693678038e821aeb5" 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/9d/c7/213df24d4dcf2eb115e2843205c6073c192976684388d6912cf674db2b8a/jsonschema-4.8.0.tar.gz" sha256 "c1d410e379b210ba903bee6adf3fce6d5204cea4c2b622d63f914d2dbfef0993" end resource "packaging" do url "https://files.pythonhosted.org/packages/df/9e/d1a7217f69310c1db8fdf8ab396229f55a699ce34a203691794c5d1cad0c/packaging-21.3.tar.gz" sha256 "dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb" end resource "peewee" do url "https://files.pythonhosted.org/packages/45/c4/be139f7b7e0bbbc7b2fba4dc492cfb0202c64a0086fa2d23c0b6091ef4f2/peewee-3.15.1.tar.gz" sha256 "6d5db3babc33819ac326f1550e5a39677f4584094c567a7b88cc6bf7bcdcb687" end resource "pyparsing" do url "https://files.pythonhosted.org/packages/71/22/207523d16464c40a0310d2d4d8926daffa00ac1f5b1576170a32db749636/pyparsing-3.0.9.tar.gz" sha256 "2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb" end resource "pyrsistent" do url "https://files.pythonhosted.org/packages/42/ac/455fdc7294acc4d4154b904e80d964cc9aae75b087bbf486be04df9f2abd/pyrsistent-0.18.1.tar.gz" sha256 "d4d61f8b993a7255ba714df3aca52700f8125289f84f704cf80916517c46eb96" end resource "python-lsp-jsonrpc" do url "https://files.pythonhosted.org/packages/99/45/1c2a272950679af529f7360af6ee567ef266f282e451be926329e8d50d84/python-lsp-jsonrpc-1.0.0.tar.gz" sha256 "7bec170733db628d3506ea3a5288ff76aa33c70215ed223abdb0d95e957660bd" end resource "requests" do url "https://files.pythonhosted.org/packages/a5/61/a867851fd5ab77277495a8709ddda0861b28163c4613b011bc00228cc724/requests-2.28.1.tar.gz" sha256 "7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983" end resource "ruamel.yaml" do url "https://files.pythonhosted.org/packages/46/a9/6ed24832095b692a8cecc323230ce2ec3480015fbfa4b79941bd41b23a3c/ruamel.yaml-0.17.21.tar.gz" sha256 "8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af" 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 "tqdm" do url "https://files.pythonhosted.org/packages/98/2a/838de32e09bd511cf69fe4ae13ffc748ac143449bfc24bb3fd172d53a84f/tqdm-4.64.0.tar.gz" sha256 "40be55d30e200777a307a7585aee69e4eabb46b4ec6a4b4a5f2d9f11e7d5408d" end resource "typing-extensions" do url "https://files.pythonhosted.org/packages/9e/1d/d128169ff58c501059330f1ad96ed62b79114a2eb30b8238af63a2e27f70/typing_extensions-4.3.0.tar.gz" sha256 "e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6" end resource "ujson" do url "https://files.pythonhosted.org/packages/fb/94/44fbbb059fe5d295f1f73e731a0b9c2e1b5073c2c6b58bb9c068715e9b72/ujson-5.4.0.tar.gz" sha256 "6b953e09441e307504130755e5bd6b15850178d591f66292bba4608c4f7f9b00" end resource "urllib3" do url "https://files.pythonhosted.org/packages/6d/d5/e8258b334c9eb8eb78e31be92ea0d5da83ddd9385dc967dd92737604d239/urllib3-1.26.11.tar.gz" sha256 "ea6e8fb210b19d950fab93b60c9009226c63a28808bc8386e05301e25883ac0a" end resource "wcmatch" do url "https://files.pythonhosted.org/packages/95/b3/597b79292584de5b790146871e50cf3cb3bf37cf845232a20123fc784ef2/wcmatch-8.4.tar.gz" sha256 "ba4fc5558f8946bf1ffc7034b05b814d825d694112499c86035e0e4d398b6a67" 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.14.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 = "cli" cd python_path do venv = virtualenv_create(libexec, Formula["python@3.10"].bin/"python3.10") 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