diff --git a/Formula/llvm@8.rb b/Formula/llvm@8.rb index 287b794a5554c..722f2f37e9f56 100644 --- a/Formula/llvm@8.rb +++ b/Formula/llvm@8.rb @@ -3,6 +3,7 @@ class LlvmAT8 < Formula homepage "https://llvm.org/" url "https://github.com/llvm/llvm-project/releases/download/llvmorg-8.0.1/llvm-8.0.1.src.tar.xz" sha256 "44787a6d02f7140f145e2250d56c9f849334e11f9ae379827510ed72f12b75e7" + revision 1 bottle do cellar :any @@ -113,6 +114,11 @@ def install -DLIBOMP_INSTALL_ALIASES=OFF ] + if MacOS.version >= :mojave + sdk_path = MacOS::CLT.installed? ? "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" : MacOS.sdk_path + args << "-DDEFAULT_SYSROOT=#{sdk_path}" + end + mkdir "build" do system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) system "make" @@ -144,7 +150,6 @@ def caveats; <<~EOS #include #include #include - int main() { #pragma omp parallel num_threads(4) { @@ -172,7 +177,6 @@ def caveats; <<~EOS (testpath/"test.c").write <<~EOS #include - int main() { printf("Hello World!\\n"); @@ -182,7 +186,6 @@ def caveats; <<~EOS (testpath/"test.cpp").write <<~EOS #include - int main() { std::cout << "Hello World!" << std::endl; @@ -190,52 +193,73 @@ def caveats; <<~EOS } EOS + # Testing default toolchain and SDK location. + system "#{bin}/clang++", "-v", + "-std=c++11", "test.cpp", "-o", "test++" + assert_includes MachO::Tools.dylibs("test++"), "/usr/lib/libc++.1.dylib" + assert_equal "Hello World!", shell_output("./test++").chomp + system "#{bin}/clang", "-v", "test.c", "-o", "test" + assert_equal "Hello World!", shell_output("./test").chomp + # Testing Command Line Tools if MacOS::CLT.installed? - libclangclt = Dir["/Library/Developer/CommandLineTools/usr/lib/clang/#{MacOS::CLT.version.to_i}*"].last { |f| File.directory? f } - - system "#{bin}/clang++", "-v", "-nostdinc", - "-I/Library/Developer/CommandLineTools/usr/include/c++/v1", - "-I#{libclangclt}/include", - "-I/usr/include", # need it because /Library/.../usr/include/c++/v1/iosfwd refers to , which CLT installs to /usr/include - "test.cpp", "-o", "testCLT++" + toolchain_path = "/Library/Developer/CommandLineTools" + sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" + system "#{bin}/clang++", "-v", + "-isysroot", sdk_path, + "-isystem", "#{toolchain_path}/usr/include/c++/v1", + "-isystem", "#{toolchain_path}/usr/include", + "-isystem", "#{sdk_path}/usr/include", + "-std=c++11", "test.cpp", "-o", "testCLT++" assert_includes MachO::Tools.dylibs("testCLT++"), "/usr/lib/libc++.1.dylib" assert_equal "Hello World!", shell_output("./testCLT++").chomp - - system "#{bin}/clang", "-v", "-nostdinc", - "-I/usr/include", # this is where CLT installs stdio.h - "test.c", "-o", "testCLT" + system "#{bin}/clang", "-v", "test.c", "-o", "testCLT" assert_equal "Hello World!", shell_output("./testCLT").chomp end # Testing Xcode if MacOS::Xcode.installed? - libclangxc = Dir["#{MacOS::Xcode.toolchain_path}/usr/lib/clang/#{DevelopmentTools.clang_version}*"].last { |f| File.directory? f } - - system "#{bin}/clang++", "-v", "-nostdinc", - "-I#{MacOS::Xcode.toolchain_path}/usr/include/c++/v1", - "-I#{libclangxc}/include", - "-I#{MacOS.sdk_path}/usr/include", - "test.cpp", "-o", "testXC++" + system "#{bin}/clang++", "-v", + "-isysroot", MacOS.sdk_path, + "-isystem", "#{MacOS::Xcode.toolchain_path}/usr/include/c++/v1", + "-isystem", "#{MacOS::Xcode.toolchain_path}/usr/include", + "-isystem", "#{MacOS.sdk_path}/usr/include", + "-std=c++11", "test.cpp", "-o", "testXC++" assert_includes MachO::Tools.dylibs("testXC++"), "/usr/lib/libc++.1.dylib" assert_equal "Hello World!", shell_output("./testXC++").chomp - - system "#{bin}/clang", "-v", "-nostdinc", - "-I#{MacOS.sdk_path}/usr/include", - "test.c", "-o", "testXC" + system "#{bin}/clang", "-v", + "-isysroot", MacOS.sdk_path, + "test.c", "-o", "testXC" assert_equal "Hello World!", shell_output("./testXC").chomp end # link against installed libc++ # related to https://github.com/Homebrew/legacy-homebrew/issues/47149 - system "#{bin}/clang++", "-v", "-nostdinc", - "-std=c++11", "-stdlib=libc++", - "-I#{MacOS::Xcode.toolchain_path}/usr/include/c++/v1", - "-I#{libclangxc}/include", - "-I#{MacOS.sdk_path}/usr/include", - "-L#{lib}", - "-Wl,-rpath,#{lib}", "test.cpp", "-o", "test" - assert_includes MachO::Tools.dylibs("test"), "#{opt_lib}/libc++.1.dylib" - assert_equal "Hello World!", shell_output("./test").chomp + system "#{bin}/clang++", "-v", + "-isystem", "#{opt_include}/c++/v1", + "-std=c++11", "-stdlib=libc++", "test.cpp", "-o", "testlibc++", + "-L#{opt_lib}", "-Wl,-rpath,#{opt_lib}" + assert_includes MachO::Tools.dylibs("testlibc++"), "#{opt_lib}/libc++.1.dylib" + assert_equal "Hello World!", shell_output("./testlibc++").chomp + + (testpath/"scanbuildtest.cpp").write <<~EOS + #include + int main() { + int *i = new int; + *i = 1; + delete i; + std::cout << *i << std::endl; + return 0; + } + EOS + assert_includes shell_output("#{bin}/scan-build --use-analyzer #{bin}/clang++ clang++ scanbuildtest.cpp 2>&1"), + "warning: Use of memory after it is freed" + + (testpath/"clangformattest.c").write <<~EOS + int main() { + printf("Hello world!"); } + EOS + assert_equal "int main() { printf(\"Hello world!\"); }\n", + shell_output("#{bin}/clang-format -style=google clangformattest.c") end end