<commit_before>require "English"
require "formula"

# 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

  satisfy { MacOS::Xcode.version >= "6.1" }

  def message
    "Xcode 6.1 or newer is required for this package."
  end
end

# This formula provides an easy way to install include-what-you-use, a tool for
# automatically managing include directives within C and C++ projects. It will
# 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"
  sha256 "41d7434545cb0c55acd9db0b1b66058ffbe88f3c3b79df4e3f649d54aabbbc7b"

  depends_on Xcode61

  def install
    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
    iwyu_clang_path.install_symlink(clang_libs => "#{Iwyu::CLANG_VERSION}.0")

    bin.install("fix_includes.py" => "fix_include")
    bin.install("include-what-you-use")
    bin.install_symlink("include-what-you-use" => "iwyu")
  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<commit_msg>Symlink include files so C++ header files are found<commit_after>require "English"
require "formula"

# 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

  satisfy { MacOS::Xcode.version >= "6.1" }

  def message
    "Xcode 6.1 or newer is required for this package."
  end
end

# This formula provides an easy way to install include-what-you-use, a tool for
# automatically managing include directives within C and C++ projects. It will
# 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"
  sha256 "41d7434545cb0c55acd9db0b1b66058ffbe88f3c3b79df4e3f649d54aabbbc7b"

  depends_on Xcode61

  def install
    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
    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")
  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
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.03532008830022075, 'mean_word_length': 3.6834625322997416, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1279260', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1305, 'n_words': 317}