121 lines
3.4 KiB
Ruby
121 lines
3.4 KiB
Ruby
class Infer < Formula
|
|
desc "Static analyzer for Java, C and Objective-C"
|
|
homepage "http://fbinfer.com/"
|
|
url "https://github.com/facebook/infer/releases/download/v0.9.4.1/infer-osx-v0.9.4.1.tar.xz"
|
|
sha256 "a738a3492a4e0229df8abd745cd88bca8fb547bc3bcca15ec194d6780b07cbda"
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "deefb4714b5bb9b95e80a2d516ed2af0ce162815b55b07a2e306ff56eb46526c" => :sierra
|
|
sha256 "d17c0540c9fb57b0c79f1d4a9d01e37821be73aec3afa946add2567bfce9f2b7" => :el_capitan
|
|
sha256 "aa7fb2d1a2f8de4321aed0bc9d5bf0f50f851401d7e3e8bbb9d9638d3001d8c9" => :yosemite
|
|
end
|
|
|
|
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 "ocaml" => :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/"opamroot"
|
|
opamroot.mkpath
|
|
ENV["OPAMROOT"] = opamroot
|
|
ENV["OPAMYES"] = "1"
|
|
|
|
# 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
|
|
|
|
ENV["INFER_CONFIGURE_OPTS"] = "--prefix=#{prefix} --disable-ocaml-annot --disable-ocaml-binannot"
|
|
|
|
target_platform = if build.without?("clang")
|
|
"java"
|
|
elsif build.without?("java")
|
|
"clang"
|
|
else
|
|
"all"
|
|
end
|
|
|
|
system "opam", "init", "--no-setup"
|
|
ocaml_version = File.read("build-infer.sh").match(/OCAML_VERSION=\"([0-9\.]+)\"/)[1]
|
|
inreplace "#{opamroot}/compilers/#{ocaml_version}/#{ocaml_version}/#{ocaml_version}.comp",
|
|
'["./configure"', '["./configure" "-no-graph"'
|
|
system "./build-infer.sh", target_platform, "--yes"
|
|
system "opam", "config", "exec", "--switch=infer-#{ocaml_version}", "--", "make", "install"
|
|
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
|