2015-12-10 23:54:35 +00:00
|
|
|
class Infer < Formula
|
|
|
|
desc "Static analyzer for Java, C and Objective-C"
|
|
|
|
homepage "http://fbinfer.com/"
|
2016-08-18 13:15:20 +00:00
|
|
|
url "https://github.com/facebook/infer/releases/download/v0.9.2/infer-osx-v0.9.2.tar.xz"
|
|
|
|
sha256 "3935f8be25982a023aba306b66804d73a7316ab833296277c1ec6c3694bfc7c7"
|
2015-12-10 23:54:35 +00:00
|
|
|
|
2016-01-09 18:26:36 +00:00
|
|
|
bottle do
|
|
|
|
cellar :any
|
2016-08-24 12:21:22 +00:00
|
|
|
sha256 "2b1dd1bdebf2550f01ad9c6d5e6ee463f24b740e28ece126787f2f08b2276818" => :el_capitan
|
|
|
|
sha256 "d65405a47ead42e33e751f33ba4766e90005ea0b59f7aeadf860828bfcf4a3ff" => :yosemite
|
|
|
|
sha256 "7ce4996fd1da93d8f325c3abb2bc6804fd5af12d09953f67f643fca5c6dc889e" => :mavericks
|
2016-01-09 18:26:36 +00:00
|
|
|
end
|
|
|
|
|
2015-12-10 23:54:35 +00:00
|
|
|
option "without-clang", "Build without C/Objective-C analyzer"
|
|
|
|
option "without-java", "Build without Java analyzer"
|
|
|
|
|
|
|
|
depends_on "autoconf" => :build
|
|
|
|
depends_on "automake" => :build
|
|
|
|
depends_on "libtool" => :build
|
|
|
|
depends_on "opam" => :build
|
|
|
|
|
|
|
|
def install
|
|
|
|
if build.without?("clang") && build.without?("java")
|
|
|
|
odie "infer: --without-clang and --without-java are mutually exclusive"
|
|
|
|
end
|
|
|
|
|
|
|
|
opamroot = buildpath/"build"
|
|
|
|
opamroot.mkpath
|
|
|
|
ENV["OPAMROOT"] = opamroot
|
|
|
|
ENV["OPAMYES"] = "1"
|
|
|
|
|
2016-08-18 13:15:20 +00:00
|
|
|
# Some of the libraries installed by ./build-infer.sh do not
|
|
|
|
# support parallel builds, eg OCaml itself. ./build-infer.sh
|
|
|
|
# builds in its own parallelization logic to mitigate that.
|
|
|
|
ENV.deparallelize
|
2015-12-10 23:54:35 +00:00
|
|
|
|
2016-08-18 13:15:20 +00:00
|
|
|
ENV["INFER_CONFIGURE_OPTS"] = "--prefix=#{prefix} --disable-ocaml-annot --disable-ocaml-binannot"
|
2015-12-10 23:54:35 +00:00
|
|
|
|
|
|
|
target_platform = if build.without?("clang")
|
|
|
|
"java"
|
|
|
|
elsif build.without?("java")
|
|
|
|
"clang"
|
|
|
|
else
|
|
|
|
"all"
|
|
|
|
end
|
|
|
|
|
2016-08-18 13:15:20 +00:00
|
|
|
system "./build-infer.sh", target_platform, "--yes"
|
|
|
|
system "opam", "config", "exec", "--switch=infer-4.02.3", "--", "make", "install"
|
2015-12-10 23:54:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test do
|
|
|
|
(testpath/"FailingTest.c").write <<-EOS.undent
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int *s = NULL;
|
|
|
|
*s = 42;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"PassingTest.c").write <<-EOS.undent
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int *s = NULL;
|
|
|
|
if (s != NULL) {
|
|
|
|
*s = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
shell_output("#{bin}/infer --fail-on-bug -- clang FailingTest.c", 2)
|
|
|
|
shell_output("#{bin}/infer --fail-on-bug -- clang PassingTest.c", 0)
|
|
|
|
|
|
|
|
(testpath/"FailingTest.java").write <<-EOS.undent
|
|
|
|
class FailingTest {
|
|
|
|
|
|
|
|
String mayReturnNull(int i) {
|
|
|
|
if (i > 0) {
|
|
|
|
return "Hello, Infer!";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mayCauseNPE() {
|
|
|
|
String s = mayReturnNull(0);
|
|
|
|
return s.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"PassingTest.java").write <<-EOS.undent
|
|
|
|
class PassingTest {
|
|
|
|
|
|
|
|
String mayReturnNull(int i) {
|
|
|
|
if (i > 0) {
|
|
|
|
return "Hello, Infer!";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mayCauseNPE() {
|
|
|
|
String s = mayReturnNull(0);
|
|
|
|
return s == null ? 0 : s.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
shell_output("#{bin}/infer --fail-on-bug -- javac FailingTest.java", 2)
|
|
|
|
shell_output("#{bin}/infer --fail-on-bug -- javac PassingTest.java", 0)
|
|
|
|
end
|
|
|
|
end
|