From 3075dd27f625155fd25963f08d5ac2dda0fe86dd Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 16:24:34 -0600 Subject: [PATCH 01/12] Remove hardcoded Xcode version By doing this we can support Xcode 6.1 or 7.0 with a single codebase. --- iwyu.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iwyu.rb b/iwyu.rb index 372e4b0..c9a7061 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -29,7 +29,9 @@ class Iwyu < Formula depends_on Xcode61 def install - clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/6.1.0" + xcode_maj_min_version = MacOS::Xcode.version[/\A\d+\.\d+/, 0] + clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/" \ + "#{xcode_maj_min_version}.0" iwyu_clang_path = (lib / "clang") iwyu_clang_path.mkpath From 9dd508c79f3fe75afd1f736bf800c6e61a653319 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 16:32:10 -0600 Subject: [PATCH 02/12] Programmatically link latest Xcode clang headers Since 6.1 they're in a directory named with Xcode's minor-major version so detecting that (6.1 or 7.0 at the moment) is enough to remove direct references to an Xcode version in paths. This will still break across Xcode upgrades, but `brew reinstall iwyu` will fix that instantly. --- iwyu.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iwyu.rb b/iwyu.rb index c9a7061..72dfd46 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -63,4 +63,10 @@ def install # sigh. they use the status code to signal how many files were edited assert_equal 1, $CHILD_STATUS.exitstatus end + + def caveats; <<-EOS.undent + This package will break after an Xcode upgrade. Fixing it is as simple as: + brew reinstall iwyu + EOS + end end From 8a4fd13f92440f20e8d568a344cae8778ca91242 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 16:33:57 -0600 Subject: [PATCH 03/12] Add sha256 checksum Homebrew's been requiring this for a while. Pretty obvious why now. --- iwyu.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iwyu.rb b/iwyu.rb index 72dfd46..0ad3fa9 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -24,7 +24,7 @@ class Iwyu < Formula homepage "http://include-what-you-use.org" url "http://include-what-you-use.org/downloads/" \ "include-what-you-use-#{version}-x86_64-apple-darwin.tar.gz" - sha1 "616cc2cd39d068896a94a40fb761e135e64db840" + sha256 "41d7434545cb0c55acd9db0b1b66058ffbe88f3c3b79df4e3f649d54aabbbc7b" depends_on Xcode61 From 1296f7e01f3851cfc9f2395f3c7c6c102f1d0ac9 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 16:51:00 -0600 Subject: [PATCH 04/12] Add matrix build for multiple Xcode versions Also turn off ri/rdoc generation for speed. --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4f25e5c..b0b20ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,16 @@ sudo: false language: objective-c +osx_image: + - beta-xcode6.3 + - xcode6.4 + - xcode7 before_install: - brew update install: - mkdir -p $(brew --repo)/Library/Taps/travis - ln -s $PWD $(brew --repo)/Library/Taps/travis/homebrew-testtap - brew tap --repair - - gem install rubocop + - gem install rubocop --no-document script: - rubocop --config=$(brew --repo)/Library/.rubocop.yml iwyu.rb - brew audit iwyu From b9ee419f7a6e79c3bc8440942f8347388b721a08 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 17:02:26 -0600 Subject: [PATCH 05/12] Try again Not sure this is matrix-able. --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0b20ac..1c36623 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ sudo: false language: objective-c -osx_image: - - beta-xcode6.3 - - xcode6.4 - - xcode7 +os: osx +matrix: + include: + - osx_image: xcode6.4 + - osx_image: xcode7 before_install: - brew update install: From beec8469a7271014da8eded51c03f7c8809645b1 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 17:11:11 -0600 Subject: [PATCH 06/12] Work around annoying Homebrew bug Something like this was probably bound to happen eventually. See Homebrew/homebrew#42553. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1c36623..90e2495 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ matrix: - osx_image: xcode6.4 - osx_image: xcode7 before_install: - - brew update + - brew update; brew update install: - mkdir -p $(brew --repo)/Library/Taps/travis - ln -s $PWD $(brew --repo)/Library/Taps/travis/homebrew-testtap From f4a675b656853411f75a97b5bee52660cf177348 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 17:21:58 -0600 Subject: [PATCH 07/12] Fix comment about LLVM 3.6 Xcode 6.1 comes with a clang based on LLVM 3.5svn. --- iwyu.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iwyu.rb b/iwyu.rb index 0ad3fa9..cf1d2d6 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -1,7 +1,7 @@ require "English" require "formula" -# include-what-you-use needs access to headers included with LLVM 3.6, which +# include-what-you-use needs access to headers included with LLVM 3.5, which # is only present in Xcode version 6.1 or higher. class Xcode61 < Requirement fatal true @@ -18,6 +18,7 @@ def message # build and install include-what-you-use, symlink it as iwyu, and install a # Python wrapper to automatically correct includes (fix_include). class Iwyu < Formula + # iwyu 0.4 based on clang 3.6 CLANG_VERSION = "3.6" version "0.4" From c5a0344c51d926ec30c9a6e3ca359ebcc3bdff5c Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 11 Aug 2015 11:22:47 -0700 Subject: [PATCH 08/12] Symlink include files so C++ header files are found --- iwyu.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iwyu.rb b/iwyu.rb index cf1d2d6..7b0ba83 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -38,6 +38,10 @@ def install iwyu_clang_path.mkpath iwyu_clang_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0") + # Include C++ headers so iwyu can find them (via Clang's relative lookup) + cpp_includes = "#{MacOS::Xcode.toolchain_path}/usr/include/c++" + include.install_symlink(cpp_includes => "c++") + bin.install("fix_includes.py" => "fix_include") bin.install("include-what-you-use") bin.install_symlink("include-what-you-use" => "iwyu") From e283aeeee17105142edc35657d0f95238eb03aee Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 17:32:48 -0600 Subject: [PATCH 09/12] Update test to require Xcode headers This'll detect when we break on including builtin headers (`stdarg`) or C++ ones (`locale`). --- iwyu.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/iwyu.rb b/iwyu.rb index 7b0ba83..dee19bd 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -38,7 +38,6 @@ def install iwyu_clang_path.mkpath iwyu_clang_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0") - # Include C++ headers so iwyu can find them (via Clang's relative lookup) cpp_includes = "#{MacOS::Xcode.toolchain_path}/usr/include/c++" include.install_symlink(cpp_includes => "c++") @@ -48,25 +47,30 @@ def install end test do - # write out a header and a C file relying on transitive dependencies - (testpath / "demo.h").write("#include ") - (testpath / "demo.c").write <<-EOS.undent - #include "demo.h" + # write out a header and a C++ file relying on transitive dependencies + (testpath / "demo.hpp").write <<-EOS.undent + #include + #include + #include + EOS + + (testpath / "demo.cpp").write <<-EOS.undent + #include "demo.hpp" int main(void) { printf("hello world"); } EOS # iwyu exits with a code equal to the number of suggested edits + 2 - fixes = shell_output "iwyu #{testpath}/demo.c 2>&1", 4 + fixes = shell_output "iwyu #{testpath}/demo.cpp 2>&1", 6 + assert_not_match(/file not found/, fixes) - # pass the output to the fixer script and assert that it fixed one file + # pass the output to the fixer script and assert that it fixed two files results = pipe_output "fix_include", fixes - - assert_match(/IWYU edited 1 file/, results) + assert_match(/IWYU edited 2 files/, results) # sigh. they use the status code to signal how many files were edited - assert_equal 1, $CHILD_STATUS.exitstatus + assert_equal 2, $CHILD_STATUS.exitstatus end def caveats; <<-EOS.undent From 8a87afb3ae00f11f2ef8ab8b7f9badcc4c264764 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 22:37:06 -0600 Subject: [PATCH 10/12] Trying something new Moved _all_ iwyu files into a special subdirectory, since leaving them in the typical `include` and `lib` directories ends up with those files being linked in folders in `/usr/local`. Since iwyu is what needs these files (they're not meant to be external), that doesn't make sense, and in fact can interfere with other packages. The binaries are really all that's necessary, so symlinks are made to them after everything else is in its place (the actual binaries must still be in the right place relative to the lib and include dirs, so there's a bin directory inside the special one in addition to a typical bin directory at the root of the package directory). --- iwyu.rb | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/iwyu.rb b/iwyu.rb index dee19bd..2c70177 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -30,20 +30,39 @@ class Iwyu < Formula depends_on Xcode61 def install + # include-what-you-use needs lib and include directories one level + # up from its bindir, but putting them in the homebrew directories + # results in them getting linked in /usr (interfering with e.g. the + # /usr/local/include dirs added by gcc). + # + # To solve this, we put iwyu in a custom dir and make bin links. + iwyu_subdir_path = (prefix / "iwyu") + iwyu_subdir_path.mkpath + xcode_maj_min_version = MacOS::Xcode.version[/\A\d+\.\d+/, 0] clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/" \ "#{xcode_maj_min_version}.0" - iwyu_clang_path = (lib / "clang") + cpp_includes = "#{MacOS::Xcode.toolchain_path}/usr/include/c++" - iwyu_clang_path.mkpath - iwyu_clang_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0") + iwyu_bindir = (iwyu_subdir_path / "bin") + iwyu_libdir = (iwyu_subdir_path / "lib") + iwyu_includes = (iwyu_subdir_path / "include") - cpp_includes = "#{MacOS::Xcode.toolchain_path}/usr/include/c++" - include.install_symlink(cpp_includes => "c++") + iwyu_bindir.mkpath + iwyu_libdir.mkpath + iwyu_includes.mkpath + + iwyu_clang_lib_path = (iwyu_libdir / "clang") + iwyu_clang_lib_path.mkpath + iwyu_clang_lib_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0") + + iwyu_includes.install_symlink(cpp_includes => "c++") + + iwyu_bindir.install("fix_includes.py" => "fix_include") + iwyu_bindir.install("include-what-you-use") + iwyu_bindir.install_symlink("include-what-you-use" => "iwyu") - bin.install("fix_includes.py" => "fix_include") - bin.install("include-what-you-use") - bin.install_symlink("include-what-you-use" => "iwyu") + bin.install_symlink Dir["#{iwyu_bindir}/*"] end test do From 7ad8f811637186526037eadd64e868b9cec6029e Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 14 Oct 2015 23:07:43 -0600 Subject: [PATCH 11/12] Use canonical source of clang version Hacking it together from the Xcode version isn't good enough. --- iwyu.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iwyu.rb b/iwyu.rb index 2c70177..d05f27d 100644 --- a/iwyu.rb +++ b/iwyu.rb @@ -39,9 +39,10 @@ def install iwyu_subdir_path = (prefix / "iwyu") iwyu_subdir_path.mkpath - xcode_maj_min_version = MacOS::Xcode.version[/\A\d+\.\d+/, 0] - clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/" \ - "#{xcode_maj_min_version}.0" + clang_version = `clang --version`.each_line.first + apple_llvm_version = clang_version[/\AApple LLVM version (\d+(?:\.\d+)+)/, 1] + + clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/#{apple_llvm_version}" cpp_includes = "#{MacOS::Xcode.toolchain_path}/usr/include/c++" iwyu_bindir = (iwyu_subdir_path / "bin") From 3778e198e3d4acf15e044b3d387f03bbc48384d7 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Thu, 15 Oct 2015 00:02:58 -0600 Subject: [PATCH 12/12] Update CHANGELOG --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64aefc7..ce800bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +### homebrew-iwyu v2.1.0 (October 15, 2015) ### + +* Supports Xcode 6.1 or higher, including 7.0 + +* Determines Xcode version at build time + +* Adds support for C++ builtin headers + +* No longer pollutes system include dirs + +* Builds against multiple Xcode versions in Travis + +* Adds stronger unit tests (fewer false positives) + ### homebrew-iwyu v2.0.0 (June 28, 2015) ### * Installs include-what-you-use 0.4