class Object

Constants

Arc
Bitmap
BitmapImage
Button
CLEANINGS
COMMON_HEADERS
COMMON_LIBS
COMPILE_C
COMPILE_CXX
COMPILE_RULES
CONFIG
CXX_EXT
C_EXT
Canvas
Checkbutton
ENV_JAVA

Equivalent to Java system properties. For example:

ENV_JAVA['java.version']
ENV_JAVA['java.class.version']
EXPORT_PREFIX
Entry
Font
Frame
Grid
LIBARG
LIBPATHFLAG
Label
Line
Listbox
MAIN_DOES_NOTHING
Message
ORIG_LIBPATH
Oval
Pack
PhotoImage
Place
Polygon
RPATHFLAG
RULE_SUBST
Radiobutton
Rectangle
SCRIPT_LINES__
SRC_EXT
STRING_OR_FAILED_FORMAT
Scala
Scale
Scrollbar
Selection
Spinbox
Synchronizer

A class that providesa two-phase lock with a counter. See Sync_m for details.

Synchronizer_m

A module that provides a two-phase lock with a counter.

Text
TextItem
ThWait

This class watches for termination of multiple threads. Basic functionality (wait until specified threads have terminated) can be accessed through the class method ThreadsWait.all_waits. Finer control can be gained using instance methods.

Example:

ThreadsWait.all_wait(thr1, thr2, ...) do |t|
  STDERR.puts "Thread #{t} has terminated."
end

th = ThreadsWait.new(thread1,...)
th.next_wait # next one to be done
TimeoutError

Raised by Timeout#timeout when the block times out.

TopLevel
UNIVERSAL_INTS
Variable
Version
VirtualEvent
WindowItem
Winfo

Public Instance Methods

CSV(*args, &block) click to toggle source

Another name for CSV.instance.

# File rake/lib/csv.rb, line 2339
def CSV(*args, &block)
  CSV.instance(*args, &block)
end
DelegateClass(superclass) click to toggle source

The primary interface to this library. Use to setup delegation when defining your class.

class MyClass < DelegateClass(ClassToDelegateTo) # Step 1
  def initialize
    super(obj_of_ClassToDelegateTo)              # Step 2
  end
end

Here’s a sample of use from Tempfile which is really a File object with a few special rules about storage location and when the File should be deleted. That makes for an almost textbook perfect example of how to use delegation.

class Tempfile < DelegateClass(File)
  # constant and class member data initialization...

  def initialize(basename, tmpdir=Dir::tmpdir)
    # build up file path/name in var tmpname...

    @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)

    # ...

    super(@tmpfile)

    # below this point, all methods of File are supported...
  end

  # ...
end
Calls superclass method
# File rake/lib/delegate.rb, line 334
def DelegateClass(superclass)
  klass = Class.new(Delegator)
  methods = superclass.instance_methods
  methods -= ::Delegator.public_api
  methods -= [:to_s,:inspect,:=~,:!~,:===]
  klass.module_eval do
    def __getobj__  # :nodoc:
      @delegate_dc_obj
    end
    def __setobj__(obj)  # :nodoc:
      raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
      @delegate_dc_obj = obj
    end
    methods.each do |method|
      define_method(method, Delegator.delegating_block(method))
    end
  end
  klass.define_singleton_method :public_instance_methods do |all=true|
    super(all) - superclass.protected_instance_methods
  end
  klass.define_singleton_method :protected_instance_methods do |all=true|
    super(all) | superclass.protected_instance_methods
  end
  return klass
end
Digest(name) → digest_subclass click to toggle source

Returns a Digest subclass by name.

require 'digest'

Digest("MD5")
# => Digest::MD5

Digest("Foo")
# => LoadError: library not found for class Digest::Foo -- digest/foo
# File rake/lib/digest.rb, line 86
def Digest(name)
  Digest.const_get(name)
end
Mainloop() click to toggle source
# File rake/lib/tkclass.rb, line 45
def Mainloop
  Tk.mainloop
end
__method_missing_alias_for_MultiTkIp__(id, *args)
Alias for: method_missing
check_signedness(type, headers = nil, opts = nil, &b) click to toggle source

Returns the signedness of the given type. You may optionally specify additional headers to search in for the type.

If the type is found and is a numeric type, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with ‘SIGNEDNESS_OF_’, followed by the type name, followed by ‘=X’ where ‘X’ is positive integer if the type is unsigned, or negative integer if the type is signed.

For example, if size_t is defined as unsigned, then #check_signedness(‘size_t’) would returned +1 and the SIGNEDNESS_OF_SIZE_T=+1 preprocessor macro would be passed to the compiler, and SIGNEDNESS_OF_INT=-1 if #check_signedness(‘int’) is done.

# File rake/lib/mkmf.rb, line 1177
def check_signedness(type, headers = nil, opts = nil, &b)
  typedef, member, prelude = typedef_expr(type, headers)
  signed = nil
  checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do
    signed = try_signedness(typedef, member, [prelude], opts, &b) or next nil
    $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed])
    signed < 0 ? "signed" : "unsigned"
  end
  signed
end
check_sizeof(type, headers = nil, opts = "", &b) click to toggle source

Returns the size of the given type. You may optionally specify additional headers to search in for the type.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with ‘SIZEOF_’, followed by the type name, followed by ‘=X’ where ‘X’ is the actual size.

For example, if #check_sizeof(‘mystruct’) returned 12, then the SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 1148
def check_sizeof(type, headers = nil, opts = "", &b)
  typedef, member, prelude = typedef_expr(type, headers)
  prelude << "static #{typedef} *rbcv_ptr_;\n"
  prelude = [prelude]
  expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
  fmt = STRING_OR_FAILED_FORMAT
  checking_for checking_message("size of #{type}", headers), fmt do
    if size = try_constant(expr, prelude, opts, &b)
      $defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size))
      size
    end
  end
end
chmod() click to toggle source

Change the mode of each FILE to OCTAL-MODE.

ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE

-v          verbose
# File rake/lib/un.rb, line 206
def chmod
  setup do |argv, options|
    mode = argv.shift.oct
    FileUtils.chmod mode, argv, options
  end
end
convertible_int(type, headers = nil, opts = nil, &b) click to toggle source

Returns the convertible integer type of the given type. You may optionally specify additional headers to search in for the type. Convertible means actually same type, or typedefed from same type.

If the type is a integer type and convertible type is found, following macros are passed as preprocessor constants to the compiler using the type name, in uppercase.

  • ‘TYPEOF_’, followed by the type name, followed by ‘=X’ where ‘X’ is the found convertible type name. * ‘TYP2NUM’ and ‘NUM2TYP, where ’TYP’ is the type name in uppercase with replacing ‘_t’ suffix with ‘T’, followed by ‘=X’ where ‘X’ is the macro name to convert type to Integer object, and vice versa.

For example, if foobar_t is defined as unsigned long, then #convertible_int(“foobar_t”) would return “unsigned long”, and define macros:

#define TYPEOF_FOOBAR_T unsigned long
#define FOOBART2NUM ULONG2NUM
#define NUM2FOOBART NUM2ULONG
# File rake/lib/mkmf.rb, line 1209
def convertible_int(type, headers = nil, opts = nil, &b)
  type, macname = *type
  checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
    if UNIVERSAL_INTS.include?(type)
      type
    else
      typedef, member, prelude = typedef_expr(type, headers, &b)
      next unless signed = try_signedness(typedef, member, [prelude])
      u = "unsigned " if signed > 0
      prelude << "extern rbcv_typedef_ foo();"
      compat = UNIVERSAL_INTS.find {|t|
        try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
      }
      if compat
        macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
        conv = (compat == "long long" ? "LL" : compat.upcase)
        compat = "#{u}#{compat}"
        $defs.push(format("-DTYPEOF_%s=%s", type.tr_cpp, compat.quote))
        $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
        conv = (u ? "U" : "") + conv
        $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
        $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
        compat
      end
    end
  end
end
cp() click to toggle source

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY

ruby -run -e cp -- [OPTION] SOURCE DEST

-p          preserve file attributes if possible
-r          copy recursively
-v          verbose
# File rake/lib/un.rb, line 77
def cp
  setup("pr") do |argv, options|
    cmd = "cp"
    cmd += "_r" if options.delete :r
    options[:preserve] = true if options.delete :p
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.send cmd, argv, dest, options
  end
end
create_header(header = "extconf.h") click to toggle source

Generates a header file consisting of the various macro definitions generated by other methods such as #have_func and have_header. These are then wrapped in a custom ifndef based on the header file name, which defaults to ‘extconf.h’.

For example:

# extconf.rb
require 'mkmf'
have_func('realpath')
have_header('sys/utime.h')
create_header
create_makefile('foo')

The above script would generate the following extconf.h file:

#ifndef EXTCONF_H
#define EXTCONF_H
#define HAVE_REALPATH 1
#define HAVE_SYS_UTIME_H 1
#endif

Given that the #create_header method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.

# File rake/lib/mkmf.rb, line 1485
def create_header(header = "extconf.h")
  message "creating %s\n", header
  sym = header.tr_cpp
  hdr = ["#ifndef #{sym}\n#define #{sym}\n"]
  for line in $defs
    case line
    when /^-D([^=]+)(?:=(.*))?/
      hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0].gsub(/(?=\t+)/, "\\\n") : 1}\n"
    when /^-U(.*)/
      hdr << "#undef #$1\n"
    end
  end
  hdr << "#endif\n"
  hdr = hdr.join
  log_src(hdr, "#{header} is")
  unless (IO.read(header) == hdr rescue false)
    open(header, "wb") do |hfile|
      hfile.write(hdr)
    end
  end
  $extconf_h = header
end
create_makefile(target, srcprefix = nil) { |conf| ... } click to toggle source

Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.

The target name should correspond the name of the global function name defined within your C extension, minus the ‘Init_’. For example, if your C extension is defined as ‘Init_foo’, then your target would simply be ‘foo’.

If any ‘/’ characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.

For example, if you pass ‘test/foo’ as a target name, your extension will be installed under the ‘test’ directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. “require ‘test/foo’”.

The srcprefix should be used when your source files are not in the same directory as your build script. This will not only eliminate the need for you to manually copy the source files into the same directory as your build script, but it also sets the proper target_prefix in the generated Makefile.

Setting the target_prefix will, in turn, install the generated binary in a directory under your RbConfig::CONFIG that mimics your local filesystem when you run ‘make install’.

For example, given the following file tree:

ext/
   extconf.rb
   test/
      foo.c

And given the following code:

create_makefile('test/foo', 'test')

That will set the target_prefix in the generated Makefile to ‘test’. That, in turn, will create the following file tree when installed via the ‘make install’ command:

/path/to/ruby/sitearchdir/test/foo.so

It is recommended that you use this approach to generate your makefiles, instead of copying files around manually, because some third party libraries may depend on the target_prefix being set properly.

The srcprefix argument can be used to override the default source directory, i.e. the current directory . It is included as part of the VPATH and added to the list of INCFLAGS.

# File rake/lib/mkmf.rb, line 1879
def create_makefile(target, srcprefix = nil)
  $target = target
  libpath = $DEFLIBPATH|$LIBPATH
  message "creating Makefile\n"
  rm_f "conftest*"
  if CONFIG["DLEXT"] == $OBJEXT
    for lib in libs = $libs.split
      lib.sub!(/-l(.*)/, %Q"lib\\1.#{$LIBEXT}"%)
    end
    $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
  end

  if target.include?('/')
    target_prefix, target = File.split(target)
    target_prefix[0,0] = '/'
  else
    target_prefix = ""
  end

  srcprefix ||= "$(srcdir)/#{srcprefix}".chomp('/')
  RbConfig.expand(srcdir = srcprefix.dup)

  ext = ".#{$OBJEXT}"
  if not $objs
    srcs = $srcs || Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
    objs = srcs.inject(Hash.new {[]}) {|h, f| h[File.basename(f, ".*") << ext] <<= f; h}
    $objs = objs.keys
    unless objs.delete_if {|b, f| f.size == 1}.empty?
      dups = objs.sort.map {|b, f|
        "#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}"
      }
      abort "source files duplication - #{dups.join(", ")}"
    end
  else
    $objs.collect! {|o| File.basename(o, ".*") << ext} unless $OBJEXT == "o"
    srcs = $srcs || $objs.collect {|o| o.chomp(ext) << ".c"}
  end
  $srcs = srcs

  target = nil if $objs.empty?

  if target and EXPORT_PREFIX
    if File.exist?(File.join(srcdir, target + '.def'))
      deffile = "$(srcdir)/$(TARGET).def"
      unless EXPORT_PREFIX.empty?
        makedef = %Q{-pe "$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
      end
    else
      makedef = %Q{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}' + 'Init_$(TARGET)'.sub(/\\..*\\z/,'')"}
    end
    if makedef
      $cleanfiles << '$(DEFFILE)'
      origdef = deffile
      deffile = "$(TARGET)-$(arch).def"
    end
  end
  origdef ||= ''

  if $extout and $INSTALLFILES
    $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))})
    $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir})
  end

  if $extmk and not $extconf_h
    create_header
  end

  libpath = libpathflag(libpath)

  dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
  staticlib = target ? "$(TARGET).#$LIBEXT" : ""
  mfile = open("Makefile", "wb")
  conf = configuration(srcprefix)
  conf = yield(conf) if block_given?
  mfile.puts(conf)
  mfile.print "
libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")}
LIBPATH = #{libpath}
DEFFILE = #{deffile}

CLEANFILES = #{$cleanfiles.join(' ')}
DISTCLEANFILES = #{$distcleanfiles.join(' ')}
DISTCLEANDIRS = #{$distcleandirs.join(' ')}

extout = #{$extout && $extout.quote}
extout_prefix = #{$extout_prefix}
target_prefix = #{target_prefix}
LOCAL_LIBS = #{$LOCAL_LIBS}
LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
SRCS = #{srcs.collect(&File.method(:basename)).join(' ')}
OBJS = #{$objs.join(" ")}
TARGET = #{target}
DLLIB = #{dllib}
EXTSTATIC = #{$static || ""}
STATIC_LIB = #{staticlib unless $static.nil?}
#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
" #"
  # TODO: fixme
  install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
  n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET)'
  mfile.print "
TARGET_SO     = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
CLEANLIBS     = #{n}.#{CONFIG['DLEXT']} #{config_string('cleanlibs') {|t| t.gsub(/\$\*/) {n}}}
CLEANOBJS     = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} if target} *.bak

all:    #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"}
static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
.PHONY: all install static install-so install-rb
.PHONY: clean clean-so clean-rb
"
  mfile.print CLEANINGS
  fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"}
  if fsep
    sep = ":/=#{fsep}"
    fseprepl = proc {|s|
      s = s.gsub("/", fsep)
      s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
      s = s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
    }
    rsep = ":#{fsep}=/"
  else
    fseprepl = proc {|s| s}
    sep = ""
    rsep = ""
  end
  dirs = []
  mfile.print "install: install-so install-rb\n\n"
  sodir = (dir = "$(RUBYARCHDIR)").dup
  mfile.print("install-so: ")
  if target
    f = "$(DLLIB)"
    dest = "#{dir}/#{f}"
    mfile.puts dest
    if $extout
      mfile.print "clean-so::\n"
      mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]}\n"
      mfile.print "\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n"
    else
      mfile.print "#{dest}: #{f}\n\t-$(Q)$(MAKEDIRS) $(@D#{sep})\n"
      mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} $(@D#{sep})\n"
      if defined?($installed_list)
        mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
      end
    end
    mfile.print "clean-static::\n"
    mfile.print "\t-$(Q)$(RM) $(STATIC_LIB)\n"
  else
    mfile.puts "Makefile"
  end
  mfile.print("install-rb: pre-install-rb install-rb-default\n")
  mfile.print("install-rb-default: pre-install-rb-default\n")
  mfile.print("pre-install-rb: Makefile\n")
  mfile.print("pre-install-rb-default: Makefile\n")
  for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
    files = install_files(mfile, i, nil, srcprefix) or next
    for dir, *files in files
      unless dirs.include?(dir)
        dirs << dir
        mfile.print "pre-install-rb#{sfx}: #{timestamp_file(dir)}\n"
      end
      for f in files
        dest = "#{dir}/#{File.basename(f)}"
        mfile.print("install-rb#{sfx}: #{dest} #{dir}\n")
        mfile.print("#{dest}: #{f}\n")
        mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
        if defined?($installed_list) and !$extout
          mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
        end
        if $extout
          mfile.print("clean-rb#{sfx}::\n")
          mfile.print("\t@-$(RM) #{fseprepl[dest]}\n")
        end
      end
    end
    mfile.print "pre-install-rb#{sfx}:\n"
    mfile.print("\t$(ECHO) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n")
    if $extout
      dirs.uniq!
      unless dirs.empty?
        mfile.print("clean-rb#{sfx}::\n")
        for dir in dirs.sort_by {|d| -d.count('/')}
          mfile.print("\t@-$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n")
        end
      end
    end
  end
  dirs.unshift(sodir) if target and !dirs.include?(sodir)
  dirs.each do |d|
    t = timestamp_file(d)
    mfile.print "#{t}:\n\t$(Q) $(MAKEDIRS) #{d}\n\t$(Q) $(TOUCH) $@\n"
  end

  mfile.print <<-SITEINSTALL

site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb

  SITEINSTALL

  return unless target

  mfile.puts SRC_EXT.collect {|e| ".path.#{e} = $(VPATH)"} if $nmake == b
  mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
  mfile.print "\n"

  compile_command = "\n\t$(ECHO) compiling $(<#{rsep})\n\t$(Q) %s\n\n"
  CXX_EXT.each do |e|
    COMPILE_RULES.each do |rule|
      mfile.printf(rule, e, $OBJEXT)
      mfile.printf(compile_command, COMPILE_CXX)
    end
  end
  C_EXT.each do |e|
    COMPILE_RULES.each do |rule|
      mfile.printf(rule, e, $OBJEXT)
      mfile.printf(compile_command, COMPILE_C)
    end
  end

  mfile.print "$(RUBYARCHDIR)/" if $extout
  mfile.print "$(DLLIB): "
  mfile.print "$(DEFFILE) " if makedef
  mfile.print "$(OBJS) Makefile"
  mfile.print " #{timestamp_file('$(RUBYARCHDIR)')}" if $extout
  mfile.print "\n"
  mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n"
  mfile.print "\t-$(Q)$(RM) $(@#{sep})\n"
  link_so = LINK_SO.gsub(/^/, "\t$(Q) ")
  if srcs.any?(&%r\.(?:#{CXX_EXT.join('|')})\z".method(:===))
    link_so = link_so.sub(/\bLDSHARED\b/, '\&XX')
  end
  mfile.print link_so, "\n\n"
  unless $static.nil?
    mfile.print "$(STATIC_LIB): $(OBJS)\n\t@-$(RM) $(@#{sep})\n\t"
    mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) "
    mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
    config_string('RANLIB') do |ranlib|
      mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
    end
  end
  mfile.print "\n\n"
  if makedef
    mfile.print "$(DEFFILE): #{origdef}\n"
    mfile.print "\t$(ECHO) generating $(@#{rsep})\n"
    mfile.print "\t$(Q) $(RUBY) #{makedef} #{origdef} > $@\n\n"
  end

  depend = File.join(srcdir, "depend")
  if File.exist?(depend)
    mfile.print("###\n", *depend_rules(File.read(depend)))
  else
    headers = %w[$(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h]
    if RULE_SUBST
      headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
    end
    headers << $config_h
    headers << '$(RUBY_EXTCONF_H)' if $extconf_h
    mfile.print "$(OBJS): ", headers.join(' '), "\n"
  end

  $makefile_created = true
ensure
  mfile.close if mfile
end
depend_rules(depend) click to toggle source

Processes the data contents of the “depend” file. Each line of this file is expected to be a file name.

Returns the output of findings, in Makefile format.

# File rake/lib/mkmf.rb, line 1771
def depend_rules(depend)
  suffixes = []
  depout = []
  cont = implicit = nil
  impconv = proc do
    COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]}
    implicit = nil
  end
  ruleconv = proc do |line|
    if implicit
      if /\A\t/ =~ line
        implicit[1] << line
        next
      else
        impconv[]
      end
    end
    if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line)
      suffixes << m[1] << m[2]
      implicit = [[m[1], m[2]], [m.post_match]]
      next
    elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
      line.gsub!(%r(\s)(?!\.)([^$(){}+=:\s\/\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
    end
    depout << line
  end
  depend.each_line do |line|
    line.gsub!(/\.o\b/, ".#{$OBJEXT}")
    line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h)
    line.gsub!(%r\$\(hdrdir\)/(?!ruby(?![^:;/\s]))(?=[-\w]+\.h)", '\&ruby/')
    if $nmake && /\A\s*\$\(RM|COPY\)/ =~ line
      line.gsub!(%r[-\w\./]{2,}"){$&.tr("/", "\\")}
      line.gsub!(/(\$\((?!RM|COPY)[^:)]+)(?=\))/, '\1:/=\')
    end
    if /(?:^|[^\])(?:\\)*\$/ =~ line
      (cont ||= []) << line
      next
    elsif cont
      line = (cont << line).join
      cont = nil
    end
    ruleconv.call(line)
  end
  if cont
    ruleconv.call(cont.join)
  elsif implicit
    impconv.call
  end
  unless suffixes.empty?
    depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n")
  end
  depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n") if $extconf_h
  depout.flatten!
  depout
end
dir_config(target, idefault=nil, ldefault=nil) click to toggle source

Sets a target name that the user can then use to configure various ‘with’ options with on the command line by using that name. For example, if the target is set to “foo”, then the user could use the –with-foo-dir command line option.

You may pass along additional ‘include’ or ‘lib’ defaults via the idefault and ldefault parameters, respectively.

Note that #dir_config only adds to the list of places to search for libraries and include files. It does not link the libraries into your application.

# File rake/lib/mkmf.rb, line 1519
def dir_config(target, idefault=nil, ldefault=nil)
  if dir = with_config(target + "-dir", (idefault unless ldefault))
    defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
    idefault = ldefault = nil
  end

  idir = with_config(target + "-include", idefault)
  $arg_config.last[1] ||= "${#{target}-dir}/include"
  ldir = with_config(target + "-lib", ldefault)
  $arg_config.last[1] ||= "${#{target}-dir}/#{@libdir_basename}"

  idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : []
  if defaults
    idirs.concat(defaults.collect {|d| d + "/include"})
    idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
  end
  unless idirs.empty?
    idirs.collect! {|d| "-I" + d}
    idirs -= Shellwords.shellwords($CPPFLAGS)
    unless idirs.empty?
      $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
    end
  end

  ldirs = ldir ? Array === ldir ? ldir.dup : ldir.split(File::PATH_SEPARATOR) : []
  if defaults
      ldirs.concat(defaults.collect {|d| "#{d}/#{@libdir_basename}"})
    ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
  end
  $LIBPATH = ldirs | $LIBPATH

  [idir, ldir]
end
dummy_makefile(srcdir) click to toggle source

creates a stub Makefile.

# File rake/lib/mkmf.rb, line 1754
def dummy_makefile(srcdir)
  configuration(srcdir) << "CLEANFILES = #{$cleanfiles.join(' ')}
DISTCLEANFILES = #{$distcleanfiles.join(' ')}

all install static install-so install-rb: Makefile
.PHONY: all install static install-so install-rb
.PHONY: clean clean-so clean-rb

" << CLEANINGS
end
enable_config(config, default=nil) { |config, default| ... } click to toggle source

Tests for the presence of an –enable-config or –disable-config option. Returns true if the enable option is given, false if the disable option is given, and the default value otherwise.

This can be useful for adding custom definitions, such as debug information.

Example:

if enable_config("debug")
   $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
# File rake/lib/mkmf.rb, line 1447
def enable_config(config, default=nil)
  if arg_config("--enable-"+config)
    true
  elsif arg_config("--disable-"+config)
    false
  elsif block_given?
    yield(config, default)
  else
    return default
  end
end
find_executable(bin, path = nil) click to toggle source

Searches for the executable bin on path. The default path is your PATH environment variable. If that isn’t defined, it will resort to searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.

If found, it will return the full path, including the executable name, of where it was found.

Note that this method does not actually affect the generated Makefile.

# File rake/lib/mkmf.rb, line 1381
def find_executable(bin, path = nil)
  checking_for checking_message(bin, path) do
    find_executable0(bin, path)
  end
end
find_header(header, *paths) click to toggle source

Instructs mkmf to search for the given header in any of the paths provided, and returns whether or not it was found in those paths.

If the header is found then the path it was found on is added to the list of included directories that are sent to the compiler (via the -I switch).

# File rake/lib/mkmf.rb, line 965
def find_header(header, *paths)
  message = checking_message(header, paths)
  header = cpp_include(header)
  checking_for message do
    if try_header(header)
      true
    else
      found = false
      paths.each do |dir|
        opt = "-I#{dir}".quote
        if try_header(header, opt)
          $INCFLAGS << " " << opt
          found = true
          break
        end
      end
      found
    end
  end
end
find_library(lib, func, *paths, &b) click to toggle source

Returns whether or not the entry point func can be found within the library lib in one of the paths specified, where paths is an array of strings. If func is nil , then the main() function is used as the entry point.

If lib is found, then the path it was found on is added to the list of library paths searched and linked against.

# File rake/lib/mkmf.rb, line 861
def find_library(lib, func, *paths, &b)
  func = "main" if !func or func.empty?
  lib = with_config(lib+'lib', lib)
  paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
  checking_for "#{func}() in #{LIBARG%lib}" do
    libpath = $LIBPATH
    libs = append_library($libs, lib)
    begin
      until r = try_func(func, libs, &b) or paths.empty?
        $LIBPATH = libpath | [paths.shift]
      end
      if r
        $libs = libs
        libpath = nil
      end
    ensure
      $LIBPATH = libpath if libpath
    end
    r
  end
end
find_type(type, opt, *headers, &b) click to toggle source

Returns where the static type type is defined.

You may also pass additional flags to opt which are then passed along to the compiler.

See also have_type.

# File rake/lib/mkmf.rb, line 1060
def find_type(type, opt, *headers, &b)
  opt ||= ""
  fmt = "not found"
  def fmt.%(x)
    x ? x.respond_to?(:join) ? x.join(",") : x : self
  end
  checking_for checking_message(type, nil, opt), fmt do
    headers.find do |h|
      try_type(type, h, opt, &b)
    end
  end
end
growl_notify(type, title, message) click to toggle source
# File lib/buildr/core/osx.rb, line 18
def growl_notify(type, title, message)
  begin
    # Loading Ruby Cocoa can slow the build down (hooks on Object class), so we're
    # saving the best for last and only requiring it at the very end.
    require 'osx/cocoa'
    icon = OSX::NSApplication.sharedApplication.applicationIconImage
    icon = OSX::NSImage.alloc.initWithContentsOfFile(File.join(File.dirname(__FILE__), '../resources/buildr.icns'))

    # Register with Growl, that way you can turn notifications on/off from system preferences.
    OSX::NSDistributedNotificationCenter.defaultCenter.
      postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification, nil,
        { :ApplicationName=>'Buildr', :AllNotifications=>['Completed', 'Failed'],
          :ApplicationIcon=>icon.TIFFRepresentation }, true)

    OSX::NSDistributedNotificationCenter.defaultCenter.
      postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil,
        { :ApplicationName=>'Buildr', :NotificationName=>type,
          :NotificationTitle=>title, :NotificationDescription=>message }, true)
  rescue Exception
    # We get here in two cases: system doesn't have Growl installed so one of the OSX
    # calls raises an exception; system doesn't have osx/cocoa, e.g. MacPorts Ruby 1.9,
    # so we also need to rescue LoadError.
  end
end
have_const(const, headers = nil, opt = "", &b) click to toggle source

Returns whether or not the constant const is defined. You may optionally pass the type of const as [const, type], like as:

have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")

You may also pass additional headers to check against in addition to the common header files, and additional flags to opt which are then passed along to the compiler.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with ‘HAVE_CONST_’.

For example, if #have_const(‘foo’) returned true, then the HAVE_CONST_FOO preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 1108
def have_const(const, headers = nil, opt = "", &b)
  checking_for checking_message([*const].compact.join(' '), headers, opt) do
    try_const(const, headers, opt, &b)
  end
end
have_framework(fw, &b) click to toggle source

Returns whether or not the given framework can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the framework name, in uppercase, prepended with ‘HAVE_FRAMEWORK_’.

For example, if #have_framework(‘Ruby’) returned true, then the HAVE_FRAMEWORK_RUBY preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 946
def have_framework(fw, &b)
  checking_for fw do
    src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}"
    if try_link(src, opt = "-framework #{fw}", &b)
      $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp))
      $LDFLAGS << " " << opt
      true
    else
      false
    end
  end
end
have_func(func, headers = nil, &b) click to toggle source

Returns whether or not the function func can be found in the common header files, or within any headers that you provide. If found, a macro is passed as a preprocessor constant to the compiler using the function name, in uppercase, prepended with ‘HAVE_’.

For example, if #have_func(‘foo’) returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 891
def have_func(func, headers = nil, &b)
  checking_for checking_message("#{func}()", headers) do
    if try_func(func, $libs, headers, &b)
      $defs.push(format("-DHAVE_%s", func.tr_cpp))
      true
    else
      false
    end
  end
end
have_header(header, preheaders = nil, &b) click to toggle source

Returns whether or not the given header file can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the header file name, in uppercase, prepended with ‘HAVE_’.

For example, if #have_header(‘foo.h’) returned true, then the HAVE_FOO_H preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 928
def have_header(header, preheaders = nil, &b)
  checking_for header do
    if try_header(cpp_include(preheaders)+cpp_include(header), &b)
      $defs.push(format("-DHAVE_%s", header.tr_cpp))
      true
    else
      false
    end
  end
end
have_library(lib, func = nil, headers = nil, &b) click to toggle source

Returns whether or not the given entry point func can be found within lib. If func is nil, the ‘main()’ entry point is used by default. If found, it adds the library to list of libraries to be used when linking your extension.

If headers are provided, it will include those header files as the header files it looks in when searching for func.

The real name of the library to be linked can be altered by ‘–with-FOOlib’ configuration option.

# File rake/lib/mkmf.rb, line 836
def have_library(lib, func = nil, headers = nil, &b)
  func = "main" if !func or func.empty?
  lib = with_config(lib+'lib', lib)
  checking_for checking_message("#{func}()", LIBARG%lib) do
    if COMMON_LIBS.include?(lib)
      true
    else
      libs = append_library($libs, lib)
      if try_func(func, libs, headers, &b)
        $libs = libs
        true
      else
        false
      end
    end
  end
end
have_macro(macro, headers = nil, opt = "", &b) click to toggle source

Returns whether or not macro is defined either in the common header files or within any headers you provide.

Any options you pass to opt are passed along to the compiler.

# File rake/lib/mkmf.rb, line 819
def have_macro(macro, headers = nil, opt = "", &b)
  checking_for checking_message(macro, headers, opt) do
    macro_defined?(macro, cpp_include(headers), opt, &b)
  end
end
have_struct_member(type, member, headers = nil, &b) click to toggle source

Returns whether or not the struct of type type contains member. If it does not, or the struct type can’t be found, then false is returned. You may optionally specify additional headers in which to look for the struct (in addition to the common header files).

If found, a macro is passed as a preprocessor constant to the compiler using the type name and the member name, in uppercase, prepended with ‘HAVE_’.

For example, if #have_struct_member(‘struct foo’, ‘bar’) returned true, then the HAVE_STRUCT_FOO_BAR preprocessor macro would be passed to the compiler.

HAVE_ST_BAR is also defined for backward compatibility.

# File rake/lib/mkmf.rb, line 999
def have_struct_member(type, member, headers = nil, &b)
  checking_for checking_message("#{type}.#{member}", headers) do
    if try_compile("#{cpp_include(headers)}
/*top*/
#{MAIN_DOES_NOTHING}
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
", &b)
      $defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp))
      $defs.push(format("-DHAVE_ST_%s", member.tr_cpp)) # backward compatibility
      true
    else
      false
    end
  end
end
have_type(type, headers = nil, opt = "", &b) click to toggle source

Returns whether or not the static type type is defined. You may optionally pass additional headers to check against in addition to the common header files.

You may also pass additional flags to opt which are then passed along to the compiler.

If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with ‘HAVE_TYPE_’.

For example, if #have_type(‘foo’) returned true, then the HAVE_TYPE_FOO preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 1047
def have_type(type, headers = nil, opt = "", &b)
  checking_for checking_message(type, headers, opt) do
    try_type(type, headers, opt, &b)
  end
end
have_var(var, headers = nil, &b) click to toggle source

Returns whether or not the variable var can be found in the common header files, or within any headers that you provide. If found, a macro is passed as a preprocessor constant to the compiler using the variable name, in uppercase, prepended with ‘HAVE_’.

For example, if #have_var(‘foo’) returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.

# File rake/lib/mkmf.rb, line 910
def have_var(var, headers = nil, &b)
  checking_for checking_message(var, headers) do
    if try_var(var, headers, &b)
      $defs.push(format("-DHAVE_%s", var.tr_cpp))
      true
    else
      false
    end
  end
end
help() click to toggle source

Display help message.

ruby -run -e help [COMMAND]
# File rake/lib/un.rb, line 335
def help
  setup do |argv,|
    all = argv.empty?
    open(__FILE__) do |me|
      while me.gets("##\n")
        if help = me.gets("\n\n")
          if all or argv.delete help[/-e \w+/].sub(/-e /, "")
            print help.gsub(/^# ?/, "")
          end
        end
      end
    end
  end
end
httpd() click to toggle source

Run WEBrick HTTP server.

ruby -run -e httpd -- [OPTION] DocumentRoot

--bind-address=ADDR         address to bind
--port=NUM                  listening port number
--max-clients=MAX           max number of simultaneous clients
--temp-dir=DIR              temporary directory
--do-not-reverse-lookup     disable reverse lookup
--request-timeout=SECOND    request timeout in seconds
--http-version=VERSION      HTTP version
-v                          verbose
# File rake/lib/un.rb, line 305
def httpd
  setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
        "DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
    |argv, options|
    require 'webrick'
    opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
    [:Port, :MaxClients].each do |name|
      opt = options[name] and (options[name] = Integer(opt)) rescue nil
    end
    unless argv.empty?
      options[:DocumentRoot] = argv.shift
    end
    s = WEBrick::HTTPServer.new(options)
    shut = proc {s.shutdown}
    Signal.trap("TERM", shut)
    Signal.trap("QUIT", shut) if Signal.list.has_key?("QUIT")
    if STDIN.tty?
      Signal.trap("HUP", shut) if Signal.list.has_key?("HUP")
      Signal.trap("INT", shut)
    end
    s.start
  end
end
info(message) click to toggle source

Show optional information. The message is printed only when running in verbose mode (the default).

# File lib/buildr/core/application.rb, line 627
def info(message)
  puts message if verbose
end
install() click to toggle source

Copy SOURCE to DEST.

ruby -run -e install -- [OPTION] SOURCE DEST

-p          apply access/modification times of SOURCE files to
            corresponding destination files
-m          set permission mode (as in chmod), instead of 0755
-v          verbose
# File rake/lib/un.rb, line 188
def install
  setup("pm:") do |argv, options|
    options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
    options[:preserve] = true if options.delete :p
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.install argv, dest, options
  end
end
ln() click to toggle source

Create a link to the specified TARGET with LINK_NAME.

ruby -run -e ln -- [OPTION] TARGET LINK_NAME

-s          make symbolic links instead of hard links
-f          remove existing destination files
-v          verbose
# File rake/lib/un.rb, line 98
def ln
  setup("sf") do |argv, options|
    cmd = "ln"
    cmd += "_s" if options.delete :s
    options[:force] = true if options.delete :f
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.send cmd, argv, dest, options
  end
end
method_missing(id, *args) click to toggle source
# File rake/lib/multi-tk.rb, line 2075
def method_missing(id, *args)
  begin
    has_top = (top = MultiTkIp.__getip.__pseudo_toplevel) &&
      top.respond_to?(:pseudo_toplevel_evaluable?) &&
      top.pseudo_toplevel_evaluable? &&
      top.respond_to?(id)
  rescue Exception => e
    has_top = false
  end

  if has_top
    top.__send__(id, *args)
  else
    __method_missing_alias_for_MultiTkIp__(id, *args)
  end
end
mkdir() click to toggle source

Create the DIR, if they do not already exist.

ruby -run -e mkdir -- [OPTION] DIR

-p          no error if existing, make parent directories as needed
-v          verbose
# File rake/lib/un.rb, line 153
def mkdir
  setup("p") do |argv, options|
    cmd = "mkdir"
    cmd += "_p" if options.delete :p
    FileUtils.send cmd, argv, options
  end
end
mkmf() click to toggle source

Create makefile using mkmf.

ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]

-d ARGS     run dir_config
-h ARGS     run have_header
-l ARGS     run have_library
-f ARGS     run have_func
-v ARGS     run have_var
-t ARGS     run have_type
-m ARGS     run have_macro
-c ARGS     run have_const
--vendor    install to vendor_ruby
# File rake/lib/un.rb, line 274
def mkmf
  setup("d:h:l:f:v:t:m:c:", "vendor") do |argv, options|
    require 'mkmf'
    opt = options[:d] and opt.split(/:/).each {|n| dir_config(*n.split(/,/))}
    opt = options[:h] and opt.split(/:/).each {|n| have_header(*n.split(/,/))}
    opt = options[:l] and opt.split(/:/).each {|n| have_library(*n.split(/,/))}
    opt = options[:f] and opt.split(/:/).each {|n| have_func(*n.split(/,/))}
    opt = options[:v] and opt.split(/:/).each {|n| have_var(*n.split(/,/))}
    opt = options[:t] and opt.split(/:/).each {|n| have_type(*n.split(/,/))}
    opt = options[:m] and opt.split(/:/).each {|n| have_macro(*n.split(/,/))}
    opt = options[:c] and opt.split(/:/).each {|n| have_const(*n.split(/,/))}
    $configure_args["--vendor"] = true if options[:vendor]
    create_makefile(*argv)
  end
end
mv() click to toggle source

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

ruby -run -e mv -- [OPTION] SOURCE DEST

-v          verbose
# File rake/lib/un.rb, line 117
def mv
  setup do |argv, options|
    dest = argv.pop
    argv = argv[0] if argv.size == 1
    FileUtils.mv argv, dest, options
  end
end
notify_send(type, title, message) click to toggle source
# File lib/buildr/core/linux.rb, line 20
def notify_send(type, title, message)
  icon = File.join(File.dirname(__FILE__), '../resources/', type.to_s + '.png')
  system "notify-send -i #{icon} \"#{title}\" \"#{message}\""
end
pretty_print(q) click to toggle source
# File rake/lib/pp.rb, line 520
def pretty_print(q)
  q.text inspect
end
pretty_print_cycle(q) click to toggle source
# File rake/lib/pp.rb, line 512
def pretty_print_cycle(q)
  q.text inspect
end
rm() click to toggle source

Remove the FILE

ruby -run -e rm -- [OPTION] FILE

-f          ignore nonexistent files
-r          remove the contents of directories recursively
-v          verbose
# File rake/lib/un.rb, line 135
def rm
  setup("fr") do |argv, options|
    cmd = "rm"
    cmd += "_r" if options.delete :r
    options[:force] = true if options.delete :f
    FileUtils.send cmd, argv, options
  end
end
rmdir() click to toggle source

Remove the DIR.

ruby -run -e rmdir -- [OPTION] DIR

-p          remove DIRECTORY and its ancestors.
-v          verbose
# File rake/lib/un.rb, line 170
def rmdir
  setup("p") do |argv, options|
    options[:parents] = true if options.delete :p
    FileUtils.rmdir argv, options
  end
end
setup(options = "", *long_options) { |argv, opt_hash| ... } click to toggle source
# File rake/lib/un.rb, line 35
def setup(options = "", *long_options)
  opt_hash = {}
  argv = []
  OptionParser.new do |o|
    options.scan(/.:?/) do |s|
      opt_name = s.delete(":").intern
      o.on("-" + s.tr(":", " ")) do |val|
        opt_hash[opt_name] = val
      end
    end
    long_options.each do |s|
      opt_name, arg_name = s.split(/(?=[\s=])/, 2)
      opt_name.sub!(/\A--/, '')
      s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}"
      puts "#{opt_name}=>#{s}" if $DEBUG
      opt_name = opt_name.intern
      o.on(s) do |val|
        opt_hash[opt_name] = val
      end
    end
    o.on("-v") do opt_hash[:verbose] = true end
    o.order!(ARGV) do |x|
      if /[*?\[{]/ =~ x
        argv.concat(Dir[x])
      else
        argv << x
      end
    end
  end
  yield argv, opt_hash
end
tar(file) → TarTask click to toggle source

The TarTask creates a new Tar file. You can include any number of files and and directories, use exclusion patterns, and include files into specific directories.

To create a GZipped Tar, either set the gzip option to true, or use the .tgz or .gz suffix.

For example:

tar("test.tgz").tap do |tgz|
  tgz.include "srcs"
  tgz.include "README", "LICENSE"
end
# File lib/buildr/packaging/tar.rb, line 185
def tar(file)
  TarTask.define_task(file)
end
timeout(n, e = nil, &block) click to toggle source

Identical to:

Timeout::timeout(n, e, &block).

This method is deprecated and provided only for backwards compatibility. You should use Timeout#timeout instead.

# File rake/lib/timeout.rb, line 98
def timeout(n, e = nil, &block)
  Timeout::timeout(n, e, &block)
end
touch() click to toggle source

Update the access and modification times of each FILE to the current time.

ruby -run -e touch -- [OPTION] FILE

-v          verbose
# File rake/lib/un.rb, line 221
def touch
  setup do |argv, options|
    FileUtils.touch argv, options
  end
end
trace(message) click to toggle source

Show message. The message is printed out only when running in trace mode.

# File lib/buildr/core/application.rb, line 632
def trace(message)
  puts message if Buildr.application.options.trace
end
trace?(*category) click to toggle source
# File lib/buildr/core/application.rb, line 636
def trace?(*category)
  options = Buildr.application.options
  return options.trace if category.empty?
  return true if options.trace_all
  return false unless options.trace_categories
  options.trace_categories.include?(category.first)
end
try_const(const, headers = nil, opt = "", &b) click to toggle source

Returns whether or not the Constant const is defined.

See also have_const

# File rake/lib/mkmf.rb, line 1077
def try_const(const, headers = nil, opt = "", &b)
  const, type = *const
  if try_compile("#{cpp_include(headers)}
/*top*/
typedef #{type || 'int'} conftest_type;
conftest_type conftestval = #{type ? '' : '(int)'}#{const};
", opt, &b)
    $defs.push(format("-DHAVE_CONST_%s", const.tr_cpp))
    true
  else
    false
  end
end
try_type(type, headers = nil, opt = "", &b) click to toggle source

Returns whether or not the static type type is defined.

See also have_type

# File rake/lib/mkmf.rb, line 1020
def try_type(type, headers = nil, opt = "", &b)
  if try_compile("#{cpp_include(headers)}
/*top*/
typedef #{type} conftest_type;
int conftestval[sizeof(conftest_type)?1:-1];
", opt, &b)
    $defs.push(format("-DHAVE_TYPE_%s", type.tr_cpp))
    true
  else
    false
  end
end
wait_writable() click to toggle source

Wait until the file becomes writable.

ruby -run -e wait_writable -- [OPTION] FILE

-n RETRY    count to retry
-w SEC      each wait time in seconds
-v          verbose
# File rake/lib/un.rb, line 237
def wait_writable
  setup("n:w:v") do |argv, options|
    verbose = options[:verbose]
    n = options[:n] and n = Integer(n)
    wait = (wait = options[:w]) ? Float(wait) : 0.2
    argv.each do |file|
      begin
        open(file, "r+b")
      rescue Errno::ENOENT
        break
      rescue Errno::EACCES => e
        raise if n and (n -= 1) <= 0
        puts e
        STDOUT.flush
        sleep wait
        retry
      end
    end
  end
end
warn(message) click to toggle source

Show warning message.

# File lib/buildr/core/application.rb, line 615
def warn(message)
  warn_without_color $terminal.color(message.to_s, :blue) if verbose
end
Also aliased as: warn_without_color
warn_without_color(message)
Alias for: warn
with_config(config, default=nil) { |config, default| ... } click to toggle source

Tests for the presence of a –with-config or –without-config option. Returns true if the with option is given, false if the without option is given, and the default value otherwise.

This can be useful for adding custom definitions, such as debug information.

Example:

if with_config("debug")
   $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
# File rake/lib/mkmf.rb, line 1414
def with_config(config, default=nil)
  config = config.sub(/^--with[-_]/, '')
  val = arg_config("--with-"+config) do
    if arg_config("--without-"+config)
      false
    elsif block_given?
      yield(config, default)
    else
      break default
    end
  end
  case val
  when "yes"
    true
  when "no"
    false
  else
    val
  end
end

Protected Instance Methods

error(message) click to toggle source

Show error message. Use this when you need to show an error message and not throwing an exception that will stop the build.

# File lib/buildr/core/application.rb, line 621
def error(message)
  puts $terminal.color(message.to_s, :red)
end