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: "v1.10.0", revision: "5e380e31c93c7dee0b5d32d4cc123ff35d0a65d2" 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_ventura: "cb8dba27380bcc27e98ab6c3c9144e776d3d10a7f942e2e6be87be660f8c1c54" sha256 cellar: :any, arm64_monterey: "7122bba14a9cdde83cfc1192d9694b3d99721ef53f1a3daffc2abb0422ceba33" sha256 cellar: :any, arm64_big_sur: "e47dda4a5838ca91d37c06736902f8049e13a4b93469f8cd2b0c31170d78b9ce" sha256 cellar: :any, ventura: "3efafb5185cb8e3c86457905ebfad104e8a00c8877c2407b91f79e8bd9dc19f1" sha256 cellar: :any, monterey: "8e3a7012f42d95342856465eb21815e3cf7c2a95159ab20f9d5cc0f7d04356f1" sha256 cellar: :any, big_sur: "5db1c2eb0c0a9d4c0eae2bd02e01c422e89281eb80ab0b05d4da99769089e379" sha256 x86_64_linux: "cb25de5abeb2f65b1defe6919a7cd14aeaf3a0dd8e65b2e6a23d5511c4df3b6c" 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-typing-extensions" depends_on "python@3.11" depends_on "tree-sitter" uses_from_macos "rsync" => :build fails_with gcc: "5" resource "attrs" do url "https://files.pythonhosted.org/packages/21/31/3f468da74c7de4fcf9b25591e682856389b3400b4b62f201e65f15ea3e07/attrs-22.2.0.tar.gz" sha256 "c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99" 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/37/f7/2b1b0ec44fdc30a3d31dfebe52226be9ddc40cd6c0f34ffc8923ba423b69/certifi-2022.12.7.tar.gz" sha256 "35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3" end resource "charset-normalizer" do url "https://files.pythonhosted.org/packages/96/d7/1675d9089a1f4677df5eb29c3f8b064aa1e70c1251a0a8a127803158942d/charset-normalizer-3.0.1.tar.gz" sha256 "ebea339af930f8ca5d7a699b921106c6e29c617fe9606fa7baa043c1cdae326f" 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/4c/29/ff7cd69825b5bfb48e39853b75d5dc2e98a581730f2b6c9c014188730755/click-option-group-0.5.5.tar.gz" sha256 "78ee474f07a0ca0ef6c0317bb3ebe79387aafb0c4a1e03b1d8b2b0be1e42fc78" end resource "colorama" do url "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz" sha256 "08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44" 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/d7/bc/4d0f6c1e095eb977782edd94245f84b69c6f8df152480c78ab310e895098/face-22.0.0.tar.gz" sha256 "d5d692f90bc8f5987b636e47e36384b9bbda499aaf0a77aa0b0bbe834c76923d" 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/8b/e1/43beb3d38dba6cb420cefa297822eac205a277ab43e5ba5d5c46faf96438/idna-3.4.tar.gz" sha256 "814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4" end resource "jsonschema" do url "https://files.pythonhosted.org/packages/36/3d/ca032d5ac064dff543aa13c984737795ac81abc9fb130cd2fcff17cfabc7/jsonschema-4.17.3.tar.gz" sha256 "0f864437ab8b6076ba6707453ef8f98a6a0d512a80e93f8abdb676f737ecb60d" end resource "markdown-it-py" do url "https://files.pythonhosted.org/packages/33/e9/ac8a93e9eda3891ecdfecf5e01c060bbd2c44d4e3e77efc83b9c7ce9db32/markdown-it-py-2.1.0.tar.gz" sha256 "cf7e59fed14b5ae17c0006eff14a2d9a00ed5f3a846148153899a0224e2c07da" end resource "mdurl" do url "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz" sha256 "bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" end resource "packaging" do url "https://files.pythonhosted.org/packages/47/d5/aca8ff6f49aa5565df1c826e7bf5e85a6df852ee063600c1efa5b932968c/packaging-23.0.tar.gz" sha256 "b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97" end resource "peewee" do url "https://files.pythonhosted.org/packages/17/c8/8035f2155832580d786c35cb1ce0a89d80a67be522f620878fc294742905/peewee-3.15.4.tar.gz" sha256 "2581520c8dfbacd9d580c2719ae259f0637a9e46eda47dfc0ce01864c6366205" end resource "Pygments" do url "https://files.pythonhosted.org/packages/da/6a/c427c06913204e24de28de5300d3f0e809933f376e0b7df95194b2bb3f71/Pygments-2.14.0.tar.gz" sha256 "b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297" end resource "pyrsistent" do url "https://files.pythonhosted.org/packages/bf/90/445a7dbd275c654c268f47fa9452152709134f61f09605cf776407055a89/pyrsistent-0.19.3.tar.gz" sha256 "1a2994773706bbb4995c31a97bc94f1418314923bd1048c6d964837040376440" 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/9d/ee/391076f5937f0a8cdf5e53b701ffc91753e87b07d66bae4a09aa671897bf/requests-2.28.2.tar.gz" sha256 "98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf" end resource "rich" do url "https://files.pythonhosted.org/packages/68/31/b8934896818c885001aeb7df388ba0523ea3ec88ad31805983d9b0480a50/rich-13.3.1.tar.gz" sha256 "125d96d20c92b946b983d0d392b84ff945461e5a06d3867e9f9e575f8697b67f" 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 "tomli" do url "https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz" sha256 "de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" end resource "tqdm" do url "https://files.pythonhosted.org/packages/c1/c2/d8a40e5363fb01806870e444fc1d066282743292ff32a9da54af51ce36a2/tqdm-4.64.1.tar.gz" sha256 "5f4f682a004951c1b450bc753c710e9280c5746ce6ffedee253ddbcbf54cf1e4" end resource "ujson" do url "https://files.pythonhosted.org/packages/43/1a/b0a027144aa5c8f4ea654f4afdd634578b450807bb70b9f8bad00d6f6d3c/ujson-5.7.0.tar.gz" sha256 "e788e5d5dcae8f6118ac9b45d0b891a0d55f7ac480eddcb7f07263f2bcf37b23" end resource "urllib3" do url "https://files.pythonhosted.org/packages/c5/52/fe421fb7364aa738b3506a2d99e4f3a56e079c0a798e9f4fa5e14c60922f/urllib3-1.26.14.tar.gz" sha256 "076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72" end resource "wcmatch" do url "https://files.pythonhosted.org/packages/b7/94/5dd083fc972655f6689587c3af705aabc8b8e781bacdf22d6d2282fe6142/wcmatch-8.4.1.tar.gz" sha256 "b1f042a899ea4c458b7321da1b5e3331e3e0ec781583434de1301946ceadb943" 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/ 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 system "opam", "install", "-y", "--deps-only", "--no-depexts", "./libs/ocaml-tree-sitter-core" system "opam", "install", "-y", "--deps-only", "--no-depexts", "./" # Run configure script in ocaml-tree-sitter-core cd "./libs/ocaml-tree-sitter-core" do system "./configure" end # Install semgrep-core and spacegrep system "opam", "install", "--deps-only", "-y", "." system "opam", "exec", "--", "make", "core" system "opam", "exec", "--", "make", "core-install" bin.install "_build/install/default/bin/semgrep-core" => "semgrep-core" bin.install "_build/install/default/bin/spacegrep" => "spacegrep" end ENV["SEMGREP_SKIP_BIN"] = "1" python_path = "cli" cd python_path do venv = virtualenv_create(libexec, Formula["python@3.11"].bin/"python3.11") 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