Skip to content
This repository has been archived by the owner on Jun 22, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed Oct 15, 2015
2 parents d4d5493 + 3778e19 commit fbe6d3a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
sudo: false
language: objective-c
os: osx
matrix:
include:
- 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
- brew tap --repair
- gem install rubocop
- gem install rubocop --no-document
script:
- rubocop --config=$(brew --repo)/Library/.rubocop.yml iwyu.rb
- brew audit iwyu
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
73 changes: 55 additions & 18 deletions iwyu.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,47 +18,84 @@ 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"
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

def install
clang_libs = "#{MacOS::Xcode.toolchain_path}/usr/lib/clang/6.1.0"
iwyu_clang_path = (lib / "clang")
# 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

iwyu_clang_path.mkpath
iwyu_clang_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0")
clang_version = `clang --version`.each_line.first
apple_llvm_version = clang_version[/\AApple LLVM version (\d+(?:\.\d+)+)/, 1]

bin.install("fix_includes.py" => "fix_include")
bin.install("include-what-you-use")
bin.install_symlink("include-what-you-use" => "iwyu")
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")
iwyu_libdir = (iwyu_subdir_path / "lib")
iwyu_includes = (iwyu_subdir_path / "include")

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_symlink Dir["#{iwyu_bindir}/*"]
end

test do
# write out a header and a C file relying on transitive dependencies
(testpath / "demo.h").write("#include <stdio.h>")
(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 <stdio.h>
#include <stdarg.h>
#include <locale>
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
This package will break after an Xcode upgrade. Fixing it is as simple as:
brew reinstall iwyu
EOS
end
end

0 comments on commit fbe6d3a

Please sign in to comment.