homebrew-core/Formula/stp.rb

86 lines
3.0 KiB
Ruby

class Stp < Formula
desc "Simple Theorem Prover, an efficient SMT solver for bitvectors"
homepage "https://stp.github.io/"
url "https://github.com/stp/stp/archive/refs/tags/2.3.3.tar.gz"
sha256 "ea6115c0fc11312c797a4b7c4db8734afcfce4908d078f386616189e01b4fffa"
license "MIT"
revision 2
head "https://github.com/stp/stp.git", branch: "master"
livecheck do
url :stable
regex(/^(?:stp[._-])?v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "9977ca306c92733f555e00073bdcba9540bc16ca8e50666cc18edd24bfaf91b9"
sha256 cellar: :any, arm64_big_sur: "c122410909f90ffa162108e95a69e6abe7eb09ce8da980afc29ad1634cf8259d"
sha256 cellar: :any, monterey: "50f40a71a6731f69a564d275580f56669b3b1e24dd578754a45f22b246471702"
sha256 cellar: :any, big_sur: "8b9d797c603a6ed43db27320a55a2fa2774d580ec9673250d2167f6b3c9634c7"
sha256 cellar: :any, catalina: "2473aedddcd7136e749d023fb018ae7e2e97760594c7db20dd0fa8ee10ff6e26"
sha256 cellar: :any_skip_relocation, x86_64_linux: "50ac49e6c6b56137bec4f62975fe1717f8a211949b2359d681288151aeeb3d3b"
end
# stp refuses to build with system bison and flex
depends_on "bison" => :build
depends_on "cmake" => :build
depends_on "flex" => :build
depends_on "boost"
depends_on "cryptominisat"
depends_on "minisat"
depends_on "python@3.10"
uses_from_macos "perl"
def install
site_packages = prefix/Language::Python.site_packages("python3")
site_packages.mkpath
inreplace "lib/Util/GitSHA1.cpp.in", "@CMAKE_CXX_COMPILER@", ENV.cxx
system "cmake", "-S", ".", "-B", "build",
"-DPYTHON_EXECUTABLE=#{Formula["python@3.10"].opt_bin}/python3",
"-DPYTHON_LIB_INSTALL_DIR=#{site_packages}",
*std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
test do
(testpath/"prob.smt").write <<~EOS
(set-logic QF_BV)
(assert (= (bvsdiv (_ bv3 2) (_ bv2 2)) (_ bv0 2)))
(check-sat)
(exit)
EOS
assert_equal "sat", shell_output("#{bin}/stp --SMTLIB2 prob.smt").chomp
(testpath/"test.c").write <<~EOS
#include "stp/c_interface.h"
#include <assert.h>
int main() {
VC vc = vc_createValidityChecker();
Expr c = vc_varExpr(vc, "c", vc_bvType(vc, 32));
Expr a = vc_bvConstExprFromInt(vc, 32, 5);
Expr b = vc_bvConstExprFromInt(vc, 32, 6);
Expr xp1 = vc_bvPlusExpr(vc, 32, a, b);
Expr eq = vc_eqExpr(vc, xp1, c);
Expr eq2 = vc_notExpr(vc, eq);
int ret = vc_query(vc, eq2);
assert(ret == false);
vc_printCounterExample(vc);
vc_Destroy(vc);
return 0;
}
EOS
expected_output = <<~EOS
COUNTEREXAMPLE BEGIN:\s
ASSERT( c = 0x0000000B );
COUNTEREXAMPLE END:\s
EOS
system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lstp", "-o", "test"
assert_equal expected_output.chomp, shell_output("./test").chomp
end
end