<commit_before>#  Copyright 2009 <NAME> <<EMAIL>>
#
#  This file is part of Homebrew.
#
#  Homebrew is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Homebrew is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Homebrew.  If not, see <http://www.gnu.org/licenses/>.

require 'env'

class BuildError <RuntimeError
  def initialize cmd
    super "Build failed during: #{cmd}"
  end
end

# the base class variety of formula, you don't get a prefix, so it's not really
# useful. See the derived classes for fun and games.
class AbstractFormula
  require 'find'
  require 'fileutils'

  # fuck knows, ruby is weird
  # TODO please fix!
  def self.url
    @url
  end
  def url
    self.class.url
  end
  def self.md5
    @md5
  end
  def md5
    self.class.md5
  end
  def self.homepage
    @homepage
  end
  def homepage
    self.class.homepage
  end  
  # end ruby is weird section

  def version
    @version
  end
  def name
    @name
  end

  # if the dir is there, but it's empty we consider it not installed
  def installed?
    return prefix.children.count > 0
  rescue
    return false
  end

  def initialize name=nil
    @name=name
    # fuck knows, ruby is weird
    @url=url if @url.nil?
    raise "@url.nil?" if @url.nil?
    @md5=md5 if @md5.nil?
    # end ruby is weird section
  end

public  
  def prefix
    raise "@name.nil!" if @name.nil?
    raise "@version.nil?" if @version.nil?
    $cellar+@name+@version
  end
  def bin
    prefix+'bin'
  end
  def doc
    prefix+'share'+'doc'+name
  end
  def man
    prefix+'share'+'man'
  end
  def man1
    man+'man1'
  end
  def lib
    prefix+'lib'
  end
  def include
    prefix+'include'
  end

  def caveats
    nil
  end
  
  # Pretty titles the command and buffers stdout/stderr
  # Throws if there's an error
  def system cmd
    ohai cmd
    if ARGV.include? '--verbose'
      Kernel.system cmd
    else
      out=''
      IO.popen "#{cmd} 2>&1" do |f|
        until f.eof?
          out+=f.gets
        end
      end
      puts out unless $? == 0
    end

    raise BuildError.new(cmd) unless $? == 0
  end

  # yields self with current working directory set to the uncompressed tarball
  def brew
    ohai "Downloading #{@url}"
    FileUtils.mkpath HOMEBREW_CACHE
    Dir.chdir HOMEBREW_CACHE do
      tmp=tgz=nil
      begin
        tgz=Pathname.new(fetch()).realpath
        md5=`md5 -q "#{tgz}"`.strip
        raise "MD5 mismatch: #{md5}" unless @md5 and md5 == @md5.downcase

        # we make an additional subdirectory so know exactly what we are
        # recursively deleting later
        # we use mktemp rather than appsupport/blah because some build scripts
        # can't handle being built in a directory with spaces in it :P
        tmp=`mktemp -dt #{File.basename @url}`.strip
        Dir.chdir tmp do
          Dir.chdir uncompress(tgz) do
            yield self
          end
        end
      rescue Interrupt, RuntimeError
        if ARGV.include? '--debug'<commit_msg>Don't allow build to be rescued if the untar fails<commit_after>#  Copyright 2009 <NAME> <<EMAIL>>
#
#  This file is part of Homebrew.
#
#  Homebrew is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Homebrew is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Homebrew.  If not, see <http://www.gnu.org/licenses/>.

require 'env'

class BuildError <RuntimeError
  def initialize cmd
    super "Build failed during: #{cmd}"
  end
end

# the base class variety of formula, you don't get a prefix, so it's not really
# useful. See the derived classes for fun and games.
class AbstractFormula
  require 'find'
  require 'fileutils'

  # fuck knows, ruby is weird
  # TODO please fix!
  def self.url
    @url
  end
  def url
    self.class.url
  end
  def self.md5
    @md5
  end
  def md5
    self.class.md5
  end
  def self.homepage
    @homepage
  end
  def homepage
    self.class.homepage
  end  
  # end ruby is weird section

  def version
    @version
  end
  def name
    @name
  end

  # if the dir is there, but it's empty we consider it not installed
  def installed?
    return prefix.children.count > 0
  rescue
    return false
  end

  def initialize name=nil
    @name=name
    # fuck knows, ruby is weird
    @url=url if @url.nil?
    raise "@url.nil?" if @url.nil?
    @md5=md5 if @md5.nil?
    # end ruby is weird section
  end

public  
  def prefix
    raise "@name.nil!" if @name.nil?
    raise "@version.nil?" if @version.nil?
    $cellar+@name+@version
  end
  def bin
    prefix+'bin'
  end
  def doc
    prefix+'share'+'doc'+name
  end
  def man
    prefix+'share'+'man'
  end
  def man1
    man+'man1'
  end
  def lib
    prefix+'lib'
  end
  def include
    prefix+'include'
  end

  def caveats
    nil
  end
  
  # Pretty titles the command and buffers stdout/stderr
  # Throws if there's an error
  def system cmd
    ohai cmd
    if ARGV.include? '--verbose'
      Kernel.system cmd
    else
      out=''
      IO.popen "#{cmd} 2>&1" do |f|
        until f.eof?
          out+=f.gets
        end
      end
      puts out unless $? == 0
    end

    raise BuildError.new(cmd) unless $? == 0
  end

  # yields self with current working directory set to the uncompressed tarball
  def brew
    ohai "Downloading #{@url}"
    FileUtils.mkpath HOMEBREW_CACHE
    Dir.chdir HOMEBREW_CACHE do
      tmp=nil
      tgz=Pathname.new(fetch()).realpath
      begin
        md5=`md5 -q "#{tgz}"`.strip
        raise "MD5 mismatch: #{md5}" unless @md5 and md5 == @md5.downcase

        # we make an additional subdirectory so know exactly what we are
        # recursively deleting later
        # we use mktemp rather than appsupport/blah because some build scripts
        # can't handle being built in a directory with spaces in it :P
        tmp=`mktemp -dt #{File.basename @url}`.strip
        Dir.chdir tmp do
          Dir.chdir uncompress(tgz) do
            yield self
          end
        end
      rescue Interrupt, RuntimeError
        if ARGV.include? '--debug'
{'fraction_non_alphanumeric': 0.07964989059080962, 'fraction_numerical': 0.0075857038657913935, 'mean_word_length': 2.4696356275303644, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 4, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256770', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2137, 'n_words': 850}