133 lines
3.8 KiB
Ruby
133 lines
3.8 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.12.0/infer-osx-v0.12.0.tar.xz"
|
|
sha256 "3b97bcabf85af8feb8d6fd0b8622fe2b4fbf27fa215fab61e3a660b5435b6d21"
|
|
revision 1
|
|
|
|
bottle do
|
|
cellar :any
|
|
rebuild 1
|
|
sha256 "29f441fe6fa66bcad880056dc078a6a5aa4d5cb58341e90a75324c5beacb64f7" => :sierra
|
|
sha256 "09c4a260609ee8d6f958557026c4aefe686a89a08dfec1e74c9d2c99d318129b" => :el_capitan
|
|
sha256 "ebd4e93fcddbbd410849274d56324610e0f303ed7084594e5aab89741851e2f7" => :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
|
|
depends_on "pkg-config" => :build
|
|
|
|
def install
|
|
# Remove for > 0.12.0
|
|
# Fix conflicting version constraints:
|
|
# ppx_deriving -> cppo_ocamlbuild -> cppo >= 1.6.0
|
|
# ppx_deriving -> cppo_ocamlbuild -> jbuilder >= 1.0+beta10
|
|
inreplace "opam.lock" do |s|
|
|
s.gsub! /^cppo = 1\.4\.1$/, "cppo = 1.6.0"
|
|
s.gsub! /^jbuilder = 1\.0\+beta6$/, "jbuilder = 1.0+beta12"
|
|
end
|
|
|
|
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-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-issue -- clang -c FailingTest.c", 2)
|
|
shell_output("#{bin}/infer --fail-on-issue -- clang -c 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-issue -- javac FailingTest.java", 2)
|
|
shell_output("#{bin}/infer --fail-on-issue -- javac PassingTest.java", 0)
|
|
end
|
|
end
|