зеркало из https://github.com/github/ruby.git
* lib/rake/*: Gemify rake [fix GH-862][Feature #11025]
* test/rake/*: ditto. * tool/rbinstall.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
8c0b2a2860
Коммит
c4ee0df8ba
|
@ -1,3 +1,9 @@
|
|||
Sat Apr 4 21:31:18 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||
|
||||
* lib/rake/*: Gemify rake [fix GH-862][Feature #11025]
|
||||
* test/rake/*: ditto.
|
||||
* tool/rbinstall.rb: ditto.
|
||||
|
||||
Sat Apr 4 11:30:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_setbyte): check the argument first not to
|
||||
|
|
33
bin/rake
33
bin/rake
|
@ -1,33 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
#--
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007 Jim Weirich
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
begin
|
||||
require 'rubygems'
|
||||
gem 'rake'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require 'rake'
|
||||
|
||||
Rake.application.run
|
|
@ -1,4 +1,3 @@
|
|||
# gem base directory versioning file [executable files under bin]
|
||||
rake lib/rake lib/rake.rb [rake]
|
||||
rdoc lib/rdoc lib/rdoc.rb [rdoc ri]
|
||||
json ext/json ext/json/lib/json/version.rb
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
power_assert 0.2.2
|
||||
test-unit 3.0.9
|
||||
minitest 5.4.3
|
||||
rake 10.4.2
|
||||
|
|
79
lib/rake.rb
79
lib/rake.rb
|
@ -1,79 +0,0 @@
|
|||
#--
|
||||
# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
module Rake
|
||||
VERSION = '10.4.2'
|
||||
end
|
||||
|
||||
require 'rake/version'
|
||||
|
||||
# :stopdoc:
|
||||
# TODO: Remove in Rake 11
|
||||
RAKEVERSION = Rake::VERSION
|
||||
# :startdoc:
|
||||
|
||||
require 'rbconfig'
|
||||
require 'fileutils'
|
||||
require 'singleton'
|
||||
require 'monitor'
|
||||
require 'optparse'
|
||||
require 'ostruct'
|
||||
|
||||
require 'rake/ext/module'
|
||||
require 'rake/ext/string'
|
||||
require 'rake/ext/time'
|
||||
|
||||
require 'rake/win32'
|
||||
|
||||
require 'rake/linked_list'
|
||||
require 'rake/cpu_counter'
|
||||
require 'rake/scope'
|
||||
require 'rake/task_argument_error'
|
||||
require 'rake/rule_recursion_overflow_error'
|
||||
require 'rake/rake_module'
|
||||
require 'rake/trace_output'
|
||||
require 'rake/pseudo_status'
|
||||
require 'rake/task_arguments'
|
||||
require 'rake/invocation_chain'
|
||||
require 'rake/task'
|
||||
require 'rake/file_task'
|
||||
require 'rake/file_creation_task'
|
||||
require 'rake/multi_task'
|
||||
require 'rake/dsl_definition'
|
||||
require 'rake/file_utils_ext'
|
||||
require 'rake/file_list'
|
||||
require 'rake/default_loader'
|
||||
require 'rake/early_time'
|
||||
require 'rake/late_time'
|
||||
require 'rake/name_space'
|
||||
require 'rake/task_manager'
|
||||
require 'rake/application'
|
||||
require 'rake/backtrace'
|
||||
|
||||
$trace = false
|
||||
|
||||
# :stopdoc:
|
||||
#
|
||||
# Some top level Constants.
|
||||
|
||||
FileList = Rake::FileList
|
||||
RakeFileUtils = Rake::FileUtilsExt
|
|
@ -1,110 +0,0 @@
|
|||
#
|
||||
# Copyright (c) 2008 James M. Lawrence
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person
|
||||
# obtaining a copy of this software and associated documentation files
|
||||
# (the "Software"), to deal in the Software without restriction,
|
||||
# including without limitation the rights to use, copy, modify, merge,
|
||||
# publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
# and to permit persons to whom the Software is furnished to do so,
|
||||
# subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
|
||||
require 'rbconfig'
|
||||
|
||||
##
|
||||
# Alternate implementations of system() and backticks `` on Windows
|
||||
# for ruby-1.8 and earlier.
|
||||
#--
|
||||
# TODO: Remove in Rake 11
|
||||
|
||||
module Rake::AltSystem # :nodoc: all
|
||||
WINDOWS = RbConfig::CONFIG["host_os"] =~
|
||||
%r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
|
||||
|
||||
class << self
|
||||
def define_module_function(name, &block)
|
||||
define_method(name, &block)
|
||||
module_function(name)
|
||||
end
|
||||
end
|
||||
|
||||
if WINDOWS && RUBY_VERSION < "1.9.0"
|
||||
RUNNABLE_EXTS = %w[com exe bat cmd]
|
||||
RUNNABLE_PATTERN = %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i
|
||||
|
||||
define_module_function :kernel_system, &Kernel.method(:system)
|
||||
define_module_function :kernel_backticks, &Kernel.method(:'`')
|
||||
|
||||
module_function
|
||||
|
||||
def repair_command(cmd)
|
||||
"call " + (
|
||||
if cmd =~ %r!\A\s*\".*?\"!
|
||||
# already quoted
|
||||
cmd
|
||||
elsif match = cmd.match(%r!\A\s*(\S+)!)
|
||||
if match[1] =~ %r!/!
|
||||
# avoid x/y.bat interpretation as x with option /y
|
||||
%Q!"#{match[1]}"! + match.post_match
|
||||
else
|
||||
# a shell command will fail if quoted
|
||||
cmd
|
||||
end
|
||||
else
|
||||
# empty or whitespace
|
||||
cmd
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
def find_runnable(file)
|
||||
if file =~ RUNNABLE_PATTERN
|
||||
file
|
||||
else
|
||||
RUNNABLE_EXTS.each { |ext|
|
||||
test = "#{file}.#{ext}"
|
||||
return test if File.exist?(test)
|
||||
}
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def system(cmd, *args)
|
||||
repaired = (
|
||||
if args.empty?
|
||||
[repair_command(cmd)]
|
||||
elsif runnable = find_runnable(cmd)
|
||||
[File.expand_path(runnable), *args]
|
||||
else
|
||||
# non-existent file
|
||||
[cmd, *args]
|
||||
end
|
||||
)
|
||||
kernel_system(*repaired)
|
||||
end
|
||||
|
||||
def backticks(cmd)
|
||||
kernel_backticks(repair_command(cmd))
|
||||
end
|
||||
|
||||
define_module_function :'`', &method(:backticks)
|
||||
else
|
||||
# Non-Windows or ruby-1.9+: same as Kernel versions
|
||||
define_module_function :system, &Kernel.method(:system)
|
||||
define_module_function :backticks, &Kernel.method(:'`')
|
||||
define_module_function :'`', &Kernel.method(:'`')
|
||||
end
|
||||
end
|
|
@ -1,790 +0,0 @@
|
|||
require 'shellwords'
|
||||
require 'optparse'
|
||||
|
||||
require 'rake/task_manager'
|
||||
require 'rake/file_list'
|
||||
require 'rake/thread_pool'
|
||||
require 'rake/thread_history_display'
|
||||
require 'rake/trace_output'
|
||||
require 'rake/win32'
|
||||
|
||||
module Rake
|
||||
|
||||
CommandLineOptionError = Class.new(StandardError)
|
||||
|
||||
##
|
||||
# Rake main application object. When invoking +rake+ from the
|
||||
# command line, a Rake::Application object is created and run.
|
||||
|
||||
class Application
|
||||
include TaskManager
|
||||
include TraceOutput
|
||||
|
||||
# The name of the application (typically 'rake')
|
||||
attr_reader :name
|
||||
|
||||
# The original directory where rake was invoked.
|
||||
attr_reader :original_dir
|
||||
|
||||
# Name of the actual rakefile used.
|
||||
attr_reader :rakefile
|
||||
|
||||
# Number of columns on the terminal
|
||||
attr_accessor :terminal_columns
|
||||
|
||||
# List of the top level task names (task names from the command line).
|
||||
attr_reader :top_level_tasks
|
||||
|
||||
DEFAULT_RAKEFILES = [
|
||||
'rakefile',
|
||||
'Rakefile',
|
||||
'rakefile.rb',
|
||||
'Rakefile.rb'
|
||||
].freeze
|
||||
|
||||
# Initialize a Rake::Application object.
|
||||
def initialize
|
||||
super
|
||||
@name = 'rake'
|
||||
@rakefiles = DEFAULT_RAKEFILES.dup
|
||||
@rakefile = nil
|
||||
@pending_imports = []
|
||||
@imported = []
|
||||
@loaders = {}
|
||||
@default_loader = Rake::DefaultLoader.new
|
||||
@original_dir = Dir.pwd
|
||||
@top_level_tasks = []
|
||||
add_loader('rb', DefaultLoader.new)
|
||||
add_loader('rf', DefaultLoader.new)
|
||||
add_loader('rake', DefaultLoader.new)
|
||||
@tty_output = STDOUT.tty?
|
||||
@terminal_columns = ENV['RAKE_COLUMNS'].to_i
|
||||
end
|
||||
|
||||
# Run the Rake application. The run method performs the following
|
||||
# three steps:
|
||||
#
|
||||
# * Initialize the command line options (+init+).
|
||||
# * Define the tasks (+load_rakefile+).
|
||||
# * Run the top level tasks (+top_level+).
|
||||
#
|
||||
# If you wish to build a custom rake command, you should call
|
||||
# +init+ on your application. Then define any tasks. Finally,
|
||||
# call +top_level+ to run your top level tasks.
|
||||
def run
|
||||
standard_exception_handling do
|
||||
init
|
||||
load_rakefile
|
||||
top_level
|
||||
end
|
||||
end
|
||||
|
||||
# Initialize the command line parameters and app name.
|
||||
def init(app_name='rake')
|
||||
standard_exception_handling do
|
||||
@name = app_name
|
||||
args = handle_options
|
||||
collect_command_line_tasks(args)
|
||||
end
|
||||
end
|
||||
|
||||
# Find the rakefile and then load it and any pending imports.
|
||||
def load_rakefile
|
||||
standard_exception_handling do
|
||||
raw_load_rakefile
|
||||
end
|
||||
end
|
||||
|
||||
# Run the top level tasks of a Rake application.
|
||||
def top_level
|
||||
run_with_threads do
|
||||
if options.show_tasks
|
||||
display_tasks_and_comments
|
||||
elsif options.show_prereqs
|
||||
display_prerequisites
|
||||
else
|
||||
top_level_tasks.each { |task_name| invoke_task(task_name) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Run the given block with the thread startup and shutdown.
|
||||
def run_with_threads
|
||||
thread_pool.gather_history if options.job_stats == :history
|
||||
|
||||
yield
|
||||
|
||||
thread_pool.join
|
||||
if options.job_stats
|
||||
stats = thread_pool.statistics
|
||||
puts "Maximum active threads: #{stats[:max_active_threads]} + main"
|
||||
puts "Total threads in play: #{stats[:total_threads_in_play]} + main"
|
||||
end
|
||||
ThreadHistoryDisplay.new(thread_pool.history).show if
|
||||
options.job_stats == :history
|
||||
end
|
||||
|
||||
# Add a loader to handle imported files ending in the extension
|
||||
# +ext+.
|
||||
def add_loader(ext, loader)
|
||||
ext = ".#{ext}" unless ext =~ /^\./
|
||||
@loaders[ext] = loader
|
||||
end
|
||||
|
||||
# Application options from the command line
|
||||
def options
|
||||
@options ||= OpenStruct.new
|
||||
end
|
||||
|
||||
# Return the thread pool used for multithreaded processing.
|
||||
def thread_pool # :nodoc:
|
||||
@thread_pool ||= ThreadPool.new(options.thread_pool_size || Rake.suggested_thread_count-1)
|
||||
end
|
||||
|
||||
# internal ----------------------------------------------------------------
|
||||
|
||||
# Invokes a task with arguments that are extracted from +task_string+
|
||||
def invoke_task(task_string) # :nodoc:
|
||||
name, args = parse_task_string(task_string)
|
||||
t = self[name]
|
||||
t.invoke(*args)
|
||||
end
|
||||
|
||||
def parse_task_string(string) # :nodoc:
|
||||
/^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
|
||||
|
||||
name = $1
|
||||
remaining_args = $2
|
||||
|
||||
return string, [] unless name
|
||||
return name, [] if remaining_args.empty?
|
||||
|
||||
args = []
|
||||
|
||||
begin
|
||||
/((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
|
||||
|
||||
remaining_args = $2
|
||||
args << $1.gsub(/\\(.)/, '\1')
|
||||
end while remaining_args
|
||||
|
||||
return name, args
|
||||
end
|
||||
|
||||
# Provide standard exception handling for the given block.
|
||||
def standard_exception_handling # :nodoc:
|
||||
yield
|
||||
rescue SystemExit
|
||||
# Exit silently with current status
|
||||
raise
|
||||
rescue OptionParser::InvalidOption => ex
|
||||
$stderr.puts ex.message
|
||||
exit(false)
|
||||
rescue Exception => ex
|
||||
# Exit with error message
|
||||
display_error_message(ex)
|
||||
exit_because_of_exception(ex)
|
||||
end
|
||||
|
||||
# Exit the program because of an unhandle exception.
|
||||
# (may be overridden by subclasses)
|
||||
def exit_because_of_exception(ex) # :nodoc:
|
||||
exit(false)
|
||||
end
|
||||
|
||||
# Display the error message that caused the exception.
|
||||
def display_error_message(ex) # :nodoc:
|
||||
trace "#{name} aborted!"
|
||||
display_exception_details(ex)
|
||||
trace "Tasks: #{ex.chain}" if has_chain?(ex)
|
||||
trace "(See full trace by running task with --trace)" unless
|
||||
options.backtrace
|
||||
end
|
||||
|
||||
def display_exception_details(ex) # :nodoc:
|
||||
seen = Thread.current[:rake_display_exception_details_seen] ||= []
|
||||
return if seen.include? ex
|
||||
seen << ex
|
||||
|
||||
display_exception_message_details(ex)
|
||||
display_exception_backtrace(ex)
|
||||
display_exception_details(ex.cause) if has_cause?(ex)
|
||||
end
|
||||
|
||||
def has_cause?(ex) # :nodoc:
|
||||
ex.respond_to?(:cause) && ex.cause
|
||||
end
|
||||
|
||||
def display_exception_message_details(ex) # :nodoc:
|
||||
if ex.instance_of?(RuntimeError)
|
||||
trace ex.message
|
||||
else
|
||||
trace "#{ex.class.name}: #{ex.message}"
|
||||
end
|
||||
end
|
||||
|
||||
def display_exception_backtrace(ex) # :nodoc:
|
||||
if options.backtrace
|
||||
trace ex.backtrace.join("\n")
|
||||
else
|
||||
trace Backtrace.collapse(ex.backtrace).join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
# Warn about deprecated usage.
|
||||
#
|
||||
# Example:
|
||||
# Rake.application.deprecate("import", "Rake.import", caller.first)
|
||||
#
|
||||
def deprecate(old_usage, new_usage, call_site) # :nodoc:
|
||||
unless options.ignore_deprecate
|
||||
$stderr.puts "WARNING: '#{old_usage}' is deprecated. " +
|
||||
"Please use '#{new_usage}' instead.\n" +
|
||||
" at #{call_site}"
|
||||
end
|
||||
end
|
||||
|
||||
# Does the exception have a task invocation chain?
|
||||
def has_chain?(exception) # :nodoc:
|
||||
exception.respond_to?(:chain) && exception.chain
|
||||
end
|
||||
private :has_chain?
|
||||
|
||||
# True if one of the files in RAKEFILES is in the current directory.
|
||||
# If a match is found, it is copied into @rakefile.
|
||||
def have_rakefile # :nodoc:
|
||||
@rakefiles.each do |fn|
|
||||
if File.exist?(fn)
|
||||
others = FileList.glob(fn, File::FNM_CASEFOLD)
|
||||
return others.size == 1 ? others.first : fn
|
||||
elsif fn == ''
|
||||
return fn
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
# True if we are outputting to TTY, false otherwise
|
||||
def tty_output? # :nodoc:
|
||||
@tty_output
|
||||
end
|
||||
|
||||
# Override the detected TTY output state (mostly for testing)
|
||||
def tty_output=(tty_output_state) # :nodoc:
|
||||
@tty_output = tty_output_state
|
||||
end
|
||||
|
||||
# We will truncate output if we are outputting to a TTY or if we've been
|
||||
# given an explicit column width to honor
|
||||
def truncate_output? # :nodoc:
|
||||
tty_output? || @terminal_columns.nonzero?
|
||||
end
|
||||
|
||||
# Display the tasks and comments.
|
||||
def display_tasks_and_comments # :nodoc:
|
||||
displayable_tasks = tasks.select { |t|
|
||||
(options.show_all_tasks || t.comment) &&
|
||||
t.name =~ options.show_task_pattern
|
||||
}
|
||||
case options.show_tasks
|
||||
when :tasks
|
||||
width = displayable_tasks.map { |t| t.name_with_args.length }.max || 10
|
||||
if truncate_output?
|
||||
max_column = terminal_width - name.size - width - 7
|
||||
else
|
||||
max_column = nil
|
||||
end
|
||||
|
||||
displayable_tasks.each do |t|
|
||||
printf("#{name} %-#{width}s # %s\n",
|
||||
t.name_with_args,
|
||||
max_column ? truncate(t.comment, max_column) : t.comment)
|
||||
end
|
||||
when :describe
|
||||
displayable_tasks.each do |t|
|
||||
puts "#{name} #{t.name_with_args}"
|
||||
comment = t.full_comment || ""
|
||||
comment.split("\n").each do |line|
|
||||
puts " #{line}"
|
||||
end
|
||||
puts
|
||||
end
|
||||
when :lines
|
||||
displayable_tasks.each do |t|
|
||||
t.locations.each do |loc|
|
||||
printf "#{name} %-30s %s\n", t.name_with_args, loc
|
||||
end
|
||||
end
|
||||
else
|
||||
fail "Unknown show task mode: '#{options.show_tasks}'"
|
||||
end
|
||||
end
|
||||
|
||||
def terminal_width # :nodoc:
|
||||
if @terminal_columns.nonzero?
|
||||
result = @terminal_columns
|
||||
else
|
||||
result = unix? ? dynamic_width : 80
|
||||
end
|
||||
(result < 10) ? 80 : result
|
||||
rescue
|
||||
80
|
||||
end
|
||||
|
||||
# Calculate the dynamic width of the
|
||||
def dynamic_width # :nodoc:
|
||||
@dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
|
||||
end
|
||||
|
||||
def dynamic_width_stty # :nodoc:
|
||||
%x{stty size 2>/dev/null}.split[1].to_i
|
||||
end
|
||||
|
||||
def dynamic_width_tput # :nodoc:
|
||||
%x{tput cols 2>/dev/null}.to_i
|
||||
end
|
||||
|
||||
def unix? # :nodoc:
|
||||
RbConfig::CONFIG['host_os'] =~
|
||||
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
|
||||
end
|
||||
|
||||
def windows? # :nodoc:
|
||||
Win32.windows?
|
||||
end
|
||||
|
||||
def truncate(string, width) # :nodoc:
|
||||
if string.nil?
|
||||
""
|
||||
elsif string.length <= width
|
||||
string
|
||||
else
|
||||
(string[0, width - 3] || "") + "..."
|
||||
end
|
||||
end
|
||||
|
||||
# Display the tasks and prerequisites
|
||||
def display_prerequisites # :nodoc:
|
||||
tasks.each do |t|
|
||||
puts "#{name} #{t.name}"
|
||||
t.prerequisites.each { |pre| puts " #{pre}" }
|
||||
end
|
||||
end
|
||||
|
||||
def trace(*strings) # :nodoc:
|
||||
options.trace_output ||= $stderr
|
||||
trace_on(options.trace_output, *strings)
|
||||
end
|
||||
|
||||
def sort_options(options) # :nodoc:
|
||||
options.sort_by { |opt|
|
||||
opt.select { |o| o =~ /^-/ }.map { |o| o.downcase }.sort.reverse
|
||||
}
|
||||
end
|
||||
private :sort_options
|
||||
|
||||
# A list of all the standard options used in rake, suitable for
|
||||
# passing to OptionParser.
|
||||
def standard_rake_options # :nodoc:
|
||||
sort_options(
|
||||
[
|
||||
['--all', '-A',
|
||||
"Show all tasks, even uncommented ones (in combination with -T or -D)",
|
||||
lambda { |value|
|
||||
options.show_all_tasks = value
|
||||
}
|
||||
],
|
||||
['--backtrace=[OUT]',
|
||||
"Enable full backtrace. OUT can be stderr (default) or stdout.",
|
||||
lambda { |value|
|
||||
options.backtrace = true
|
||||
select_trace_output(options, 'backtrace', value)
|
||||
}
|
||||
],
|
||||
['--build-all', '-B',
|
||||
"Build all prerequisites, including those which are up-to-date.",
|
||||
lambda { |value|
|
||||
options.build_all = true
|
||||
}
|
||||
],
|
||||
['--comments',
|
||||
"Show commented tasks only",
|
||||
lambda { |value|
|
||||
options.show_all_tasks = !value
|
||||
}
|
||||
],
|
||||
['--describe', '-D [PATTERN]',
|
||||
"Describe the tasks (matching optional PATTERN), then exit.",
|
||||
lambda { |value|
|
||||
select_tasks_to_show(options, :describe, value)
|
||||
}
|
||||
],
|
||||
['--dry-run', '-n',
|
||||
"Do a dry run without executing actions.",
|
||||
lambda { |value|
|
||||
Rake.verbose(true)
|
||||
Rake.nowrite(true)
|
||||
options.dryrun = true
|
||||
options.trace = true
|
||||
}
|
||||
],
|
||||
['--execute', '-e CODE',
|
||||
"Execute some Ruby code and exit.",
|
||||
lambda { |value|
|
||||
eval(value)
|
||||
exit
|
||||
}
|
||||
],
|
||||
['--execute-print', '-p CODE',
|
||||
"Execute some Ruby code, print the result, then exit.",
|
||||
lambda { |value|
|
||||
puts eval(value)
|
||||
exit
|
||||
}
|
||||
],
|
||||
['--execute-continue', '-E CODE',
|
||||
"Execute some Ruby code, " +
|
||||
"then continue with normal task processing.",
|
||||
lambda { |value| eval(value) }
|
||||
],
|
||||
['--jobs', '-j [NUMBER]',
|
||||
"Specifies the maximum number of tasks to execute in parallel. " +
|
||||
"(default is number of CPU cores + 4)",
|
||||
lambda { |value|
|
||||
if value.nil? || value == ''
|
||||
value = FIXNUM_MAX
|
||||
elsif value =~ /^\d+$/
|
||||
value = value.to_i
|
||||
else
|
||||
value = Rake.suggested_thread_count
|
||||
end
|
||||
value = 1 if value < 1
|
||||
options.thread_pool_size = value - 1
|
||||
}
|
||||
],
|
||||
['--job-stats [LEVEL]',
|
||||
"Display job statistics. " +
|
||||
"LEVEL=history displays a complete job list",
|
||||
lambda { |value|
|
||||
if value =~ /^history/i
|
||||
options.job_stats = :history
|
||||
else
|
||||
options.job_stats = true
|
||||
end
|
||||
}
|
||||
],
|
||||
['--libdir', '-I LIBDIR',
|
||||
"Include LIBDIR in the search path for required modules.",
|
||||
lambda { |value| $:.push(value) }
|
||||
],
|
||||
['--multitask', '-m',
|
||||
"Treat all tasks as multitasks.",
|
||||
lambda { |value| options.always_multitask = true }
|
||||
],
|
||||
['--no-search', '--nosearch',
|
||||
'-N', "Do not search parent directories for the Rakefile.",
|
||||
lambda { |value| options.nosearch = true }
|
||||
],
|
||||
['--prereqs', '-P',
|
||||
"Display the tasks and dependencies, then exit.",
|
||||
lambda { |value| options.show_prereqs = true }
|
||||
],
|
||||
['--quiet', '-q',
|
||||
"Do not log messages to standard output.",
|
||||
lambda { |value| Rake.verbose(false) }
|
||||
],
|
||||
['--rakefile', '-f [FILENAME]',
|
||||
"Use FILENAME as the rakefile to search for.",
|
||||
lambda { |value|
|
||||
value ||= ''
|
||||
@rakefiles.clear
|
||||
@rakefiles << value
|
||||
}
|
||||
],
|
||||
['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
|
||||
"Auto-import any .rake files in RAKELIBDIR. " +
|
||||
"(default is 'rakelib')",
|
||||
lambda { |value|
|
||||
options.rakelib = value.split(File::PATH_SEPARATOR)
|
||||
}
|
||||
],
|
||||
['--require', '-r MODULE',
|
||||
"Require MODULE before executing rakefile.",
|
||||
lambda { |value|
|
||||
begin
|
||||
require value
|
||||
rescue LoadError => ex
|
||||
begin
|
||||
rake_require value
|
||||
rescue LoadError
|
||||
raise ex
|
||||
end
|
||||
end
|
||||
}
|
||||
],
|
||||
['--rules',
|
||||
"Trace the rules resolution.",
|
||||
lambda { |value| options.trace_rules = true }
|
||||
],
|
||||
['--silent', '-s',
|
||||
"Like --quiet, but also suppresses the " +
|
||||
"'in directory' announcement.",
|
||||
lambda { |value|
|
||||
Rake.verbose(false)
|
||||
options.silent = true
|
||||
}
|
||||
],
|
||||
['--suppress-backtrace PATTERN',
|
||||
"Suppress backtrace lines matching regexp PATTERN. " +
|
||||
"Ignored if --trace is on.",
|
||||
lambda { |value|
|
||||
options.suppress_backtrace_pattern = Regexp.new(value)
|
||||
}
|
||||
],
|
||||
['--system', '-g',
|
||||
"Using system wide (global) rakefiles " +
|
||||
"(usually '~/.rake/*.rake').",
|
||||
lambda { |value| options.load_system = true }
|
||||
],
|
||||
['--no-system', '--nosystem', '-G',
|
||||
"Use standard project Rakefile search paths, " +
|
||||
"ignore system wide rakefiles.",
|
||||
lambda { |value| options.ignore_system = true }
|
||||
],
|
||||
['--tasks', '-T [PATTERN]',
|
||||
"Display the tasks (matching optional PATTERN) " +
|
||||
"with descriptions, then exit.",
|
||||
lambda { |value|
|
||||
select_tasks_to_show(options, :tasks, value)
|
||||
}
|
||||
],
|
||||
['--trace=[OUT]', '-t',
|
||||
"Turn on invoke/execute tracing, enable full backtrace. " +
|
||||
"OUT can be stderr (default) or stdout.",
|
||||
lambda { |value|
|
||||
options.trace = true
|
||||
options.backtrace = true
|
||||
select_trace_output(options, 'trace', value)
|
||||
Rake.verbose(true)
|
||||
}
|
||||
],
|
||||
['--verbose', '-v',
|
||||
"Log message to standard output.",
|
||||
lambda { |value| Rake.verbose(true) }
|
||||
],
|
||||
['--version', '-V',
|
||||
"Display the program version.",
|
||||
lambda { |value|
|
||||
puts "rake, version #{RAKEVERSION}"
|
||||
exit
|
||||
}
|
||||
],
|
||||
['--where', '-W [PATTERN]',
|
||||
"Describe the tasks (matching optional PATTERN), then exit.",
|
||||
lambda { |value|
|
||||
select_tasks_to_show(options, :lines, value)
|
||||
options.show_all_tasks = true
|
||||
}
|
||||
],
|
||||
['--no-deprecation-warnings', '-X',
|
||||
"Disable the deprecation warnings.",
|
||||
lambda { |value|
|
||||
options.ignore_deprecate = true
|
||||
}
|
||||
],
|
||||
])
|
||||
end
|
||||
|
||||
def select_tasks_to_show(options, show_tasks, value) # :nodoc:
|
||||
options.show_tasks = show_tasks
|
||||
options.show_task_pattern = Regexp.new(value || '')
|
||||
Rake::TaskManager.record_task_metadata = true
|
||||
end
|
||||
private :select_tasks_to_show
|
||||
|
||||
def select_trace_output(options, trace_option, value) # :nodoc:
|
||||
value = value.strip unless value.nil?
|
||||
case value
|
||||
when 'stdout'
|
||||
options.trace_output = $stdout
|
||||
when 'stderr', nil
|
||||
options.trace_output = $stderr
|
||||
else
|
||||
fail CommandLineOptionError,
|
||||
"Unrecognized --#{trace_option} option '#{value}'"
|
||||
end
|
||||
end
|
||||
private :select_trace_output
|
||||
|
||||
# Read and handle the command line options. Returns the command line
|
||||
# arguments that we didn't understand, which should (in theory) be just
|
||||
# task names and env vars.
|
||||
def handle_options # :nodoc:
|
||||
options.rakelib = ['rakelib']
|
||||
options.trace_output = $stderr
|
||||
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..."
|
||||
opts.separator ""
|
||||
opts.separator "Options are ..."
|
||||
|
||||
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
|
||||
standard_rake_options.each { |args| opts.on(*args) }
|
||||
opts.environment('RAKEOPT')
|
||||
end.parse(ARGV)
|
||||
end
|
||||
|
||||
# Similar to the regular Ruby +require+ command, but will check
|
||||
# for *.rake files in addition to *.rb files.
|
||||
def rake_require(file_name, paths=$LOAD_PATH, loaded=$") # :nodoc:
|
||||
fn = file_name + ".rake"
|
||||
return false if loaded.include?(fn)
|
||||
paths.each do |path|
|
||||
full_path = File.join(path, fn)
|
||||
if File.exist?(full_path)
|
||||
Rake.load_rakefile(full_path)
|
||||
loaded << fn
|
||||
return true
|
||||
end
|
||||
end
|
||||
fail LoadError, "Can't find #{file_name}"
|
||||
end
|
||||
|
||||
def find_rakefile_location # :nodoc:
|
||||
here = Dir.pwd
|
||||
until (fn = have_rakefile)
|
||||
Dir.chdir("..")
|
||||
return nil if Dir.pwd == here || options.nosearch
|
||||
here = Dir.pwd
|
||||
end
|
||||
[fn, here]
|
||||
ensure
|
||||
Dir.chdir(Rake.original_dir)
|
||||
end
|
||||
|
||||
def print_rakefile_directory(location) # :nodoc:
|
||||
$stderr.puts "(in #{Dir.pwd})" unless
|
||||
options.silent or original_dir == location
|
||||
end
|
||||
|
||||
def raw_load_rakefile # :nodoc:
|
||||
rakefile, location = find_rakefile_location
|
||||
if (! options.ignore_system) &&
|
||||
(options.load_system || rakefile.nil?) &&
|
||||
system_dir && File.directory?(system_dir)
|
||||
print_rakefile_directory(location)
|
||||
glob("#{system_dir}/*.rake") do |name|
|
||||
add_import name
|
||||
end
|
||||
else
|
||||
fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})" if
|
||||
rakefile.nil?
|
||||
@rakefile = rakefile
|
||||
Dir.chdir(location)
|
||||
print_rakefile_directory(location)
|
||||
Rake.load_rakefile(File.expand_path(@rakefile)) if
|
||||
@rakefile && @rakefile != ''
|
||||
options.rakelib.each do |rlib|
|
||||
glob("#{rlib}/*.rake") do |name|
|
||||
add_import name
|
||||
end
|
||||
end
|
||||
end
|
||||
load_imports
|
||||
end
|
||||
|
||||
def glob(path, &block) # :nodoc:
|
||||
FileList.glob(path.gsub("\\", '/')).each(&block)
|
||||
end
|
||||
private :glob
|
||||
|
||||
# The directory path containing the system wide rakefiles.
|
||||
def system_dir # :nodoc:
|
||||
@system_dir ||=
|
||||
begin
|
||||
if ENV['RAKE_SYSTEM']
|
||||
ENV['RAKE_SYSTEM']
|
||||
else
|
||||
standard_system_dir
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The standard directory containing system wide rake files.
|
||||
if Win32.windows?
|
||||
def standard_system_dir #:nodoc:
|
||||
Win32.win32_system_dir
|
||||
end
|
||||
else
|
||||
def standard_system_dir #:nodoc:
|
||||
File.join(File.expand_path('~'), '.rake')
|
||||
end
|
||||
end
|
||||
private :standard_system_dir
|
||||
|
||||
# Collect the list of tasks on the command line. If no tasks are
|
||||
# given, return a list containing only the default task.
|
||||
# Environmental assignments are processed at this time as well.
|
||||
#
|
||||
# `args` is the list of arguments to peruse to get the list of tasks.
|
||||
# It should be the command line that was given to rake, less any
|
||||
# recognised command-line options, which OptionParser.parse will
|
||||
# have taken care of already.
|
||||
def collect_command_line_tasks(args) # :nodoc:
|
||||
@top_level_tasks = []
|
||||
args.each do |arg|
|
||||
if arg =~ /^(\w+)=(.*)$/m
|
||||
ENV[$1] = $2
|
||||
else
|
||||
@top_level_tasks << arg unless arg =~ /^-/
|
||||
end
|
||||
end
|
||||
@top_level_tasks.push(default_task_name) if @top_level_tasks.empty?
|
||||
end
|
||||
|
||||
# Default task name ("default").
|
||||
# (May be overridden by subclasses)
|
||||
def default_task_name # :nodoc:
|
||||
"default"
|
||||
end
|
||||
|
||||
# Add a file to the list of files to be imported.
|
||||
def add_import(fn) # :nodoc:
|
||||
@pending_imports << fn
|
||||
end
|
||||
|
||||
# Load the pending list of imported files.
|
||||
def load_imports # :nodoc:
|
||||
while fn = @pending_imports.shift
|
||||
next if @imported.member?(fn)
|
||||
fn_task = lookup(fn) and fn_task.invoke
|
||||
ext = File.extname(fn)
|
||||
loader = @loaders[ext] || @default_loader
|
||||
loader.load(fn)
|
||||
if fn_task = lookup(fn) and fn_task.needed?
|
||||
fn_task.reenable
|
||||
fn_task.invoke
|
||||
loader.load(fn)
|
||||
end
|
||||
@imported << fn
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_location(backtrace=caller) # :nodoc:
|
||||
backtrace.map { |t| t[/([^:]+):/, 1] }
|
||||
|
||||
re = /^#{@rakefile}$/
|
||||
re = /#{re.source}/i if windows?
|
||||
|
||||
backtrace.find { |str| str =~ re } || ''
|
||||
end
|
||||
|
||||
private
|
||||
FIXNUM_MAX = (2**(0.size * 8 - 2) - 1) # :nodoc:
|
||||
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
module Rake
|
||||
module Backtrace # :nodoc: all
|
||||
SYS_KEYS = RbConfig::CONFIG.keys.grep(/(?:[a-z]prefix|libdir)\z/)
|
||||
SYS_PATHS = RbConfig::CONFIG.values_at(*SYS_KEYS).uniq +
|
||||
[ File.join(File.dirname(__FILE__), "..") ]
|
||||
|
||||
SUPPRESSED_PATHS = SYS_PATHS.
|
||||
map { |s| s.gsub("\\", "/") }.
|
||||
map { |f| File.expand_path(f) }.
|
||||
reject { |s| s.nil? || s =~ /^ *$/ }
|
||||
SUPPRESSED_PATHS_RE = SUPPRESSED_PATHS.map { |f| Regexp.quote(f) }.join("|")
|
||||
SUPPRESSED_PATHS_RE << "|^org\\/jruby\\/\\w+\\.java" if
|
||||
Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
||||
|
||||
SUPPRESS_PATTERN = %r!(\A(#{SUPPRESSED_PATHS_RE})|bin/rake:\d+)!i
|
||||
|
||||
def self.collapse(backtrace)
|
||||
pattern = Rake.application.options.suppress_backtrace_pattern ||
|
||||
SUPPRESS_PATTERN
|
||||
backtrace.reject { |elem| elem =~ pattern }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,76 +0,0 @@
|
|||
# The 'rake/clean' file defines two file lists (CLEAN and CLOBBER) and
|
||||
# two rake tasks (:clean and :clobber).
|
||||
#
|
||||
# [:clean] Clean up the project by deleting scratch files and backup
|
||||
# files. Add files to the CLEAN file list to have the :clean
|
||||
# target handle them.
|
||||
#
|
||||
# [:clobber] Clobber all generated and non-source files in a project.
|
||||
# The task depends on :clean, so all the clean files will
|
||||
# be deleted as well as files in the CLOBBER file list.
|
||||
# The intent of this task is to return a project to its
|
||||
# pristine, just unpacked state.
|
||||
|
||||
require 'rake'
|
||||
|
||||
# :stopdoc:
|
||||
|
||||
module Rake
|
||||
module Cleaner
|
||||
extend FileUtils
|
||||
|
||||
module_function
|
||||
|
||||
def cleanup_files(file_names)
|
||||
file_names.each do |file_name|
|
||||
cleanup(file_name)
|
||||
end
|
||||
end
|
||||
|
||||
def cleanup(file_name, opts={})
|
||||
begin
|
||||
rm_r file_name, opts
|
||||
rescue StandardError => ex
|
||||
puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name)
|
||||
end
|
||||
end
|
||||
|
||||
def file_already_gone?(file_name)
|
||||
return false if File.exist?(file_name)
|
||||
|
||||
path = file_name
|
||||
prev = nil
|
||||
|
||||
while path = File.dirname(path)
|
||||
return false if cant_be_deleted?(path)
|
||||
break if [prev, "."].include?(path)
|
||||
prev = path
|
||||
end
|
||||
true
|
||||
end
|
||||
private_class_method :file_already_gone?
|
||||
|
||||
def cant_be_deleted?(path_name)
|
||||
File.exist?(path_name) &&
|
||||
(!File.readable?(path_name) || !File.executable?(path_name))
|
||||
end
|
||||
private_class_method :cant_be_deleted?
|
||||
end
|
||||
end
|
||||
|
||||
CLEAN = ::Rake::FileList["**/*~", "**/*.bak", "**/core"]
|
||||
CLEAN.clear_exclude.exclude { |fn|
|
||||
fn.pathmap("%f").downcase == 'core' && File.directory?(fn)
|
||||
}
|
||||
|
||||
desc "Remove any temporary products."
|
||||
task :clean do
|
||||
Rake::Cleaner.cleanup_files(CLEAN)
|
||||
end
|
||||
|
||||
CLOBBER = ::Rake::FileList.new
|
||||
|
||||
desc "Remove any generated file."
|
||||
task :clobber => [:clean] do
|
||||
Rake::Cleaner.cleanup_files(CLOBBER)
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
module Rake
|
||||
##
|
||||
# Mixin for creating easily cloned objects.
|
||||
|
||||
module Cloneable # :nodoc:
|
||||
# The hook that is invoked by 'clone' and 'dup' methods.
|
||||
def initialize_copy(source)
|
||||
super
|
||||
source.instance_variables.each do |var|
|
||||
src_value = source.instance_variable_get(var)
|
||||
value = src_value.clone rescue src_value
|
||||
instance_variable_set(var, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Manage several publishers as a single entity.
|
||||
class CompositePublisher
|
||||
def initialize
|
||||
@publishers = []
|
||||
end
|
||||
|
||||
# Add a publisher to the composite.
|
||||
def add(pub)
|
||||
@publishers << pub
|
||||
end
|
||||
|
||||
# Upload all the individual publishers.
|
||||
def upload
|
||||
@publishers.each { |p| p.upload }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
# = Tools for FTP uploading.
|
||||
#
|
||||
# This file is still under development and is not released for general
|
||||
# use.
|
||||
|
||||
require 'date'
|
||||
require 'net/ftp'
|
||||
require 'rake/file_list'
|
||||
|
||||
module Rake # :nodoc:
|
||||
|
||||
class FtpFile # :nodoc: all
|
||||
attr_reader :name, :size, :owner, :group, :time
|
||||
|
||||
def self.date
|
||||
@date_class ||= Date
|
||||
end
|
||||
|
||||
def self.time
|
||||
@time_class ||= Time
|
||||
end
|
||||
|
||||
def initialize(path, entry)
|
||||
@path = path
|
||||
@mode, _, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
|
||||
@size = size.to_i
|
||||
@time = determine_time(d1, d2, d3)
|
||||
end
|
||||
|
||||
def path
|
||||
File.join(@path, @name)
|
||||
end
|
||||
|
||||
def directory?
|
||||
@mode[0] == ?d
|
||||
end
|
||||
|
||||
def mode
|
||||
parse_mode(@mode)
|
||||
end
|
||||
|
||||
def symlink?
|
||||
@mode[0] == ?l
|
||||
end
|
||||
|
||||
private # --------------------------------------------------------
|
||||
|
||||
def parse_mode(m)
|
||||
result = 0
|
||||
(1..9).each do |i|
|
||||
result = 2 * result + ((m[i] == ?-) ? 0 : 1)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def determine_time(d1, d2, d3)
|
||||
now = self.class.time.now
|
||||
if /:/ !~ d3
|
||||
result = Time.parse("#{d1} #{d2} #{d3}")
|
||||
else
|
||||
result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
|
||||
result = Time.parse("#{d1} #{d2} #{now.year - 1} #{d3}") if
|
||||
result > now
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Manage the uploading of files to an FTP account.
|
||||
class FtpUploader # :nodoc:
|
||||
|
||||
# Log uploads to standard output when true.
|
||||
attr_accessor :verbose
|
||||
|
||||
class << FtpUploader
|
||||
# Create an uploader and pass it to the given block as +up+.
|
||||
# When the block is complete, close the uploader.
|
||||
def connect(path, host, account, password)
|
||||
up = self.new(path, host, account, password)
|
||||
begin
|
||||
yield(up)
|
||||
ensure
|
||||
up.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create an FTP uploader targeting the directory +path+ on +host+
|
||||
# using the given account and password. +path+ will be the root
|
||||
# path of the uploader.
|
||||
def initialize(path, host, account, password)
|
||||
@created = Hash.new
|
||||
@path = path
|
||||
@ftp = Net::FTP.new(host, account, password)
|
||||
makedirs(@path)
|
||||
@ftp.chdir(@path)
|
||||
end
|
||||
|
||||
# Create the directory +path+ in the uploader root path.
|
||||
def makedirs(path)
|
||||
route = []
|
||||
File.split(path).each do |dir|
|
||||
route << dir
|
||||
current_dir = File.join(route)
|
||||
if @created[current_dir].nil?
|
||||
@created[current_dir] = true
|
||||
$stderr.puts "Creating Directory #{current_dir}" if @verbose
|
||||
@ftp.mkdir(current_dir) rescue nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Upload all files matching +wildcard+ to the uploader's root
|
||||
# path.
|
||||
def upload_files(wildcard)
|
||||
FileList.glob(wildcard).each do |fn|
|
||||
upload(fn)
|
||||
end
|
||||
end
|
||||
|
||||
# Close the uploader.
|
||||
def close
|
||||
@ftp.close
|
||||
end
|
||||
|
||||
private # --------------------------------------------------------
|
||||
|
||||
# Upload a single file to the uploader's root path.
|
||||
def upload(file)
|
||||
$stderr.puts "Uploading #{file}" if @verbose
|
||||
dir = File.dirname(file)
|
||||
makedirs(dir)
|
||||
@ftp.putbinaryfile(file, file) unless File.directory?(file)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,81 +0,0 @@
|
|||
# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
|
||||
# All rights reserved.
|
||||
|
||||
# :stopdoc:
|
||||
|
||||
# Configuration information about an upload host system.
|
||||
# name :: Name of host system.
|
||||
# webdir :: Base directory for the web information for the
|
||||
# application. The application name (APP) is appended to
|
||||
# this directory before using.
|
||||
# pkgdir :: Directory on the host system where packages can be
|
||||
# placed.
|
||||
HostInfo = Struct.new(:name, :webdir, :pkgdir)
|
||||
|
||||
# :startdoc:
|
||||
|
||||
# TODO: Move to contrib/sshpublisher
|
||||
#--
|
||||
# Manage several publishers as a single entity.
|
||||
class CompositePublisher # :nodoc:
|
||||
def initialize
|
||||
@publishers = []
|
||||
end
|
||||
|
||||
# Add a publisher to the composite.
|
||||
def add(pub)
|
||||
@publishers << pub
|
||||
end
|
||||
|
||||
# Upload all the individual publishers.
|
||||
def upload
|
||||
@publishers.each { |p| p.upload }
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Remove in Rake 11, duplicated
|
||||
#--
|
||||
# Publish an entire directory to an existing remote directory using
|
||||
# SSH.
|
||||
class SshDirPublisher # :nodoc: all
|
||||
def initialize(host, remote_dir, local_dir)
|
||||
@host = host
|
||||
@remote_dir = remote_dir
|
||||
@local_dir = local_dir
|
||||
end
|
||||
|
||||
def upload
|
||||
run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Remove in Rake 11, duplicated
|
||||
#--
|
||||
# Publish an entire directory to a fresh remote directory using SSH.
|
||||
class SshFreshDirPublisher < SshDirPublisher # :nodoc: all
|
||||
def upload
|
||||
run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
|
||||
run %{ssh #{@host} mkdir #{@remote_dir}}
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Remove in Rake 11, duplicated
|
||||
#--
|
||||
# Publish a list of files to an existing remote directory.
|
||||
class SshFilePublisher # :nodoc: all
|
||||
# Create a publisher using the give host information.
|
||||
def initialize(host, remote_dir, local_dir, *files)
|
||||
@host = host
|
||||
@remote_dir = remote_dir
|
||||
@local_dir = local_dir
|
||||
@files = files
|
||||
end
|
||||
|
||||
# Upload the local directory to the remote directory.
|
||||
def upload
|
||||
@files.each do |fn|
|
||||
run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
# TODO: Remove in Rake 11
|
||||
|
||||
require 'rake/contrib/sshpublisher'
|
||||
|
||||
module Rake
|
||||
|
||||
class RubyForgePublisher < SshDirPublisher # :nodoc: all
|
||||
attr_reader :project, :proj_id, :user
|
||||
|
||||
def initialize(projname, user)
|
||||
super(
|
||||
"#{user}@rubyforge.org",
|
||||
"/var/www/gforge-projects/#{projname}",
|
||||
"html")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
require 'rake/dsl_definition'
|
||||
require 'rake/contrib/compositepublisher'
|
||||
|
||||
module Rake
|
||||
|
||||
# Publish an entire directory to an existing remote directory using
|
||||
# SSH.
|
||||
class SshDirPublisher
|
||||
include Rake::DSL
|
||||
|
||||
# Creates an SSH publisher which will scp all files in +local_dir+ to
|
||||
# +remote_dir+ on +host+
|
||||
|
||||
def initialize(host, remote_dir, local_dir)
|
||||
@host = host
|
||||
@remote_dir = remote_dir
|
||||
@local_dir = local_dir
|
||||
end
|
||||
|
||||
# Uploads the files
|
||||
|
||||
def upload
|
||||
sh "scp", "-rq", "#{@local_dir}/*", "#{@host}:#{@remote_dir}"
|
||||
end
|
||||
end
|
||||
|
||||
# Publish an entire directory to a fresh remote directory using SSH.
|
||||
class SshFreshDirPublisher < SshDirPublisher
|
||||
|
||||
# Uploads the files after removing the existing remote directory.
|
||||
|
||||
def upload
|
||||
sh "ssh", @host, "rm", "-rf", @remote_dir rescue nil
|
||||
sh "ssh", @host, "mkdir", @remote_dir
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Publish a list of files to an existing remote directory.
|
||||
class SshFilePublisher
|
||||
include Rake::DSL
|
||||
|
||||
# Creates an SSH publisher which will scp all +files+ in +local_dir+ to
|
||||
# +remote_dir+ on +host+.
|
||||
|
||||
def initialize(host, remote_dir, local_dir, *files)
|
||||
@host = host
|
||||
@remote_dir = remote_dir
|
||||
@local_dir = local_dir
|
||||
@files = files
|
||||
end
|
||||
|
||||
# Uploads the files
|
||||
|
||||
def upload
|
||||
@files.each do |fn|
|
||||
sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
# TODO: Remove in Rake 11
|
||||
|
||||
fail "ERROR: 'rake/contrib/sys' is obsolete and no longer supported. " +
|
||||
"Use 'FileUtils' instead."
|
|
@ -1,125 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Based on a script at:
|
||||
# http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed
|
||||
class CpuCounter # :nodoc: all
|
||||
def self.count
|
||||
new.count_with_default
|
||||
end
|
||||
|
||||
def count_with_default(default=4)
|
||||
count || default
|
||||
rescue StandardError
|
||||
default
|
||||
end
|
||||
|
||||
begin
|
||||
require 'etc'
|
||||
rescue LoadError
|
||||
else
|
||||
if Etc.respond_to?(:nprocessors)
|
||||
def count
|
||||
return Etc.nprocessors
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Rake::CpuCounter.method_defined?(:count)
|
||||
Rake::CpuCounter.class_eval <<-'end;', __FILE__, __LINE__+1
|
||||
require 'rbconfig'
|
||||
|
||||
# TODO: replace with IO.popen using array-style arguments in Rake 11
|
||||
require 'open3'
|
||||
|
||||
def count
|
||||
if defined?(Java::Java)
|
||||
count_via_java_runtime
|
||||
else
|
||||
case RbConfig::CONFIG['host_os']
|
||||
when /darwin9/
|
||||
count_via_hwprefs_cpu_count
|
||||
when /darwin/
|
||||
count_via_hwprefs_thread_count || count_via_sysctl
|
||||
when /linux/
|
||||
count_via_cpuinfo
|
||||
when /bsd/
|
||||
count_via_sysctl
|
||||
when /mswin|mingw/
|
||||
count_via_win32
|
||||
else
|
||||
# Try everything
|
||||
count_via_win32 ||
|
||||
count_via_sysctl ||
|
||||
count_via_hwprefs_thread_count ||
|
||||
count_via_hwprefs_cpu_count ||
|
||||
count_via_cpuinfo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def count_via_java_runtime
|
||||
Java::Java.lang.Runtime.getRuntime.availableProcessors
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
def count_via_win32
|
||||
require 'win32ole'
|
||||
wmi = WIN32OLE.connect("winmgmts://")
|
||||
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
|
||||
cpu.to_enum.first.NumberOfCores
|
||||
rescue StandardError, LoadError
|
||||
nil
|
||||
end
|
||||
|
||||
def count_via_cpuinfo
|
||||
open('/proc/cpuinfo') { |f| f.readlines }.grep(/processor/).size
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
def count_via_hwprefs_thread_count
|
||||
run 'hwprefs', 'thread_count'
|
||||
end
|
||||
|
||||
def count_via_hwprefs_cpu_count
|
||||
run 'hwprefs', 'cpu_count'
|
||||
end
|
||||
|
||||
def count_via_sysctl
|
||||
run 'sysctl', '-n', 'hw.ncpu'
|
||||
end
|
||||
|
||||
def run(command, *args)
|
||||
cmd = resolve_command(command)
|
||||
if cmd
|
||||
Open3.popen3 cmd, *args do |inn, out, err,|
|
||||
inn.close
|
||||
err.read
|
||||
out.read.to_i
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_command(command)
|
||||
look_for_command("/usr/sbin", command) ||
|
||||
look_for_command("/sbin", command) ||
|
||||
in_path_command(command)
|
||||
end
|
||||
|
||||
def look_for_command(dir, command)
|
||||
path = File.join(dir, command)
|
||||
File.exist?(path) ? path : nil
|
||||
end
|
||||
|
||||
def in_path_command(command)
|
||||
Open3.popen3 'which', command do |_, out,|
|
||||
out.eof? ? nil : command
|
||||
end
|
||||
end
|
||||
end;
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Default Rakefile loader used by +import+.
|
||||
class DefaultLoader
|
||||
|
||||
##
|
||||
# Loads a rakefile into the current application from +fn+
|
||||
|
||||
def load(fn)
|
||||
Rake.load_rakefile(File.expand_path(fn))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,201 +0,0 @@
|
|||
# Rake DSL functions.
|
||||
require 'rake/file_utils_ext'
|
||||
|
||||
module Rake
|
||||
|
||||
##
|
||||
# DSL is a module that provides #task, #desc, #namespace, etc. Use this
|
||||
# when you'd like to use rake outside the top level scope.
|
||||
#
|
||||
# For a Rakefile you run from the command line this module is automatically
|
||||
# included.
|
||||
|
||||
module DSL
|
||||
|
||||
#--
|
||||
# Include the FileUtils file manipulation functions in the top
|
||||
# level module, but mark them private so that they don't
|
||||
# unintentionally define methods on other objects.
|
||||
#++
|
||||
|
||||
include FileUtilsExt
|
||||
private(*FileUtils.instance_methods(false))
|
||||
private(*FileUtilsExt.instance_methods(false))
|
||||
|
||||
private
|
||||
|
||||
# :call-seq:
|
||||
# task task_name
|
||||
# task task_name: dependencies
|
||||
# task task_name, arguments => dependencies
|
||||
# task task_name, argument[, argument ...], :needs: dependencies
|
||||
#
|
||||
# Declare a basic task. The +task_name+ is always the first argument. If
|
||||
# the task name contains a ":" it is defined in that namespace.
|
||||
#
|
||||
# The +dependencies+ may be a single task name or an Array of task names.
|
||||
# The +argument+ (a single name) or +arguments+ (an Array of names) define
|
||||
# the arguments provided to the task.
|
||||
#
|
||||
# The task, argument and dependency names may be either symbols or
|
||||
# strings.
|
||||
#
|
||||
# A task with a single dependency:
|
||||
#
|
||||
# task clobber: %w[clean] do
|
||||
# rm_rf "html"
|
||||
# end
|
||||
#
|
||||
# A task with an argument and a dependency:
|
||||
#
|
||||
# task :package, [:version] => :test do |t, args|
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
# To invoke this task from the command line:
|
||||
#
|
||||
# $ rake package[1.2.3]
|
||||
#
|
||||
# Alternate definition:
|
||||
#
|
||||
# task :package, :version, needs: :test do |t, args|
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
def task(*args, &block) # :doc:
|
||||
Rake::Task.define_task(*args, &block)
|
||||
end
|
||||
|
||||
# Declare a file task.
|
||||
#
|
||||
# Example:
|
||||
# file "config.cfg" => ["config.template"] do
|
||||
# open("config.cfg", "w") do |outfile|
|
||||
# open("config.template") do |infile|
|
||||
# while line = infile.gets
|
||||
# outfile.puts line
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def file(*args, &block) # :doc:
|
||||
Rake::FileTask.define_task(*args, &block)
|
||||
end
|
||||
|
||||
# Declare a file creation task.
|
||||
# (Mainly used for the directory command).
|
||||
def file_create(*args, &block)
|
||||
Rake::FileCreationTask.define_task(*args, &block)
|
||||
end
|
||||
|
||||
# Declare a set of files tasks to create the given directories on
|
||||
# demand.
|
||||
#
|
||||
# Example:
|
||||
# directory "testdata/doc"
|
||||
#
|
||||
def directory(*args, &block) # :doc:
|
||||
result = file_create(*args, &block)
|
||||
dir, _ = *Rake.application.resolve_args(args)
|
||||
dir = Rake.from_pathname(dir)
|
||||
Rake.each_dir_parent(dir) do |d|
|
||||
file_create d do |t|
|
||||
mkdir_p t.name unless File.exist?(t.name)
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Declare a task that performs its prerequisites in
|
||||
# parallel. Multitasks does *not* guarantee that its prerequisites
|
||||
# will execute in any given order (which is obvious when you think
|
||||
# about it)
|
||||
#
|
||||
# Example:
|
||||
# multitask deploy: %w[deploy_gem deploy_rdoc]
|
||||
#
|
||||
def multitask(*args, &block) # :doc:
|
||||
Rake::MultiTask.define_task(*args, &block)
|
||||
end
|
||||
|
||||
# Create a new rake namespace and use it for evaluating the given
|
||||
# block. Returns a NameSpace object that can be used to lookup
|
||||
# tasks defined in the namespace.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# ns = namespace "nested" do
|
||||
# # the "nested:run" task
|
||||
# task :run
|
||||
# end
|
||||
# task_run = ns[:run] # find :run in the given namespace.
|
||||
#
|
||||
# Tasks can also be defined in a namespace by using a ":" in the task
|
||||
# name:
|
||||
#
|
||||
# task "nested:test" do
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
def namespace(name=nil, &block) # :doc:
|
||||
name = name.to_s if name.kind_of?(Symbol)
|
||||
name = name.to_str if name.respond_to?(:to_str)
|
||||
unless name.kind_of?(String) || name.nil?
|
||||
raise ArgumentError, "Expected a String or Symbol for a namespace name"
|
||||
end
|
||||
Rake.application.in_namespace(name, &block)
|
||||
end
|
||||
|
||||
# Declare a rule for auto-tasks.
|
||||
#
|
||||
# Example:
|
||||
# rule '.o' => '.c' do |t|
|
||||
# sh 'cc', '-o', t.name, t.source
|
||||
# end
|
||||
#
|
||||
def rule(*args, &block) # :doc:
|
||||
Rake::Task.create_rule(*args, &block)
|
||||
end
|
||||
|
||||
# Describes the next rake task. Duplicate descriptions are discarded.
|
||||
# Descriptions are shown with <code>rake -T</code> (up to the first
|
||||
# sentence) and <code>rake -D</code> (the entire description).
|
||||
#
|
||||
# Example:
|
||||
# desc "Run the Unit Tests"
|
||||
# task test: [:build]
|
||||
# # ... run tests
|
||||
# end
|
||||
#
|
||||
def desc(description) # :doc:
|
||||
Rake.application.last_description = description
|
||||
end
|
||||
|
||||
# Import the partial Rakefiles +fn+. Imported files are loaded
|
||||
# _after_ the current file is completely loaded. This allows the
|
||||
# import statement to appear anywhere in the importing file, and yet
|
||||
# allowing the imported files to depend on objects defined in the
|
||||
# importing file.
|
||||
#
|
||||
# A common use of the import statement is to include files
|
||||
# containing dependency declarations.
|
||||
#
|
||||
# See also the --rakelibdir command line option.
|
||||
#
|
||||
# Example:
|
||||
# import ".depend", "my_rules"
|
||||
#
|
||||
def import(*fns) # :doc:
|
||||
fns.each do |fn|
|
||||
Rake.application.add_import(fn)
|
||||
end
|
||||
end
|
||||
end
|
||||
extend FileUtilsExt
|
||||
end
|
||||
|
||||
# Extend the main object with the DSL commands. This allows top-level
|
||||
# calls to task, etc. to work from a Rakefile without polluting the
|
||||
# object inheritance tree.
|
||||
self.extend Rake::DSL
|
|
@ -1,21 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# EarlyTime is a fake timestamp that occurs _before_ any other time value.
|
||||
class EarlyTime
|
||||
include Comparable
|
||||
include Singleton
|
||||
|
||||
##
|
||||
# The EarlyTime always comes before +other+!
|
||||
|
||||
def <=>(other)
|
||||
-1
|
||||
end
|
||||
|
||||
def to_s # :nodoc:
|
||||
"<EARLY TIME>"
|
||||
end
|
||||
end
|
||||
|
||||
EARLY = EarlyTime.instance
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
class Module
|
||||
# Check for an existing method in the current class before extending. If
|
||||
# the method already exists, then a warning is printed and the extension is
|
||||
# not added. Otherwise the block is yielded and any definitions in the
|
||||
# block will take effect.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# class String
|
||||
# rake_extension("xyz") do
|
||||
# def xyz
|
||||
# ...
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def rake_extension(method) # :nodoc:
|
||||
if method_defined?(method)
|
||||
$stderr.puts "WARNING: Possible conflict with Rake extension: " +
|
||||
"#{self}##{method} already exists"
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
# TODO: remove in Rake 11
|
|
@ -1,25 +0,0 @@
|
|||
require 'rake/ext/core'
|
||||
require 'pathname'
|
||||
|
||||
class Pathname
|
||||
|
||||
rake_extension("ext") do
|
||||
# Return a new Pathname with <tt>String#ext</tt> applied to it.
|
||||
#
|
||||
# This Pathname extension comes from Rake
|
||||
def ext(newext='')
|
||||
Pathname.new(Rake.from_pathname(self).ext(newext))
|
||||
end
|
||||
end
|
||||
|
||||
rake_extension("pathmap") do
|
||||
# Apply the pathmap spec to the Pathname, returning a
|
||||
# new Pathname with the modified paths. (See String#pathmap for
|
||||
# details.)
|
||||
#
|
||||
# This Pathname extension comes from Rake
|
||||
def pathmap(spec=nil, &block)
|
||||
Pathname.new(Rake.from_pathname(self).pathmap(spec, &block))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,173 +0,0 @@
|
|||
require 'rake/ext/core'
|
||||
|
||||
class String
|
||||
|
||||
rake_extension("ext") do
|
||||
# Replace the file extension with +newext+. If there is no extension on
|
||||
# the string, append the new extension to the end. If the new extension
|
||||
# is not given, or is the empty string, remove any existing extension.
|
||||
#
|
||||
# +ext+ is a user added method for the String class.
|
||||
#
|
||||
# This String extension comes from Rake
|
||||
def ext(newext='')
|
||||
return self.dup if ['.', '..'].include? self
|
||||
newext = (newext =~ /^\./) ? newext : ("." + newext) if newext != ''
|
||||
self.chomp(File.extname(self)) << newext
|
||||
end
|
||||
end
|
||||
|
||||
rake_extension("pathmap") do
|
||||
# Explode a path into individual components. Used by +pathmap+.
|
||||
#
|
||||
# This String extension comes from Rake
|
||||
def pathmap_explode
|
||||
head, tail = File.split(self)
|
||||
return [self] if head == self
|
||||
return [tail] if head == '.' || tail == '/'
|
||||
return [head, tail] if head == '/'
|
||||
return head.pathmap_explode + [tail]
|
||||
end
|
||||
protected :pathmap_explode
|
||||
|
||||
# Extract a partial path from the path. Include +n+ directories from the
|
||||
# front end (left hand side) if +n+ is positive. Include |+n+|
|
||||
# directories from the back end (right hand side) if +n+ is negative.
|
||||
#
|
||||
# This String extension comes from Rake
|
||||
def pathmap_partial(n)
|
||||
dirs = File.dirname(self).pathmap_explode
|
||||
partial_dirs =
|
||||
if n > 0
|
||||
dirs[0...n]
|
||||
elsif n < 0
|
||||
dirs.reverse[0...-n].reverse
|
||||
else
|
||||
"."
|
||||
end
|
||||
File.join(partial_dirs)
|
||||
end
|
||||
protected :pathmap_partial
|
||||
|
||||
# Perform the pathmap replacement operations on the given path. The
|
||||
# patterns take the form 'pat1,rep1;pat2,rep2...'.
|
||||
#
|
||||
# This String extension comes from Rake
|
||||
def pathmap_replace(patterns, &block)
|
||||
result = self
|
||||
patterns.split(';').each do |pair|
|
||||
pattern, replacement = pair.split(',')
|
||||
pattern = Regexp.new(pattern)
|
||||
if replacement == '*' && block_given?
|
||||
result = result.sub(pattern, &block)
|
||||
elsif replacement
|
||||
result = result.sub(pattern, replacement)
|
||||
else
|
||||
result = result.sub(pattern, '')
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
protected :pathmap_replace
|
||||
|
||||
# Map the path according to the given specification. The specification
|
||||
# controls the details of the mapping. The following special patterns are
|
||||
# recognized:
|
||||
#
|
||||
# <tt>%p</tt> :: The complete path.
|
||||
# <tt>%f</tt> :: The base file name of the path, with its file extension,
|
||||
# but without any directories.
|
||||
# <tt>%n</tt> :: The file name of the path without its file extension.
|
||||
# <tt>%d</tt> :: The directory list of the path.
|
||||
# <tt>%x</tt> :: The file extension of the path. An empty string if there
|
||||
# is no extension.
|
||||
# <tt>%X</tt> :: Everything *but* the file extension.
|
||||
# <tt>%s</tt> :: The alternate file separator if defined, otherwise use #
|
||||
# the standard file separator.
|
||||
# <tt>%%</tt> :: A percent sign.
|
||||
#
|
||||
# The <tt>%d</tt> specifier can also have a numeric prefix (e.g. '%2d').
|
||||
# If the number is positive, only return (up to) +n+ directories in the
|
||||
# path, starting from the left hand side. If +n+ is negative, return (up
|
||||
# to) +n+ directories from the right hand side of the path.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b'
|
||||
# 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d'
|
||||
#
|
||||
# Also the <tt>%d</tt>, <tt>%p</tt>, <tt>%f</tt>, <tt>%n</tt>,
|
||||
# <tt>%x</tt>, and <tt>%X</tt> operators can take a pattern/replacement
|
||||
# argument to perform simple string substitutions on a particular part of
|
||||
# the path. The pattern and replacement are separated by a comma and are
|
||||
# enclosed by curly braces. The replacement spec comes after the %
|
||||
# character but before the operator letter. (e.g. "%{old,new}d").
|
||||
# Multiple replacement specs should be separated by semi-colons (e.g.
|
||||
# "%{old,new;src,bin}d").
|
||||
#
|
||||
# Regular expressions may be used for the pattern, and back refs may be
|
||||
# used in the replacement text. Curly braces, commas and semi-colons are
|
||||
# excluded from both the pattern and replacement text (let's keep parsing
|
||||
# reasonable).
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# "src/org/onestepback/proj/A.java".pathmap("%{^src,class}X.class")
|
||||
#
|
||||
# returns:
|
||||
#
|
||||
# "class/org/onestepback/proj/A.class"
|
||||
#
|
||||
# If the replacement text is '*', then a block may be provided to perform
|
||||
# some arbitrary calculation for the replacement.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# "/path/to/file.TXT".pathmap("%X%{.*,*}x") { |ext|
|
||||
# ext.downcase
|
||||
# }
|
||||
#
|
||||
# Returns:
|
||||
#
|
||||
# "/path/to/file.txt"
|
||||
#
|
||||
# This String extension comes from Rake
|
||||
def pathmap(spec=nil, &block)
|
||||
return self if spec.nil?
|
||||
result = ''
|
||||
spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
|
||||
case frag
|
||||
when '%f'
|
||||
result << File.basename(self)
|
||||
when '%n'
|
||||
result << File.basename(self).ext
|
||||
when '%d'
|
||||
result << File.dirname(self)
|
||||
when '%x'
|
||||
result << File.extname(self)
|
||||
when '%X'
|
||||
result << self.ext
|
||||
when '%p'
|
||||
result << self
|
||||
when '%s'
|
||||
result << (File::ALT_SEPARATOR || File::SEPARATOR)
|
||||
when '%-'
|
||||
# do nothing
|
||||
when '%%'
|
||||
result << "%"
|
||||
when /%(-?\d+)d/
|
||||
result << pathmap_partial($1.to_i)
|
||||
when /^%\{([^}]*)\}(\d*[dpfnxX])/
|
||||
patterns, operator = $1, $2
|
||||
result << pathmap('%' + operator).pathmap_replace(patterns, &block)
|
||||
when /^%/
|
||||
fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
|
||||
else
|
||||
result << frag
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
#--
|
||||
# Extensions to time to allow comparisons with early and late time classes.
|
||||
|
||||
require 'rake/early_time'
|
||||
require 'rake/late_time'
|
||||
|
||||
class Time # :nodoc: all
|
||||
alias rake_original_time_compare :<=>
|
||||
def <=>(other)
|
||||
if Rake::EarlyTime === other || Rake::LateTime === other
|
||||
- other.<=>(self)
|
||||
else
|
||||
rake_original_time_compare(other)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
require 'rake/file_task'
|
||||
require 'rake/early_time'
|
||||
|
||||
module Rake
|
||||
|
||||
# A FileCreationTask is a file task that when used as a dependency will be
|
||||
# needed if and only if the file has not been created. Once created, it is
|
||||
# not re-triggered if any of its dependencies are newer, nor does trigger
|
||||
# any rebuilds of tasks that depend on it whenever it is updated.
|
||||
#
|
||||
class FileCreationTask < FileTask
|
||||
# Is this file task needed? Yes if it doesn't exist.
|
||||
def needed?
|
||||
! File.exist?(name)
|
||||
end
|
||||
|
||||
# Time stamp for file creation task. This time stamp is earlier
|
||||
# than any other time stamp.
|
||||
def timestamp
|
||||
Rake::EARLY
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,428 +0,0 @@
|
|||
require 'rake/cloneable'
|
||||
require 'rake/file_utils_ext'
|
||||
require 'rake/pathmap'
|
||||
|
||||
|
||||
module Rake
|
||||
|
||||
##
|
||||
# A FileList is essentially an array with a few helper methods defined to
|
||||
# make file manipulation a bit easier.
|
||||
#
|
||||
# FileLists are lazy. When given a list of glob patterns for possible files
|
||||
# to be included in the file list, instead of searching the file structures
|
||||
# to find the files, a FileList holds the pattern for latter use.
|
||||
#
|
||||
# This allows us to define a number of FileList to match any number of
|
||||
# files, but only search out the actual files when then FileList itself is
|
||||
# actually used. The key is that the first time an element of the
|
||||
# FileList/Array is requested, the pending patterns are resolved into a real
|
||||
# list of file names.
|
||||
#
|
||||
class FileList
|
||||
|
||||
include Cloneable
|
||||
|
||||
# == Method Delegation
|
||||
#
|
||||
# The lazy evaluation magic of FileLists happens by implementing all the
|
||||
# array specific methods to call +resolve+ before delegating the heavy
|
||||
# lifting to an embedded array object (@items).
|
||||
#
|
||||
# In addition, there are two kinds of delegation calls. The regular kind
|
||||
# delegates to the @items array and returns the result directly. Well,
|
||||
# almost directly. It checks if the returned value is the @items object
|
||||
# itself, and if so will return the FileList object instead.
|
||||
#
|
||||
# The second kind of delegation call is used in methods that normally
|
||||
# return a new Array object. We want to capture the return value of these
|
||||
# methods and wrap them in a new FileList object. We enumerate these
|
||||
# methods in the +SPECIAL_RETURN+ list below.
|
||||
|
||||
# List of array methods (that are not in +Object+) that need to be
|
||||
# delegated.
|
||||
ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).
|
||||
map { |n| n.to_s }
|
||||
|
||||
# List of additional methods that must be delegated.
|
||||
MUST_DEFINE = %w[inspect <=>]
|
||||
|
||||
# List of methods that should not be delegated here (we define special
|
||||
# versions of them explicitly below).
|
||||
MUST_NOT_DEFINE = %w[to_a to_ary partition * <<]
|
||||
|
||||
# List of delegated methods that return new array values which need
|
||||
# wrapping.
|
||||
SPECIAL_RETURN = %w[
|
||||
map collect sort sort_by select find_all reject grep
|
||||
compact flatten uniq values_at
|
||||
+ - & |
|
||||
]
|
||||
|
||||
DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).
|
||||
map { |s| s.to_s }.sort.uniq
|
||||
|
||||
# Now do the delegation.
|
||||
DELEGATING_METHODS.each do |sym|
|
||||
if SPECIAL_RETURN.include?(sym)
|
||||
ln = __LINE__ + 1
|
||||
class_eval %{
|
||||
def #{sym}(*args, &block)
|
||||
resolve
|
||||
result = @items.send(:#{sym}, *args, &block)
|
||||
FileList.new.import(result)
|
||||
end
|
||||
}, __FILE__, ln
|
||||
else
|
||||
ln = __LINE__ + 1
|
||||
class_eval %{
|
||||
def #{sym}(*args, &block)
|
||||
resolve
|
||||
result = @items.send(:#{sym}, *args, &block)
|
||||
result.object_id == @items.object_id ? self : result
|
||||
end
|
||||
}, __FILE__, ln
|
||||
end
|
||||
end
|
||||
|
||||
# Create a file list from the globbable patterns given. If you wish to
|
||||
# perform multiple includes or excludes at object build time, use the
|
||||
# "yield self" pattern.
|
||||
#
|
||||
# Example:
|
||||
# file_list = FileList.new('lib/**/*.rb', 'test/test*.rb')
|
||||
#
|
||||
# pkg_files = FileList.new('lib/**/*') do |fl|
|
||||
# fl.exclude(/\bCVS\b/)
|
||||
# end
|
||||
#
|
||||
def initialize(*patterns)
|
||||
@pending_add = []
|
||||
@pending = false
|
||||
@exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
|
||||
@exclude_procs = DEFAULT_IGNORE_PROCS.dup
|
||||
@items = []
|
||||
patterns.each { |pattern| include(pattern) }
|
||||
yield self if block_given?
|
||||
end
|
||||
|
||||
# Add file names defined by glob patterns to the file list. If an array
|
||||
# is given, add each element of the array.
|
||||
#
|
||||
# Example:
|
||||
# file_list.include("*.java", "*.cfg")
|
||||
# file_list.include %w( math.c lib.h *.o )
|
||||
#
|
||||
def include(*filenames)
|
||||
# TODO: check for pending
|
||||
filenames.each do |fn|
|
||||
if fn.respond_to? :to_ary
|
||||
include(*fn.to_ary)
|
||||
else
|
||||
@pending_add << Rake.from_pathname(fn)
|
||||
end
|
||||
end
|
||||
@pending = true
|
||||
self
|
||||
end
|
||||
alias :add :include
|
||||
|
||||
# Register a list of file name patterns that should be excluded from the
|
||||
# list. Patterns may be regular expressions, glob patterns or regular
|
||||
# strings. In addition, a block given to exclude will remove entries that
|
||||
# return true when given to the block.
|
||||
#
|
||||
# Note that glob patterns are expanded against the file system. If a file
|
||||
# is explicitly added to a file list, but does not exist in the file
|
||||
# system, then an glob pattern in the exclude list will not exclude the
|
||||
# file.
|
||||
#
|
||||
# Examples:
|
||||
# FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
|
||||
# FileList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
|
||||
#
|
||||
# If "a.c" is a file, then ...
|
||||
# FileList['a.c', 'b.c'].exclude("a.*") => ['b.c']
|
||||
#
|
||||
# If "a.c" is not a file, then ...
|
||||
# FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
|
||||
#
|
||||
def exclude(*patterns, &block)
|
||||
patterns.each do |pat|
|
||||
@exclude_patterns << Rake.from_pathname(pat)
|
||||
end
|
||||
@exclude_procs << block if block_given?
|
||||
resolve_exclude unless @pending
|
||||
self
|
||||
end
|
||||
|
||||
# Clear all the exclude patterns so that we exclude nothing.
|
||||
def clear_exclude
|
||||
@exclude_patterns = []
|
||||
@exclude_procs = []
|
||||
self
|
||||
end
|
||||
|
||||
# A FileList is equal through array equality.
|
||||
def ==(array)
|
||||
to_ary == array
|
||||
end
|
||||
|
||||
# Return the internal array object.
|
||||
def to_a
|
||||
resolve
|
||||
@items
|
||||
end
|
||||
|
||||
# Return the internal array object.
|
||||
def to_ary
|
||||
to_a
|
||||
end
|
||||
|
||||
# Lie about our class.
|
||||
def is_a?(klass)
|
||||
klass == Array || super(klass)
|
||||
end
|
||||
alias kind_of? is_a?
|
||||
|
||||
# Redefine * to return either a string or a new file list.
|
||||
def *(other)
|
||||
result = @items * other
|
||||
case result
|
||||
when Array
|
||||
FileList.new.import(result)
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def <<(obj)
|
||||
resolve
|
||||
@items << Rake.from_pathname(obj)
|
||||
self
|
||||
end
|
||||
|
||||
# Resolve all the pending adds now.
|
||||
def resolve
|
||||
if @pending
|
||||
@pending = false
|
||||
@pending_add.each do |fn| resolve_add(fn) end
|
||||
@pending_add = []
|
||||
resolve_exclude
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def resolve_add(fn) # :nodoc:
|
||||
case fn
|
||||
when %r{[*?\[\{]}
|
||||
add_matching(fn)
|
||||
else
|
||||
self << fn
|
||||
end
|
||||
end
|
||||
private :resolve_add
|
||||
|
||||
def resolve_exclude # :nodoc:
|
||||
reject! { |fn| excluded_from_list?(fn) }
|
||||
self
|
||||
end
|
||||
private :resolve_exclude
|
||||
|
||||
# Return a new FileList with the results of running +sub+ against each
|
||||
# element of the original list.
|
||||
#
|
||||
# Example:
|
||||
# FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
|
||||
#
|
||||
def sub(pat, rep)
|
||||
inject(FileList.new) { |res, fn| res << fn.sub(pat, rep) }
|
||||
end
|
||||
|
||||
# Return a new FileList with the results of running +gsub+ against each
|
||||
# element of the original list.
|
||||
#
|
||||
# Example:
|
||||
# FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
|
||||
# => ['lib\\test\\file', 'x\\y']
|
||||
#
|
||||
def gsub(pat, rep)
|
||||
inject(FileList.new) { |res, fn| res << fn.gsub(pat, rep) }
|
||||
end
|
||||
|
||||
# Same as +sub+ except that the original file list is modified.
|
||||
def sub!(pat, rep)
|
||||
each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
|
||||
self
|
||||
end
|
||||
|
||||
# Same as +gsub+ except that the original file list is modified.
|
||||
def gsub!(pat, rep)
|
||||
each_with_index { |fn, i| self[i] = fn.gsub(pat, rep) }
|
||||
self
|
||||
end
|
||||
|
||||
# Apply the pathmap spec to each of the included file names, returning a
|
||||
# new file list with the modified paths. (See String#pathmap for
|
||||
# details.)
|
||||
def pathmap(spec=nil)
|
||||
collect { |fn| fn.pathmap(spec) }
|
||||
end
|
||||
|
||||
# Return a new FileList with <tt>String#ext</tt> method applied to
|
||||
# each member of the array.
|
||||
#
|
||||
# This method is a shortcut for:
|
||||
#
|
||||
# array.collect { |item| item.ext(newext) }
|
||||
#
|
||||
# +ext+ is a user added method for the Array class.
|
||||
def ext(newext='')
|
||||
collect { |fn| fn.ext(newext) }
|
||||
end
|
||||
|
||||
# Grep each of the files in the filelist using the given pattern. If a
|
||||
# block is given, call the block on each matching line, passing the file
|
||||
# name, line number, and the matching line of text. If no block is given,
|
||||
# a standard emacs style file:linenumber:line message will be printed to
|
||||
# standard out. Returns the number of matched items.
|
||||
def egrep(pattern, *options)
|
||||
matched = 0
|
||||
each do |fn|
|
||||
begin
|
||||
open(fn, "r", *options) do |inf|
|
||||
count = 0
|
||||
inf.each do |line|
|
||||
count += 1
|
||||
if pattern.match(line)
|
||||
matched += 1
|
||||
if block_given?
|
||||
yield fn, count, line
|
||||
else
|
||||
puts "#{fn}:#{count}:#{line}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue StandardError => ex
|
||||
$stderr.puts "Error while processing '#{fn}': #{ex}"
|
||||
end
|
||||
end
|
||||
matched
|
||||
end
|
||||
|
||||
# Return a new file list that only contains file names from the current
|
||||
# file list that exist on the file system.
|
||||
def existing
|
||||
select { |fn| File.exist?(fn) }
|
||||
end
|
||||
|
||||
# Modify the current file list so that it contains only file name that
|
||||
# exist on the file system.
|
||||
def existing!
|
||||
resolve
|
||||
@items = @items.select { |fn| File.exist?(fn) }
|
||||
self
|
||||
end
|
||||
|
||||
# FileList version of partition. Needed because the nested arrays should
|
||||
# be FileLists in this version.
|
||||
def partition(&block) # :nodoc:
|
||||
resolve
|
||||
result = @items.partition(&block)
|
||||
[
|
||||
FileList.new.import(result[0]),
|
||||
FileList.new.import(result[1]),
|
||||
]
|
||||
end
|
||||
|
||||
# Convert a FileList to a string by joining all elements with a space.
|
||||
def to_s
|
||||
resolve
|
||||
self.join(' ')
|
||||
end
|
||||
|
||||
# Add matching glob patterns.
|
||||
def add_matching(pattern)
|
||||
FileList.glob(pattern).each do |fn|
|
||||
self << fn unless excluded_from_list?(fn)
|
||||
end
|
||||
end
|
||||
private :add_matching
|
||||
|
||||
# Should the given file name be excluded from the list?
|
||||
#
|
||||
# NOTE: This method was formerly named "exclude?", but Rails
|
||||
# introduced an exclude? method as an array method and setup a
|
||||
# conflict with file list. We renamed the method to avoid
|
||||
# confusion. If you were using "FileList#exclude?" in your user
|
||||
# code, you will need to update.
|
||||
def excluded_from_list?(fn)
|
||||
return true if @exclude_patterns.any? do |pat|
|
||||
case pat
|
||||
when Regexp
|
||||
fn =~ pat
|
||||
when /[*?]/
|
||||
File.fnmatch?(pat, fn, File::FNM_PATHNAME)
|
||||
else
|
||||
fn == pat
|
||||
end
|
||||
end
|
||||
@exclude_procs.any? { |p| p.call(fn) }
|
||||
end
|
||||
|
||||
DEFAULT_IGNORE_PATTERNS = [
|
||||
/(^|[\/\\])CVS([\/\\]|$)/,
|
||||
/(^|[\/\\])\.svn([\/\\]|$)/,
|
||||
/\.bak$/,
|
||||
/~$/
|
||||
]
|
||||
DEFAULT_IGNORE_PROCS = [
|
||||
proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
|
||||
]
|
||||
|
||||
def import(array) # :nodoc:
|
||||
@items = array
|
||||
self
|
||||
end
|
||||
|
||||
class << self
|
||||
# Create a new file list including the files listed. Similar to:
|
||||
#
|
||||
# FileList.new(*args)
|
||||
def [](*args)
|
||||
new(*args)
|
||||
end
|
||||
|
||||
# Get a sorted list of files matching the pattern. This method
|
||||
# should be preferred to Dir[pattern] and Dir.glob(pattern) because
|
||||
# the files returned are guaranteed to be sorted.
|
||||
def glob(pattern, *args)
|
||||
Dir.glob(pattern, *args).sort
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Rake
|
||||
class << self
|
||||
|
||||
# Yield each file or directory component.
|
||||
def each_dir_parent(dir) # :nodoc:
|
||||
old_length = nil
|
||||
while dir != '.' && dir.length != old_length
|
||||
yield(dir)
|
||||
old_length = dir.length
|
||||
dir = File.dirname(dir)
|
||||
end
|
||||
end
|
||||
|
||||
# Convert Pathname and Pathname-like objects to strings;
|
||||
# leave everything else alone
|
||||
def from_pathname(path) # :nodoc:
|
||||
path = path.to_path if path.respond_to?(:to_path)
|
||||
path = path.to_str if path.respond_to?(:to_str)
|
||||
path
|
||||
end
|
||||
end
|
||||
end # module Rake
|
|
@ -1,46 +0,0 @@
|
|||
require 'rake/task.rb'
|
||||
require 'rake/early_time'
|
||||
|
||||
module Rake
|
||||
|
||||
# A FileTask is a task that includes time based dependencies. If any of a
|
||||
# FileTask's prerequisites have a timestamp that is later than the file
|
||||
# represented by this task, then the file must be rebuilt (using the
|
||||
# supplied actions).
|
||||
#
|
||||
class FileTask < Task
|
||||
|
||||
# Is this file task needed? Yes if it doesn't exist, or if its time stamp
|
||||
# is out of date.
|
||||
def needed?
|
||||
! File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all
|
||||
end
|
||||
|
||||
# Time stamp for file task.
|
||||
def timestamp
|
||||
if File.exist?(name)
|
||||
File.mtime(name.to_s)
|
||||
else
|
||||
Rake::LATE
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Are there any prerequisites with a later time than the given time stamp?
|
||||
def out_of_date?(stamp)
|
||||
@prerequisites.any? { |n| application[n, @scope].timestamp > stamp }
|
||||
end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Task class methods.
|
||||
#
|
||||
class << self
|
||||
# Apply the scope to the task name according to the rules for this kind
|
||||
# of task. File based tasks ignore the scope when creating the name.
|
||||
def scope_name(scope, task_name)
|
||||
Rake.from_pathname(task_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,128 +0,0 @@
|
|||
require 'rbconfig'
|
||||
require 'fileutils'
|
||||
|
||||
#--
|
||||
# This a FileUtils extension that defines several additional commands to be
|
||||
# added to the FileUtils utility functions.
|
||||
module FileUtils
|
||||
# Path to the currently running Ruby program
|
||||
RUBY = ENV['RUBY'] || File.join(
|
||||
RbConfig::CONFIG['bindir'],
|
||||
RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']).
|
||||
sub(/.*\s.*/m, '"\&"')
|
||||
|
||||
OPT_TABLE['sh'] = %w(noop verbose)
|
||||
OPT_TABLE['ruby'] = %w(noop verbose)
|
||||
|
||||
# Run the system command +cmd+. If multiple arguments are given the command
|
||||
# is run directly (without the shell, same semantics as Kernel::exec and
|
||||
# Kernel::system).
|
||||
#
|
||||
# It is recommended you use the multiple argument form over interpolating
|
||||
# user input for both usability and security reasons. With the multiple
|
||||
# argument form you can easily process files with spaces or other shell
|
||||
# reserved characters in them. With the multiple argument form your rake
|
||||
# tasks are not vulnerable to users providing an argument like
|
||||
# <code>; rm # -rf /</code>.
|
||||
#
|
||||
# If a block is given, upon command completion the block is called with an
|
||||
# OK flag (true on a zero exit status) and a Process::Status object.
|
||||
# Without a block a RuntimeError is raised when the command exits non-zero.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sh 'ls -ltr'
|
||||
#
|
||||
# sh 'ls', 'file with spaces'
|
||||
#
|
||||
# # check exit status after command runs
|
||||
# sh %{grep pattern file} do |ok, res|
|
||||
# if ! ok
|
||||
# puts "pattern not found (status = #{res.exitstatus})"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def sh(*cmd, &block)
|
||||
options = (Hash === cmd.last) ? cmd.pop : {}
|
||||
shell_runner = block_given? ? block : create_shell_runner(cmd)
|
||||
set_verbose_option(options)
|
||||
options[:noop] ||= Rake::FileUtilsExt.nowrite_flag
|
||||
Rake.rake_check_options options, :noop, :verbose
|
||||
Rake.rake_output_message cmd.join(" ") if options[:verbose]
|
||||
|
||||
unless options[:noop]
|
||||
res = rake_system(*cmd)
|
||||
status = $?
|
||||
status = Rake::PseudoStatus.new(1) if !res && status.nil?
|
||||
shell_runner.call(res, status)
|
||||
end
|
||||
end
|
||||
|
||||
def create_shell_runner(cmd) # :nodoc:
|
||||
show_command = cmd.join(" ")
|
||||
show_command = show_command[0, 42] + "..." unless $trace
|
||||
lambda do |ok, status|
|
||||
ok or
|
||||
fail "Command failed with status (#{status.exitstatus}): " +
|
||||
"[#{show_command}]"
|
||||
end
|
||||
end
|
||||
private :create_shell_runner
|
||||
|
||||
def set_verbose_option(options) # :nodoc:
|
||||
unless options.key? :verbose
|
||||
options[:verbose] =
|
||||
(Rake::FileUtilsExt.verbose_flag == Rake::FileUtilsExt::DEFAULT) ||
|
||||
Rake::FileUtilsExt.verbose_flag
|
||||
end
|
||||
end
|
||||
private :set_verbose_option
|
||||
|
||||
def rake_system(*cmd) # :nodoc:
|
||||
Rake::AltSystem.system(*cmd)
|
||||
end
|
||||
private :rake_system
|
||||
|
||||
# Run a Ruby interpreter with the given arguments.
|
||||
#
|
||||
# Example:
|
||||
# ruby %{-pe '$_.upcase!' <README}
|
||||
#
|
||||
def ruby(*args, &block)
|
||||
options = (Hash === args.last) ? args.pop : {}
|
||||
if args.length > 1
|
||||
sh(*([RUBY] + args + [options]), &block)
|
||||
else
|
||||
sh("#{RUBY} #{args.first}", options, &block)
|
||||
end
|
||||
end
|
||||
|
||||
LN_SUPPORTED = [true]
|
||||
|
||||
# Attempt to do a normal file link, but fall back to a copy if the link
|
||||
# fails.
|
||||
def safe_ln(*args)
|
||||
if ! LN_SUPPORTED[0]
|
||||
cp(*args)
|
||||
else
|
||||
begin
|
||||
ln(*args)
|
||||
rescue StandardError, NotImplementedError
|
||||
LN_SUPPORTED[0] = false
|
||||
cp(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Split a file path into individual directory names.
|
||||
#
|
||||
# Example:
|
||||
# split_all("a/b/c") => ['a', 'b', 'c']
|
||||
#
|
||||
def split_all(path)
|
||||
head, tail = File.split(path)
|
||||
return [tail] if head == '.' || tail == '/'
|
||||
return [head, tail] if head == '/'
|
||||
return split_all(head) + [tail]
|
||||
end
|
||||
end
|
|
@ -1,144 +0,0 @@
|
|||
require 'rake/file_utils'
|
||||
|
||||
module Rake
|
||||
#
|
||||
# FileUtilsExt provides a custom version of the FileUtils methods
|
||||
# that respond to the <tt>verbose</tt> and <tt>nowrite</tt>
|
||||
# commands.
|
||||
#
|
||||
module FileUtilsExt
|
||||
include FileUtils
|
||||
|
||||
class << self
|
||||
attr_accessor :verbose_flag, :nowrite_flag
|
||||
end
|
||||
|
||||
DEFAULT = Object.new
|
||||
|
||||
FileUtilsExt.verbose_flag = DEFAULT
|
||||
FileUtilsExt.nowrite_flag = false
|
||||
|
||||
FileUtils.commands.each do |name|
|
||||
opts = FileUtils.options_of name
|
||||
default_options = []
|
||||
if opts.include?("verbose")
|
||||
default_options << ':verbose => FileUtilsExt.verbose_flag'
|
||||
end
|
||||
if opts.include?("noop")
|
||||
default_options << ':noop => FileUtilsExt.nowrite_flag'
|
||||
end
|
||||
|
||||
next if default_options.empty?
|
||||
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||
def #{name}( *args, &block )
|
||||
super(
|
||||
*rake_merge_option(args,
|
||||
#{default_options.join(', ')}
|
||||
), &block)
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
# Get/set the verbose flag controlling output from the FileUtils
|
||||
# utilities. If verbose is true, then the utility method is
|
||||
# echoed to standard output.
|
||||
#
|
||||
# Examples:
|
||||
# verbose # return the current value of the
|
||||
# # verbose flag
|
||||
# verbose(v) # set the verbose flag to _v_.
|
||||
# verbose(v) { code } # Execute code with the verbose flag set
|
||||
# # temporarily to _v_. Return to the
|
||||
# # original value when code is done.
|
||||
def verbose(value=nil)
|
||||
oldvalue = FileUtilsExt.verbose_flag
|
||||
FileUtilsExt.verbose_flag = value unless value.nil?
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
FileUtilsExt.verbose_flag = oldvalue
|
||||
end
|
||||
end
|
||||
FileUtilsExt.verbose_flag
|
||||
end
|
||||
|
||||
# Get/set the nowrite flag controlling output from the FileUtils
|
||||
# utilities. If verbose is true, then the utility method is
|
||||
# echoed to standard output.
|
||||
#
|
||||
# Examples:
|
||||
# nowrite # return the current value of the
|
||||
# # nowrite flag
|
||||
# nowrite(v) # set the nowrite flag to _v_.
|
||||
# nowrite(v) { code } # Execute code with the nowrite flag set
|
||||
# # temporarily to _v_. Return to the
|
||||
# # original value when code is done.
|
||||
def nowrite(value=nil)
|
||||
oldvalue = FileUtilsExt.nowrite_flag
|
||||
FileUtilsExt.nowrite_flag = value unless value.nil?
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
FileUtilsExt.nowrite_flag = oldvalue
|
||||
end
|
||||
end
|
||||
oldvalue
|
||||
end
|
||||
|
||||
# Use this function to prevent potentially destructive ruby code
|
||||
# from running when the :nowrite flag is set.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# when_writing("Building Project") do
|
||||
# project.build
|
||||
# end
|
||||
#
|
||||
# The following code will build the project under normal
|
||||
# conditions. If the nowrite(true) flag is set, then the example
|
||||
# will print:
|
||||
#
|
||||
# DRYRUN: Building Project
|
||||
#
|
||||
# instead of actually building the project.
|
||||
#
|
||||
def when_writing(msg=nil)
|
||||
if FileUtilsExt.nowrite_flag
|
||||
$stderr.puts "DRYRUN: #{msg}" if msg
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Merge the given options with the default values.
|
||||
def rake_merge_option(args, defaults)
|
||||
if Hash === args.last
|
||||
defaults.update(args.last)
|
||||
args.pop
|
||||
end
|
||||
args.push defaults
|
||||
args
|
||||
end
|
||||
|
||||
# Send the message to the default rake output (which is $stderr).
|
||||
def rake_output_message(message)
|
||||
$stderr.puts(message)
|
||||
end
|
||||
|
||||
# Check that the options do not contain options not listed in
|
||||
# +optdecl+. An ArgumentError exception is thrown if non-declared
|
||||
# options are found.
|
||||
def rake_check_options(options, *optdecl)
|
||||
h = options.dup
|
||||
optdecl.each do |name|
|
||||
h.delete name
|
||||
end
|
||||
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless
|
||||
h.empty?
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
# TODO: Remove in Rake 11
|
||||
|
||||
fail "ERROR: 'rake/gempackagetask' is obsolete and no longer supported. " +
|
||||
"Use 'rubygems/package_task' instead."
|
|
@ -1,56 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# InvocationChain tracks the chain of task invocations to detect
|
||||
# circular dependencies.
|
||||
class InvocationChain < LinkedList
|
||||
|
||||
# Is the invocation already in the chain?
|
||||
def member?(invocation)
|
||||
head == invocation || tail.member?(invocation)
|
||||
end
|
||||
|
||||
# Append an invocation to the chain of invocations. It is an error
|
||||
# if the invocation already listed.
|
||||
def append(invocation)
|
||||
if member?(invocation)
|
||||
fail RuntimeError, "Circular dependency detected: #{to_s} => #{invocation}"
|
||||
end
|
||||
conj(invocation)
|
||||
end
|
||||
|
||||
# Convert to string, ie: TOP => invocation => invocation
|
||||
def to_s
|
||||
"#{prefix}#{head}"
|
||||
end
|
||||
|
||||
# Class level append.
|
||||
def self.append(invocation, chain)
|
||||
chain.append(invocation)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prefix
|
||||
"#{tail} => "
|
||||
end
|
||||
|
||||
# Null object for an empty chain.
|
||||
class EmptyInvocationChain < LinkedList::EmptyLinkedList
|
||||
@parent = InvocationChain
|
||||
|
||||
def member?(obj)
|
||||
false
|
||||
end
|
||||
|
||||
def append(invocation)
|
||||
conj(invocation)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"TOP"
|
||||
end
|
||||
end
|
||||
|
||||
EMPTY = EmptyInvocationChain.new
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
module Rake
|
||||
module InvocationExceptionMixin
|
||||
# Return the invocation chain (list of Rake tasks) that were in
|
||||
# effect when this exception was detected by rake. May be null if
|
||||
# no tasks were active.
|
||||
def chain
|
||||
@rake_invocation_chain ||= nil
|
||||
end
|
||||
|
||||
# Set the invocation chain in effect when this exception was
|
||||
# detected.
|
||||
def chain=(value)
|
||||
@rake_invocation_chain = value
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
module Rake
|
||||
# LateTime is a fake timestamp that occurs _after_ any other time value.
|
||||
class LateTime
|
||||
include Comparable
|
||||
include Singleton
|
||||
|
||||
def <=>(other)
|
||||
1
|
||||
end
|
||||
|
||||
def to_s
|
||||
'<LATE TIME>'
|
||||
end
|
||||
end
|
||||
|
||||
LATE = LateTime.instance
|
||||
end
|
|
@ -1,103 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Polylithic linked list structure used to implement several data
|
||||
# structures in Rake.
|
||||
class LinkedList
|
||||
include Enumerable
|
||||
|
||||
attr_reader :head, :tail
|
||||
|
||||
def initialize(head, tail=EMPTY)
|
||||
@head = head
|
||||
@tail = tail
|
||||
end
|
||||
|
||||
# Polymorphically add a new element to the head of a list. The
|
||||
# type of head node will be the same list type as the tail.
|
||||
def conj(item)
|
||||
self.class.cons(item, self)
|
||||
end
|
||||
|
||||
# Is the list empty?
|
||||
def empty?
|
||||
false
|
||||
end
|
||||
|
||||
# Lists are structurally equivalent.
|
||||
def ==(other)
|
||||
current = self
|
||||
while ! current.empty? && ! other.empty?
|
||||
return false if current.head != other.head
|
||||
current = current.tail
|
||||
other = other.tail
|
||||
end
|
||||
current.empty? && other.empty?
|
||||
end
|
||||
|
||||
# Convert to string: LL(item, item...)
|
||||
def to_s
|
||||
items = map { |item| item.to_s }.join(", ")
|
||||
"LL(#{items})"
|
||||
end
|
||||
|
||||
# Same as +to_s+, but with inspected items.
|
||||
def inspect
|
||||
items = map { |item| item.inspect }.join(", ")
|
||||
"LL(#{items})"
|
||||
end
|
||||
|
||||
# For each item in the list.
|
||||
def each
|
||||
current = self
|
||||
while ! current.empty?
|
||||
yield(current.head)
|
||||
current = current.tail
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# Make a list out of the given arguments. This method is
|
||||
# polymorphic
|
||||
def self.make(*args)
|
||||
result = empty
|
||||
args.reverse_each do |item|
|
||||
result = cons(item, result)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Cons a new head onto the tail list.
|
||||
def self.cons(head, tail)
|
||||
new(head, tail)
|
||||
end
|
||||
|
||||
# The standard empty list class for the given LinkedList class.
|
||||
def self.empty
|
||||
self::EMPTY
|
||||
end
|
||||
|
||||
# Represent an empty list, using the Null Object Pattern.
|
||||
#
|
||||
# When inheriting from the LinkedList class, you should implement
|
||||
# a type specific Empty class as well. Make sure you set the class
|
||||
# instance variable @parent to the associated list class (this
|
||||
# allows conj, cons and make to work polymorphically).
|
||||
class EmptyLinkedList < LinkedList
|
||||
@parent = LinkedList
|
||||
|
||||
def initialize
|
||||
end
|
||||
|
||||
def empty?
|
||||
true
|
||||
end
|
||||
|
||||
def self.cons(head, tail)
|
||||
@parent.cons(head, tail)
|
||||
end
|
||||
end
|
||||
|
||||
EMPTY = EmptyLinkedList.new
|
||||
end
|
||||
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Makefile loader to be used with the import file loader.
|
||||
class MakefileLoader
|
||||
include Rake::DSL
|
||||
|
||||
SPACE_MARK = "\0"
|
||||
|
||||
# Load the makefile dependencies in +fn+.
|
||||
def load(fn)
|
||||
lines = File.read fn
|
||||
lines.gsub!(/\\ /, SPACE_MARK)
|
||||
lines.gsub!(/#[^\n]*\n/m, "")
|
||||
lines.gsub!(/\\\n/, ' ')
|
||||
lines.each_line do |line|
|
||||
process_line(line)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Process one logical line of makefile data.
|
||||
def process_line(line)
|
||||
file_tasks, args = line.split(':', 2)
|
||||
return if args.nil?
|
||||
dependents = args.split.map { |d| respace(d) }
|
||||
file_tasks.scan(/\S+/) do |file_task|
|
||||
file_task = respace(file_task)
|
||||
file file_task => dependents
|
||||
end
|
||||
end
|
||||
|
||||
def respace(str)
|
||||
str.tr SPACE_MARK, ' '
|
||||
end
|
||||
end
|
||||
|
||||
# Install the handler
|
||||
Rake.application.add_loader('mf', MakefileLoader.new)
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Same as a regular task, but the immediate prerequisites are done in
|
||||
# parallel using Ruby threads.
|
||||
#
|
||||
class MultiTask < Task
|
||||
private
|
||||
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
|
||||
invoke_prerequisites_concurrently(task_args, invocation_chain)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
##
|
||||
# The NameSpace class will lookup task names in the scope defined by a
|
||||
# +namespace+ command.
|
||||
|
||||
class Rake::NameSpace
|
||||
|
||||
##
|
||||
# Create a namespace lookup object using the given task manager
|
||||
# and the list of scopes.
|
||||
|
||||
def initialize(task_manager, scope_list)
|
||||
@task_manager = task_manager
|
||||
@scope = scope_list.dup
|
||||
end
|
||||
|
||||
##
|
||||
# Lookup a task named +name+ in the namespace.
|
||||
|
||||
def [](name)
|
||||
@task_manager.lookup(name, @scope)
|
||||
end
|
||||
|
||||
##
|
||||
# The scope of the namespace (a LinkedList)
|
||||
|
||||
def scope
|
||||
@scope.dup
|
||||
end
|
||||
|
||||
##
|
||||
# Return the list of tasks defined in this and nested namespaces.
|
||||
|
||||
def tasks
|
||||
@task_manager.tasks_in_scope(@scope)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
# Define a package task library to aid in the definition of
|
||||
# redistributable package files.
|
||||
|
||||
require 'rake'
|
||||
require 'rake/tasklib'
|
||||
|
||||
module Rake
|
||||
|
||||
# Create a packaging task that will package the project into
|
||||
# distributable files (e.g zip archive or tar files).
|
||||
#
|
||||
# The PackageTask will create the following targets:
|
||||
#
|
||||
# +:package+ ::
|
||||
# Create all the requested package files.
|
||||
#
|
||||
# +:clobber_package+ ::
|
||||
# Delete all the package files. This target is automatically
|
||||
# added to the main clobber target.
|
||||
#
|
||||
# +:repackage+ ::
|
||||
# Rebuild the package files from scratch, even if they are not out
|
||||
# of date.
|
||||
#
|
||||
# <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</tt> ::
|
||||
# Create a gzipped tar package (if <em>need_tar</em> is true).
|
||||
#
|
||||
# <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</tt> ::
|
||||
# Create a gzipped tar package (if <em>need_tar_gz</em> is true).
|
||||
#
|
||||
# <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</tt> ::
|
||||
# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
|
||||
#
|
||||
# <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</tt> ::
|
||||
# Create a zip package archive (if <em>need_zip</em> is true).
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Rake::PackageTask.new("rake", "1.2.3") do |p|
|
||||
# p.need_tar = true
|
||||
# p.package_files.include("lib/**/*.rb")
|
||||
# end
|
||||
#
|
||||
class PackageTask < TaskLib
|
||||
# Name of the package (from the GEM Spec).
|
||||
attr_accessor :name
|
||||
|
||||
# Version of the package (e.g. '1.3.2').
|
||||
attr_accessor :version
|
||||
|
||||
# Directory used to store the package files (default is 'pkg').
|
||||
attr_accessor :package_dir
|
||||
|
||||
# True if a gzipped tar file (tgz) should be produced (default is
|
||||
# false).
|
||||
attr_accessor :need_tar
|
||||
|
||||
# True if a gzipped tar file (tar.gz) should be produced (default
|
||||
# is false).
|
||||
attr_accessor :need_tar_gz
|
||||
|
||||
# True if a bzip2'd tar file (tar.bz2) should be produced (default
|
||||
# is false).
|
||||
attr_accessor :need_tar_bz2
|
||||
|
||||
# True if a zip file should be produced (default is false)
|
||||
attr_accessor :need_zip
|
||||
|
||||
# List of files to be included in the package.
|
||||
attr_accessor :package_files
|
||||
|
||||
# Tar command for gzipped or bzip2ed archives. The default is 'tar'.
|
||||
attr_accessor :tar_command
|
||||
|
||||
# Zip command for zipped archives. The default is 'zip'.
|
||||
attr_accessor :zip_command
|
||||
|
||||
# Create a Package Task with the given name and version. Use +:noversion+
|
||||
# as the version to build a package without a version or to provide a
|
||||
# fully-versioned package name.
|
||||
|
||||
def initialize(name=nil, version=nil)
|
||||
init(name, version)
|
||||
yield self if block_given?
|
||||
define unless name.nil?
|
||||
end
|
||||
|
||||
# Initialization that bypasses the "yield self" and "define" step.
|
||||
def init(name, version)
|
||||
@name = name
|
||||
@version = version
|
||||
@package_files = Rake::FileList.new
|
||||
@package_dir = 'pkg'
|
||||
@need_tar = false
|
||||
@need_tar_gz = false
|
||||
@need_tar_bz2 = false
|
||||
@need_zip = false
|
||||
@tar_command = 'tar'
|
||||
@zip_command = 'zip'
|
||||
end
|
||||
|
||||
# Create the tasks defined by this task library.
|
||||
def define
|
||||
fail "Version required (or :noversion)" if @version.nil?
|
||||
@version = nil if :noversion == @version
|
||||
|
||||
desc "Build all the packages"
|
||||
task :package
|
||||
|
||||
desc "Force a rebuild of the package files"
|
||||
task :repackage => [:clobber_package, :package]
|
||||
|
||||
desc "Remove package products"
|
||||
task :clobber_package do
|
||||
rm_r package_dir rescue nil
|
||||
end
|
||||
|
||||
task :clobber => [:clobber_package]
|
||||
|
||||
[
|
||||
[need_tar, tgz_file, "z"],
|
||||
[need_tar_gz, tar_gz_file, "z"],
|
||||
[need_tar_bz2, tar_bz2_file, "j"]
|
||||
].each do |(need, file, flag)|
|
||||
if need
|
||||
task :package => ["#{package_dir}/#{file}"]
|
||||
file "#{package_dir}/#{file}" =>
|
||||
[package_dir_path] + package_files do
|
||||
chdir(package_dir) do
|
||||
sh @tar_command, "#{flag}cvf", file, package_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if need_zip
|
||||
task :package => ["#{package_dir}/#{zip_file}"]
|
||||
file "#{package_dir}/#{zip_file}" =>
|
||||
[package_dir_path] + package_files do
|
||||
chdir(package_dir) do
|
||||
sh @zip_command, "-r", zip_file, package_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
directory package_dir_path => @package_files do
|
||||
@package_files.each do |fn|
|
||||
f = File.join(package_dir_path, fn)
|
||||
fdir = File.dirname(f)
|
||||
mkdir_p(fdir) unless File.exist?(fdir)
|
||||
if File.directory?(fn)
|
||||
mkdir_p(f)
|
||||
else
|
||||
rm_f f
|
||||
safe_ln(fn, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# The name of this package
|
||||
|
||||
def package_name
|
||||
@version ? "#{@name}-#{@version}" : @name
|
||||
end
|
||||
|
||||
# The directory this package will be built in
|
||||
|
||||
def package_dir_path
|
||||
"#{package_dir}/#{package_name}"
|
||||
end
|
||||
|
||||
# The package name with .tgz added
|
||||
|
||||
def tgz_file
|
||||
"#{package_name}.tgz"
|
||||
end
|
||||
|
||||
# The package name with .tar.gz added
|
||||
|
||||
def tar_gz_file
|
||||
"#{package_name}.tar.gz"
|
||||
end
|
||||
|
||||
# The package name with .tar.bz2 added
|
||||
|
||||
def tar_bz2_file
|
||||
"#{package_name}.tar.bz2"
|
||||
end
|
||||
|
||||
# The package name with .zip added
|
||||
|
||||
def zip_file
|
||||
"#{package_name}.zip"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
# TODO: Remove in Rake 11
|
||||
|
||||
require 'rake/ext/string'
|
|
@ -1,15 +0,0 @@
|
|||
# Defines a :phony task that you can use as a dependency. This allows
|
||||
# file-based tasks to use non-file-based tasks as prerequisites
|
||||
# without forcing them to rebuild.
|
||||
#
|
||||
# See FileTask#out_of_date? and Task#timestamp for more info.
|
||||
|
||||
require 'rake'
|
||||
|
||||
task :phony
|
||||
|
||||
Rake::Task[:phony].tap do |task|
|
||||
def task.timestamp # :nodoc:
|
||||
Time.at 0
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Include PrivateReader to use +private_reader+.
|
||||
module PrivateReader # :nodoc: all
|
||||
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
# Declare a list of private accessors
|
||||
def private_reader(*names)
|
||||
attr_reader(*names)
|
||||
private(*names)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,99 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# A Promise object represents a promise to do work (a chore) in the
|
||||
# future. The promise is created with a block and a list of
|
||||
# arguments for the block. Calling value will return the value of
|
||||
# the promised chore.
|
||||
#
|
||||
# Used by ThreadPool.
|
||||
#
|
||||
class Promise # :nodoc: all
|
||||
NOT_SET = Object.new.freeze # :nodoc:
|
||||
|
||||
attr_accessor :recorder
|
||||
|
||||
# Create a promise to do the chore specified by the block.
|
||||
def initialize(args, &block)
|
||||
@mutex = Mutex.new
|
||||
@result = NOT_SET
|
||||
@error = NOT_SET
|
||||
@args = args
|
||||
@block = block
|
||||
end
|
||||
|
||||
# Return the value of this promise.
|
||||
#
|
||||
# If the promised chore is not yet complete, then do the work
|
||||
# synchronously. We will wait.
|
||||
def value
|
||||
unless complete?
|
||||
stat :sleeping_on, :item_id => object_id
|
||||
@mutex.synchronize do
|
||||
stat :has_lock_on, :item_id => object_id
|
||||
chore
|
||||
stat :releasing_lock_on, :item_id => object_id
|
||||
end
|
||||
end
|
||||
error? ? raise(@error) : @result
|
||||
end
|
||||
|
||||
# If no one else is working this promise, go ahead and do the chore.
|
||||
def work
|
||||
stat :attempting_lock_on, :item_id => object_id
|
||||
if @mutex.try_lock
|
||||
stat :has_lock_on, :item_id => object_id
|
||||
chore
|
||||
stat :releasing_lock_on, :item_id => object_id
|
||||
@mutex.unlock
|
||||
else
|
||||
stat :bailed_on, :item_id => object_id
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Perform the chore promised
|
||||
def chore
|
||||
if complete?
|
||||
stat :found_completed, :item_id => object_id
|
||||
return
|
||||
end
|
||||
stat :will_execute, :item_id => object_id
|
||||
begin
|
||||
@result = @block.call(*@args)
|
||||
rescue Exception => e
|
||||
@error = e
|
||||
end
|
||||
stat :did_execute, :item_id => object_id
|
||||
discard
|
||||
end
|
||||
|
||||
# Do we have a result for the promise
|
||||
def result?
|
||||
! @result.equal?(NOT_SET)
|
||||
end
|
||||
|
||||
# Did the promise throw an error
|
||||
def error?
|
||||
! @error.equal?(NOT_SET)
|
||||
end
|
||||
|
||||
# Are we done with the promise
|
||||
def complete?
|
||||
result? || error?
|
||||
end
|
||||
|
||||
# free up these items for the GC
|
||||
def discard
|
||||
@args = nil
|
||||
@block = nil
|
||||
end
|
||||
|
||||
# Record execution statistics if there is a recorder
|
||||
def stat(*args)
|
||||
@recorder.call(*args) if @recorder
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
module Rake
|
||||
|
||||
##
|
||||
# Exit status class for times the system just gives us a nil.
|
||||
class PseudoStatus # :nodoc: all
|
||||
attr_reader :exitstatus
|
||||
|
||||
def initialize(code=0)
|
||||
@exitstatus = code
|
||||
end
|
||||
|
||||
def to_i
|
||||
@exitstatus << 8
|
||||
end
|
||||
|
||||
def >>(n)
|
||||
to_i >> n
|
||||
end
|
||||
|
||||
def stopped?
|
||||
false
|
||||
end
|
||||
|
||||
def exited?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
require 'rake/application'
|
||||
|
||||
module Rake
|
||||
|
||||
class << self
|
||||
# Current Rake Application
|
||||
def application
|
||||
@application ||= Rake::Application.new
|
||||
end
|
||||
|
||||
# Set the current Rake application object.
|
||||
def application=(app)
|
||||
@application = app
|
||||
end
|
||||
|
||||
def suggested_thread_count # :nodoc:
|
||||
@cpu_count ||= Rake::CpuCounter.count
|
||||
@cpu_count + 4
|
||||
end
|
||||
|
||||
# Return the original directory where the Rake application was started.
|
||||
def original_dir
|
||||
application.original_dir
|
||||
end
|
||||
|
||||
# Load a rakefile.
|
||||
def load_rakefile(path)
|
||||
load(path)
|
||||
end
|
||||
|
||||
# Add files to the rakelib list
|
||||
def add_rakelib(*files)
|
||||
application.options.rakelib ||= []
|
||||
application.options.rakelib.concat(files)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'rake'
|
||||
|
||||
# Load the test files from the command line.
|
||||
argv = ARGV.select do |argument|
|
||||
case argument
|
||||
when /^-/ then
|
||||
argument
|
||||
when /\*/ then
|
||||
FileList[argument].to_a.each do |file|
|
||||
require File.expand_path file
|
||||
end
|
||||
|
||||
false
|
||||
else
|
||||
require File.expand_path argument
|
||||
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
ARGV.replace argv
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
# TODO: Remove in Rake 11
|
||||
|
||||
fail "ERROR: 'rake/rdoctask' is obsolete and no longer supported. " +
|
||||
"Use 'rdoc/task' (available in RDoc 2.4.2+) instead."
|
|
@ -1,29 +0,0 @@
|
|||
# TODO: Remove in rake 11
|
||||
|
||||
# Local Rake override to fix bug in Ruby 0.8.2
|
||||
module Test # :nodoc:
|
||||
# Local Rake override to fix bug in Ruby 0.8.2
|
||||
module Unit # :nodoc:
|
||||
# Local Rake override to fix bug in Ruby 0.8.2
|
||||
module Collector # :nodoc:
|
||||
# Local Rake override to fix bug in Ruby 0.8.2
|
||||
class Dir # :nodoc:
|
||||
undef collect_file
|
||||
def collect_file(name, suites, already_gathered) # :nodoc:
|
||||
dir = File.dirname(File.expand_path(name))
|
||||
$:.unshift(dir) unless $:.first == dir
|
||||
if @req
|
||||
@req.require(name)
|
||||
else
|
||||
require(name)
|
||||
end
|
||||
find_test_cases(already_gathered).each do |t|
|
||||
add_suite(suites, t.suite)
|
||||
end
|
||||
ensure
|
||||
$:.delete_at $:.rindex(dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
module Rake
|
||||
|
||||
# Error indicating a recursion overflow error in task selection.
|
||||
class RuleRecursionOverflowError < StandardError
|
||||
def initialize(*args)
|
||||
super
|
||||
@targets = []
|
||||
end
|
||||
|
||||
def add_target(target)
|
||||
@targets << target
|
||||
end
|
||||
|
||||
def message
|
||||
super + ": [" + @targets.reverse.join(' => ') + "]"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
require 'test/unit'
|
||||
require 'test/unit/assertions'
|
||||
require 'rake/file_list'
|
||||
|
||||
module Rake
|
||||
include Test::Unit::Assertions
|
||||
|
||||
##
|
||||
# Deprecated way of running tests in process, but only for Test::Unit.
|
||||
#--
|
||||
# TODO: Remove in rake 11
|
||||
|
||||
def run_tests(pattern='test/test*.rb', log_enabled=false) # :nodoc:
|
||||
FileList.glob(pattern).each do |fn|
|
||||
$stderr.puts fn if log_enabled
|
||||
begin
|
||||
require fn
|
||||
rescue Exception => ex
|
||||
$stderr.puts "Error in #{fn}: #{ex.message}"
|
||||
$stderr.puts ex.backtrace
|
||||
assert false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
module Rake
|
||||
class Scope < LinkedList # :nodoc: all
|
||||
|
||||
# Path for the scope.
|
||||
def path
|
||||
map { |item| item.to_s }.reverse.join(":")
|
||||
end
|
||||
|
||||
# Path for the scope + the named path.
|
||||
def path_with_task_name(task_name)
|
||||
"#{path}:#{task_name}"
|
||||
end
|
||||
|
||||
# Trim +n+ innermost scope levels from the scope. In no case will
|
||||
# this trim beyond the toplevel scope.
|
||||
def trim(n)
|
||||
result = self
|
||||
while n > 0 && ! result.empty?
|
||||
result = result.tail
|
||||
n -= 1
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Scope lists always end with an EmptyScope object. See Null
|
||||
# Object Pattern)
|
||||
class EmptyScope < EmptyLinkedList
|
||||
@parent = Scope
|
||||
|
||||
def path
|
||||
""
|
||||
end
|
||||
|
||||
def path_with_task_name(task_name)
|
||||
task_name
|
||||
end
|
||||
end
|
||||
|
||||
# Singleton null object for an empty scope.
|
||||
EMPTY = EmptyScope.new
|
||||
end
|
||||
end
|
383
lib/rake/task.rb
383
lib/rake/task.rb
|
@ -1,383 +0,0 @@
|
|||
require 'rake/invocation_exception_mixin'
|
||||
|
||||
module Rake
|
||||
|
||||
##
|
||||
# A Task is the basic unit of work in a Rakefile. Tasks have associated
|
||||
# actions (possibly more than one) and a list of prerequisites. When
|
||||
# invoked, a task will first ensure that all of its prerequisites have an
|
||||
# opportunity to run and then it will execute its own actions.
|
||||
#
|
||||
# Tasks are not usually created directly using the new method, but rather
|
||||
# use the +file+ and +task+ convenience methods.
|
||||
#
|
||||
class Task
|
||||
# List of prerequisites for a task.
|
||||
attr_reader :prerequisites
|
||||
|
||||
# List of actions attached to a task.
|
||||
attr_reader :actions
|
||||
|
||||
# Application owning this task.
|
||||
attr_accessor :application
|
||||
|
||||
# Array of nested namespaces names used for task lookup by this task.
|
||||
attr_reader :scope
|
||||
|
||||
# File/Line locations of each of the task definitions for this
|
||||
# task (only valid if the task was defined with the detect
|
||||
# location option set).
|
||||
attr_reader :locations
|
||||
|
||||
# Return task name
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def inspect # :nodoc:
|
||||
"<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
|
||||
end
|
||||
|
||||
# List of sources for task.
|
||||
attr_writer :sources
|
||||
def sources
|
||||
if defined?(@sources)
|
||||
@sources
|
||||
else
|
||||
prerequisites
|
||||
end
|
||||
end
|
||||
|
||||
# List of prerequisite tasks
|
||||
def prerequisite_tasks
|
||||
prerequisites.map { |pre| lookup_prerequisite(pre) }
|
||||
end
|
||||
|
||||
def lookup_prerequisite(prerequisite_name) # :nodoc:
|
||||
application[prerequisite_name, @scope]
|
||||
end
|
||||
private :lookup_prerequisite
|
||||
|
||||
# List of all unique prerequisite tasks including prerequisite tasks'
|
||||
# prerequisites.
|
||||
# Includes self when cyclic dependencies are found.
|
||||
def all_prerequisite_tasks
|
||||
seen = {}
|
||||
collect_prerequisites(seen)
|
||||
seen.values
|
||||
end
|
||||
|
||||
def collect_prerequisites(seen) # :nodoc:
|
||||
prerequisite_tasks.each do |pre|
|
||||
next if seen[pre.name]
|
||||
seen[pre.name] = pre
|
||||
pre.collect_prerequisites(seen)
|
||||
end
|
||||
end
|
||||
protected :collect_prerequisites
|
||||
|
||||
# First source from a rule (nil if no sources)
|
||||
def source
|
||||
sources.first
|
||||
end
|
||||
|
||||
# Create a task named +task_name+ with no actions or prerequisites. Use
|
||||
# +enhance+ to add actions and prerequisites.
|
||||
def initialize(task_name, app)
|
||||
@name = task_name.to_s
|
||||
@prerequisites = []
|
||||
@actions = []
|
||||
@already_invoked = false
|
||||
@comments = []
|
||||
@lock = Monitor.new
|
||||
@application = app
|
||||
@scope = app.current_scope
|
||||
@arg_names = nil
|
||||
@locations = []
|
||||
end
|
||||
|
||||
# Enhance a task with prerequisites or actions. Returns self.
|
||||
def enhance(deps=nil, &block)
|
||||
@prerequisites |= deps if deps
|
||||
@actions << block if block_given?
|
||||
self
|
||||
end
|
||||
|
||||
# Name of the task, including any namespace qualifiers.
|
||||
def name
|
||||
@name.to_s
|
||||
end
|
||||
|
||||
# Name of task with argument list description.
|
||||
def name_with_args # :nodoc:
|
||||
if arg_description
|
||||
"#{name}#{arg_description}"
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
# Argument description (nil if none).
|
||||
def arg_description # :nodoc:
|
||||
@arg_names ? "[#{arg_names.join(',')}]" : nil
|
||||
end
|
||||
|
||||
# Name of arguments for this task.
|
||||
def arg_names
|
||||
@arg_names || []
|
||||
end
|
||||
|
||||
# Reenable the task, allowing its tasks to be executed if the task
|
||||
# is invoked again.
|
||||
def reenable
|
||||
@already_invoked = false
|
||||
end
|
||||
|
||||
# Clear the existing prerequisites and actions of a rake task.
|
||||
def clear
|
||||
clear_prerequisites
|
||||
clear_actions
|
||||
clear_comments
|
||||
self
|
||||
end
|
||||
|
||||
# Clear the existing prerequisites of a rake task.
|
||||
def clear_prerequisites
|
||||
prerequisites.clear
|
||||
self
|
||||
end
|
||||
|
||||
# Clear the existing actions on a rake task.
|
||||
def clear_actions
|
||||
actions.clear
|
||||
self
|
||||
end
|
||||
|
||||
# Clear the existing comments on a rake task.
|
||||
def clear_comments
|
||||
@comments = []
|
||||
self
|
||||
end
|
||||
|
||||
# Invoke the task if it is needed. Prerequisites are invoked first.
|
||||
def invoke(*args)
|
||||
task_args = TaskArguments.new(arg_names, args)
|
||||
invoke_with_call_chain(task_args, InvocationChain::EMPTY)
|
||||
end
|
||||
|
||||
# Same as invoke, but explicitly pass a call chain to detect
|
||||
# circular dependencies.
|
||||
def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
|
||||
new_chain = InvocationChain.append(self, invocation_chain)
|
||||
@lock.synchronize do
|
||||
if application.options.trace
|
||||
application.trace "** Invoke #{name} #{format_trace_flags}"
|
||||
end
|
||||
return if @already_invoked
|
||||
@already_invoked = true
|
||||
invoke_prerequisites(task_args, new_chain)
|
||||
execute(task_args) if needed?
|
||||
end
|
||||
rescue Exception => ex
|
||||
add_chain_to(ex, new_chain)
|
||||
raise ex
|
||||
end
|
||||
protected :invoke_with_call_chain
|
||||
|
||||
def add_chain_to(exception, new_chain) # :nodoc:
|
||||
exception.extend(InvocationExceptionMixin) unless
|
||||
exception.respond_to?(:chain)
|
||||
exception.chain = new_chain if exception.chain.nil?
|
||||
end
|
||||
private :add_chain_to
|
||||
|
||||
# Invoke all the prerequisites of a task.
|
||||
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
|
||||
if application.options.always_multitask
|
||||
invoke_prerequisites_concurrently(task_args, invocation_chain)
|
||||
else
|
||||
prerequisite_tasks.each { |p|
|
||||
prereq_args = task_args.new_scope(p.arg_names)
|
||||
p.invoke_with_call_chain(prereq_args, invocation_chain)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Invoke all the prerequisites of a task in parallel.
|
||||
def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc:
|
||||
futures = prerequisite_tasks.map do |p|
|
||||
prereq_args = task_args.new_scope(p.arg_names)
|
||||
application.thread_pool.future(p) do |r|
|
||||
r.invoke_with_call_chain(prereq_args, invocation_chain)
|
||||
end
|
||||
end
|
||||
futures.each { |f| f.value }
|
||||
end
|
||||
|
||||
# Format the trace flags for display.
|
||||
def format_trace_flags
|
||||
flags = []
|
||||
flags << "first_time" unless @already_invoked
|
||||
flags << "not_needed" unless needed?
|
||||
flags.empty? ? "" : "(" + flags.join(", ") + ")"
|
||||
end
|
||||
private :format_trace_flags
|
||||
|
||||
# Execute the actions associated with this task.
|
||||
def execute(args=nil)
|
||||
args ||= EMPTY_TASK_ARGS
|
||||
if application.options.dryrun
|
||||
application.trace "** Execute (dry run) #{name}"
|
||||
return
|
||||
end
|
||||
application.trace "** Execute #{name}" if application.options.trace
|
||||
application.enhance_with_matching_rule(name) if @actions.empty?
|
||||
@actions.each do |act|
|
||||
case act.arity
|
||||
when 1
|
||||
act.call(self)
|
||||
else
|
||||
act.call(self, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Is this task needed?
|
||||
def needed?
|
||||
true
|
||||
end
|
||||
|
||||
# Timestamp for this task. Basic tasks return the current time for their
|
||||
# time stamp. Other tasks can be more sophisticated.
|
||||
def timestamp
|
||||
Time.now
|
||||
end
|
||||
|
||||
# Add a description to the task. The description can consist of an option
|
||||
# argument list (enclosed brackets) and an optional comment.
|
||||
def add_description(description)
|
||||
return unless description
|
||||
comment = description.strip
|
||||
add_comment(comment) if comment && ! comment.empty?
|
||||
end
|
||||
|
||||
def comment=(comment) # :nodoc:
|
||||
add_comment(comment)
|
||||
end
|
||||
|
||||
def add_comment(comment) # :nodoc:
|
||||
return if comment.nil?
|
||||
@comments << comment unless @comments.include?(comment)
|
||||
end
|
||||
private :add_comment
|
||||
|
||||
# Full collection of comments. Multiple comments are separated by
|
||||
# newlines.
|
||||
def full_comment
|
||||
transform_comments("\n")
|
||||
end
|
||||
|
||||
# First line (or sentence) of all comments. Multiple comments are
|
||||
# separated by a "/".
|
||||
def comment
|
||||
transform_comments(" / ") { |c| first_sentence(c) }
|
||||
end
|
||||
|
||||
# Transform the list of comments as specified by the block and
|
||||
# join with the separator.
|
||||
def transform_comments(separator, &block)
|
||||
if @comments.empty?
|
||||
nil
|
||||
else
|
||||
block ||= lambda { |c| c }
|
||||
@comments.map(&block).join(separator)
|
||||
end
|
||||
end
|
||||
private :transform_comments
|
||||
|
||||
# Get the first sentence in a string. The sentence is terminated
|
||||
# by the first period or the end of the line. Decimal points do
|
||||
# not count as periods.
|
||||
def first_sentence(string)
|
||||
string.split(/\.[ \t]|\.$|\n/).first
|
||||
end
|
||||
private :first_sentence
|
||||
|
||||
# Set the names of the arguments for this task. +args+ should be
|
||||
# an array of symbols, one for each argument name.
|
||||
def set_arg_names(args)
|
||||
@arg_names = args.map { |a| a.to_sym }
|
||||
end
|
||||
|
||||
# Return a string describing the internal state of a task. Useful for
|
||||
# debugging.
|
||||
def investigation
|
||||
result = "------------------------------\n"
|
||||
result << "Investigating #{name}\n"
|
||||
result << "class: #{self.class}\n"
|
||||
result << "task needed: #{needed?}\n"
|
||||
result << "timestamp: #{timestamp}\n"
|
||||
result << "pre-requisites: \n"
|
||||
prereqs = prerequisite_tasks
|
||||
prereqs.sort! { |a, b| a.timestamp <=> b.timestamp }
|
||||
prereqs.each do |p|
|
||||
result << "--#{p.name} (#{p.timestamp})\n"
|
||||
end
|
||||
latest_prereq = prerequisite_tasks.map { |pre| pre.timestamp }.max
|
||||
result << "latest-prerequisite time: #{latest_prereq}\n"
|
||||
result << "................................\n\n"
|
||||
return result
|
||||
end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Rake Module Methods
|
||||
#
|
||||
class << self
|
||||
|
||||
# Clear the task list. This cause rake to immediately forget all the
|
||||
# tasks that have been assigned. (Normally used in the unit tests.)
|
||||
def clear
|
||||
Rake.application.clear
|
||||
end
|
||||
|
||||
# List of all defined tasks.
|
||||
def tasks
|
||||
Rake.application.tasks
|
||||
end
|
||||
|
||||
# Return a task with the given name. If the task is not currently
|
||||
# known, try to synthesize one from the defined rules. If no rules are
|
||||
# found, but an existing file matches the task name, assume it is a file
|
||||
# task with no dependencies or actions.
|
||||
def [](task_name)
|
||||
Rake.application[task_name]
|
||||
end
|
||||
|
||||
# TRUE if the task name is already defined.
|
||||
def task_defined?(task_name)
|
||||
Rake.application.lookup(task_name) != nil
|
||||
end
|
||||
|
||||
# Define a task given +args+ and an option block. If a rule with the
|
||||
# given name already exists, the prerequisites and actions are added to
|
||||
# the existing task. Returns the defined task.
|
||||
def define_task(*args, &block)
|
||||
Rake.application.define_task(self, *args, &block)
|
||||
end
|
||||
|
||||
# Define a rule for synthesizing tasks.
|
||||
def create_rule(*args, &block)
|
||||
Rake.application.create_rule(*args, &block)
|
||||
end
|
||||
|
||||
# Apply the scope to the task name according to the rules for
|
||||
# this kind of task. Generic tasks will accept the scope as
|
||||
# part of the name.
|
||||
def scope_name(scope, task_name)
|
||||
# (scope + [task_name]).join(':')
|
||||
scope.path_with_task_name(task_name)
|
||||
end
|
||||
|
||||
end # class << Rake::Task
|
||||
end # class Rake::Task
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# Error indicating an ill-formed task declaration.
|
||||
class TaskArgumentError < ArgumentError
|
||||
end
|
||||
|
||||
end
|
|
@ -1,98 +0,0 @@
|
|||
module Rake
|
||||
|
||||
##
|
||||
# TaskArguments manage the arguments passed to a task.
|
||||
#
|
||||
class TaskArguments
|
||||
include Enumerable
|
||||
|
||||
# Argument names
|
||||
attr_reader :names
|
||||
|
||||
# Create a TaskArgument object with a list of argument +names+ and a set
|
||||
# of associated +values+. +parent+ is the parent argument object.
|
||||
def initialize(names, values, parent=nil)
|
||||
@names = names
|
||||
@parent = parent
|
||||
@hash = {}
|
||||
@values = values
|
||||
names.each_with_index { |name, i|
|
||||
@hash[name.to_sym] = values[i] unless values[i].nil?
|
||||
}
|
||||
end
|
||||
|
||||
# Retrieve the complete array of sequential values
|
||||
def to_a
|
||||
@values.dup
|
||||
end
|
||||
|
||||
# Retrieve the list of values not associated with named arguments
|
||||
def extras
|
||||
@values[@names.length..-1] || []
|
||||
end
|
||||
|
||||
# Create a new argument scope using the prerequisite argument
|
||||
# names.
|
||||
def new_scope(names)
|
||||
values = names.map { |n| self[n] }
|
||||
self.class.new(names, values + extras, self)
|
||||
end
|
||||
|
||||
# Find an argument value by name or index.
|
||||
def [](index)
|
||||
lookup(index.to_sym)
|
||||
end
|
||||
|
||||
# Specify a hash of default values for task arguments. Use the
|
||||
# defaults only if there is no specific value for the given
|
||||
# argument.
|
||||
def with_defaults(defaults)
|
||||
@hash = defaults.merge(@hash)
|
||||
end
|
||||
|
||||
# Enumerates the arguments and their values
|
||||
def each(&block)
|
||||
@hash.each(&block)
|
||||
end
|
||||
|
||||
# Extracts the argument values at +keys+
|
||||
def values_at(*keys)
|
||||
keys.map { |k| lookup(k) }
|
||||
end
|
||||
|
||||
# Returns the value of the given argument via method_missing
|
||||
def method_missing(sym, *args)
|
||||
lookup(sym.to_sym)
|
||||
end
|
||||
|
||||
# Returns a Hash of arguments and their values
|
||||
def to_hash
|
||||
@hash
|
||||
end
|
||||
|
||||
def to_s # :nodoc:
|
||||
@hash.inspect
|
||||
end
|
||||
|
||||
def inspect # :nodoc:
|
||||
to_s
|
||||
end
|
||||
|
||||
# Returns true if +key+ is one of the arguments
|
||||
def has_key?(key)
|
||||
@hash.has_key?(key)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def lookup(name) # :nodoc:
|
||||
if @hash.has_key?(name)
|
||||
@hash[name]
|
||||
elsif @parent
|
||||
@parent.lookup(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
|
||||
end
|
|
@ -1,307 +0,0 @@
|
|||
module Rake
|
||||
|
||||
# The TaskManager module is a mixin for managing tasks.
|
||||
module TaskManager
|
||||
# Track the last comment made in the Rakefile.
|
||||
attr_accessor :last_description
|
||||
|
||||
# TODO: Remove in Rake 11
|
||||
|
||||
alias :last_comment :last_description # :nodoc: Backwards compatibility
|
||||
|
||||
def initialize # :nodoc:
|
||||
super
|
||||
@tasks = Hash.new
|
||||
@rules = Array.new
|
||||
@scope = Scope.make
|
||||
@last_description = nil
|
||||
end
|
||||
|
||||
def create_rule(*args, &block) # :nodoc:
|
||||
pattern, args, deps = resolve_args(args)
|
||||
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
|
||||
@rules << [pattern, args, deps, block]
|
||||
end
|
||||
|
||||
def define_task(task_class, *args, &block) # :nodoc:
|
||||
task_name, arg_names, deps = resolve_args(args)
|
||||
|
||||
original_scope = @scope
|
||||
if String === task_name and
|
||||
not task_class.ancestors.include? Rake::FileTask then
|
||||
task_name, *definition_scope = *(task_name.split(":").reverse)
|
||||
@scope = Scope.make(*(definition_scope + @scope.to_a))
|
||||
end
|
||||
|
||||
task_name = task_class.scope_name(@scope, task_name)
|
||||
deps = [deps] unless deps.respond_to?(:to_ary)
|
||||
deps = deps.map { |d| Rake.from_pathname(d).to_s }
|
||||
task = intern(task_class, task_name)
|
||||
task.set_arg_names(arg_names) unless arg_names.empty?
|
||||
if Rake::TaskManager.record_task_metadata
|
||||
add_location(task)
|
||||
task.add_description(get_description(task))
|
||||
end
|
||||
task.enhance(deps, &block)
|
||||
ensure
|
||||
@scope = original_scope
|
||||
end
|
||||
|
||||
# Lookup a task. Return an existing task if found, otherwise
|
||||
# create a task of the current type.
|
||||
def intern(task_class, task_name)
|
||||
@tasks[task_name.to_s] ||= task_class.new(task_name, self)
|
||||
end
|
||||
|
||||
# Find a matching task for +task_name+.
|
||||
def [](task_name, scopes=nil)
|
||||
task_name = task_name.to_s
|
||||
self.lookup(task_name, scopes) or
|
||||
enhance_with_matching_rule(task_name) or
|
||||
synthesize_file_task(task_name) or
|
||||
fail "Don't know how to build task '#{task_name}'"
|
||||
end
|
||||
|
||||
def synthesize_file_task(task_name) # :nodoc:
|
||||
return nil unless File.exist?(task_name)
|
||||
define_task(Rake::FileTask, task_name)
|
||||
end
|
||||
|
||||
# Resolve the arguments for a task/rule. Returns a triplet of
|
||||
# [task_name, arg_name_list, prerequisites].
|
||||
def resolve_args(args)
|
||||
if args.last.is_a?(Hash)
|
||||
deps = args.pop
|
||||
resolve_args_with_dependencies(args, deps)
|
||||
else
|
||||
resolve_args_without_dependencies(args)
|
||||
end
|
||||
end
|
||||
|
||||
# Resolve task arguments for a task or rule when there are no
|
||||
# dependencies declared.
|
||||
#
|
||||
# The patterns recognized by this argument resolving function are:
|
||||
#
|
||||
# task :t
|
||||
# task :t, [:a]
|
||||
#
|
||||
def resolve_args_without_dependencies(args)
|
||||
task_name = args.shift
|
||||
if args.size == 1 && args.first.respond_to?(:to_ary)
|
||||
arg_names = args.first.to_ary
|
||||
else
|
||||
arg_names = args
|
||||
end
|
||||
[task_name, arg_names, []]
|
||||
end
|
||||
private :resolve_args_without_dependencies
|
||||
|
||||
# Resolve task arguments for a task or rule when there are
|
||||
# dependencies declared.
|
||||
#
|
||||
# The patterns recognized by this argument resolving function are:
|
||||
#
|
||||
# task :t => [:d]
|
||||
# task :t, [a] => [:d]
|
||||
#
|
||||
def resolve_args_with_dependencies(args, hash) # :nodoc:
|
||||
fail "Task Argument Error" if hash.size != 1
|
||||
key, value = hash.map { |k, v| [k, v] }.first
|
||||
if args.empty?
|
||||
task_name = key
|
||||
arg_names = []
|
||||
deps = value || []
|
||||
else
|
||||
task_name = args.shift
|
||||
arg_names = key
|
||||
deps = value
|
||||
end
|
||||
deps = [deps] unless deps.respond_to?(:to_ary)
|
||||
[task_name, arg_names, deps]
|
||||
end
|
||||
private :resolve_args_with_dependencies
|
||||
|
||||
# If a rule can be found that matches the task name, enhance the
|
||||
# task with the prerequisites and actions from the rule. Set the
|
||||
# source attribute of the task appropriately for the rule. Return
|
||||
# the enhanced task or nil of no rule was found.
|
||||
def enhance_with_matching_rule(task_name, level=0)
|
||||
fail Rake::RuleRecursionOverflowError,
|
||||
"Rule Recursion Too Deep" if level >= 16
|
||||
@rules.each do |pattern, args, extensions, block|
|
||||
if pattern.match(task_name)
|
||||
task = attempt_rule(task_name, args, extensions, block, level)
|
||||
return task if task
|
||||
end
|
||||
end
|
||||
nil
|
||||
rescue Rake::RuleRecursionOverflowError => ex
|
||||
ex.add_target(task_name)
|
||||
fail ex
|
||||
end
|
||||
|
||||
# List of all defined tasks in this application.
|
||||
def tasks
|
||||
@tasks.values.sort_by { |t| t.name }
|
||||
end
|
||||
|
||||
# List of all the tasks defined in the given scope (and its
|
||||
# sub-scopes).
|
||||
def tasks_in_scope(scope)
|
||||
prefix = scope.path
|
||||
tasks.select { |t|
|
||||
/^#{prefix}:/ =~ t.name
|
||||
}
|
||||
end
|
||||
|
||||
# Clear all tasks in this application.
|
||||
def clear
|
||||
@tasks.clear
|
||||
@rules.clear
|
||||
end
|
||||
|
||||
# Lookup a task, using scope and the scope hints in the task name.
|
||||
# This method performs straight lookups without trying to
|
||||
# synthesize file tasks or rules. Special scope names (e.g. '^')
|
||||
# are recognized. If no scope argument is supplied, use the
|
||||
# current scope. Return nil if the task cannot be found.
|
||||
def lookup(task_name, initial_scope=nil)
|
||||
initial_scope ||= @scope
|
||||
task_name = task_name.to_s
|
||||
if task_name =~ /^rake:/
|
||||
scopes = Scope.make
|
||||
task_name = task_name.sub(/^rake:/, '')
|
||||
elsif task_name =~ /^(\^+)/
|
||||
scopes = initial_scope.trim($1.size)
|
||||
task_name = task_name.sub(/^(\^+)/, '')
|
||||
else
|
||||
scopes = initial_scope
|
||||
end
|
||||
lookup_in_scope(task_name, scopes)
|
||||
end
|
||||
|
||||
# Lookup the task name
|
||||
def lookup_in_scope(name, scope)
|
||||
loop do
|
||||
tn = scope.path_with_task_name(name)
|
||||
task = @tasks[tn]
|
||||
return task if task
|
||||
break if scope.empty?
|
||||
scope = scope.tail
|
||||
end
|
||||
nil
|
||||
end
|
||||
private :lookup_in_scope
|
||||
|
||||
# Return the list of scope names currently active in the task
|
||||
# manager.
|
||||
def current_scope
|
||||
@scope
|
||||
end
|
||||
|
||||
# Evaluate the block in a nested namespace named +name+. Create
|
||||
# an anonymous namespace if +name+ is nil.
|
||||
def in_namespace(name)
|
||||
name ||= generate_name
|
||||
@scope = Scope.new(name, @scope)
|
||||
ns = NameSpace.new(self, @scope)
|
||||
yield(ns)
|
||||
ns
|
||||
ensure
|
||||
@scope = @scope.tail
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Add a location to the locations field of the given task.
|
||||
def add_location(task)
|
||||
loc = find_location
|
||||
task.locations << loc if loc
|
||||
task
|
||||
end
|
||||
|
||||
# Find the location that called into the dsl layer.
|
||||
def find_location
|
||||
locations = caller
|
||||
i = 0
|
||||
while locations[i]
|
||||
return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
|
||||
i += 1
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# Generate an anonymous namespace name.
|
||||
def generate_name
|
||||
@seed ||= 0
|
||||
@seed += 1
|
||||
"_anon_#{@seed}"
|
||||
end
|
||||
|
||||
def trace_rule(level, message) # :nodoc:
|
||||
options.trace_output.puts "#{" " * level}#{message}" if
|
||||
Rake.application.options.trace_rules
|
||||
end
|
||||
|
||||
# Attempt to create a rule given the list of prerequisites.
|
||||
def attempt_rule(task_name, args, extensions, block, level)
|
||||
sources = make_sources(task_name, extensions)
|
||||
prereqs = sources.map { |source|
|
||||
trace_rule level, "Attempting Rule #{task_name} => #{source}"
|
||||
if File.exist?(source) || Rake::Task.task_defined?(source)
|
||||
trace_rule level, "(#{task_name} => #{source} ... EXIST)"
|
||||
source
|
||||
elsif parent = enhance_with_matching_rule(source, level + 1)
|
||||
trace_rule level, "(#{task_name} => #{source} ... ENHANCE)"
|
||||
parent.name
|
||||
else
|
||||
trace_rule level, "(#{task_name} => #{source} ... FAIL)"
|
||||
return nil
|
||||
end
|
||||
}
|
||||
task = FileTask.define_task(task_name, {args => prereqs}, &block)
|
||||
task.sources = prereqs
|
||||
task
|
||||
end
|
||||
|
||||
# Make a list of sources from the list of file name extensions /
|
||||
# translation procs.
|
||||
def make_sources(task_name, extensions)
|
||||
result = extensions.map { |ext|
|
||||
case ext
|
||||
when /%/
|
||||
task_name.pathmap(ext)
|
||||
when %r{/}
|
||||
ext
|
||||
when /^\./
|
||||
task_name.ext(ext)
|
||||
when String
|
||||
ext
|
||||
when Proc, Method
|
||||
if ext.arity == 1
|
||||
ext.call(task_name)
|
||||
else
|
||||
ext.call
|
||||
end
|
||||
else
|
||||
fail "Don't know how to handle rule dependent: #{ext.inspect}"
|
||||
end
|
||||
}
|
||||
result.flatten
|
||||
end
|
||||
|
||||
# Return the current description, clearing it in the process.
|
||||
def get_description(task)
|
||||
desc = @last_description
|
||||
@last_description = nil
|
||||
desc
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_accessor :record_task_metadata # :nodoc:
|
||||
TaskManager.record_task_metadata = false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
require 'rake'
|
||||
|
||||
module Rake
|
||||
|
||||
# Base class for Task Libraries.
|
||||
class TaskLib
|
||||
include Cloneable
|
||||
include Rake::DSL
|
||||
|
||||
# Make a symbol by pasting two strings together.
|
||||
#
|
||||
# NOTE: DEPRECATED! This method is kinda stupid. I don't know why
|
||||
# I didn't just use string interpolation. But now other task
|
||||
# libraries depend on this so I can't remove it without breaking
|
||||
# other people's code. So for now it stays for backwards
|
||||
# compatibility. BUT DON'T USE IT.
|
||||
#--
|
||||
# TODO: Remove in Rake 11
|
||||
def paste(a, b) # :nodoc:
|
||||
(a.to_s + b.to_s).intern
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,212 +0,0 @@
|
|||
require 'rake'
|
||||
require 'rake/tasklib'
|
||||
|
||||
module Rake
|
||||
|
||||
# Create a task that runs a set of tests.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# Rake::TestTask.new do |t|
|
||||
# t.libs << "test"
|
||||
# t.test_files = FileList['test/test*.rb']
|
||||
# t.verbose = true
|
||||
# end
|
||||
#
|
||||
# If rake is invoked with a "TEST=filename" command line option,
|
||||
# then the list of test files will be overridden to include only the
|
||||
# filename specified on the command line. This provides an easy way
|
||||
# to run just one test.
|
||||
#
|
||||
# If rake is invoked with a "TESTOPTS=options" command line option,
|
||||
# then the given options are passed to the test process after a
|
||||
# '--'. This allows Test::Unit options to be passed to the test
|
||||
# suite.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# rake test # run tests normally
|
||||
# rake test TEST=just_one_file.rb # run just one test file.
|
||||
# rake test TESTOPTS="-v" # run in verbose mode
|
||||
# rake test TESTOPTS="--runner=fox" # use the fox test runner
|
||||
#
|
||||
class TestTask < TaskLib
|
||||
|
||||
# Name of test task. (default is :test)
|
||||
attr_accessor :name
|
||||
|
||||
# List of directories to added to $LOAD_PATH before running the
|
||||
# tests. (default is 'lib')
|
||||
attr_accessor :libs
|
||||
|
||||
# True if verbose test output desired. (default is false)
|
||||
attr_accessor :verbose
|
||||
|
||||
# Test options passed to the test suite. An explicit
|
||||
# TESTOPTS=opts on the command line will override this. (default
|
||||
# is NONE)
|
||||
attr_accessor :options
|
||||
|
||||
# Request that the tests be run with the warning flag set.
|
||||
# E.g. warning=true implies "ruby -w" used to run the tests.
|
||||
attr_accessor :warning
|
||||
|
||||
# Glob pattern to match test files. (default is 'test/test*.rb')
|
||||
attr_accessor :pattern
|
||||
|
||||
# Style of test loader to use. Options are:
|
||||
#
|
||||
# * :rake -- Rake provided test loading script (default).
|
||||
# * :testrb -- Ruby provided test loading script.
|
||||
# * :direct -- Load tests using command line loader.
|
||||
#
|
||||
attr_accessor :loader
|
||||
|
||||
# Array of command line options to pass to ruby when running test loader.
|
||||
attr_accessor :ruby_opts
|
||||
|
||||
# Description of the test task. (default is 'Run tests')
|
||||
attr_accessor :description
|
||||
|
||||
# Explicitly define the list of test files to be included in a
|
||||
# test. +list+ is expected to be an array of file names (a
|
||||
# FileList is acceptable). If both +pattern+ and +test_files+ are
|
||||
# used, then the list of test files is the union of the two.
|
||||
def test_files=(list)
|
||||
@test_files = list
|
||||
end
|
||||
|
||||
# Create a testing task.
|
||||
def initialize(name=:test)
|
||||
@name = name
|
||||
@libs = ["lib"]
|
||||
@pattern = nil
|
||||
@options = nil
|
||||
@test_files = nil
|
||||
@verbose = false
|
||||
@warning = false
|
||||
@loader = :rake
|
||||
@ruby_opts = []
|
||||
@description = "Run tests" + (@name == :test ? "" : " for #{@name}")
|
||||
yield self if block_given?
|
||||
@pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
|
||||
define
|
||||
end
|
||||
|
||||
# Create the tasks defined by this task lib.
|
||||
def define
|
||||
desc @description
|
||||
task @name do
|
||||
FileUtilsExt.verbose(@verbose) do
|
||||
args =
|
||||
"#{ruby_opts_string} #{run_code} " +
|
||||
"#{file_list_string} #{option_list}"
|
||||
ruby args do |ok, status|
|
||||
if !ok && status.respond_to?(:signaled?) && status.signaled?
|
||||
raise SignalException.new(status.termsig)
|
||||
elsif !ok
|
||||
fail "Command failed with status (#{status.exitstatus}): " +
|
||||
"[ruby #{args}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def option_list # :nodoc:
|
||||
(ENV['TESTOPTS'] ||
|
||||
ENV['TESTOPT'] ||
|
||||
ENV['TEST_OPTS'] ||
|
||||
ENV['TEST_OPT'] ||
|
||||
@options ||
|
||||
"")
|
||||
end
|
||||
|
||||
def ruby_opts_string # :nodoc:
|
||||
opts = @ruby_opts.dup
|
||||
opts.unshift("-I\"#{lib_path}\"") unless @libs.empty?
|
||||
opts.unshift("-w") if @warning
|
||||
opts.join(" ")
|
||||
end
|
||||
|
||||
def lib_path # :nodoc:
|
||||
@libs.join(File::PATH_SEPARATOR)
|
||||
end
|
||||
|
||||
def file_list_string # :nodoc:
|
||||
file_list.map { |fn| "\"#{fn}\"" }.join(' ')
|
||||
end
|
||||
|
||||
def file_list # :nodoc:
|
||||
if ENV['TEST']
|
||||
FileList[ENV['TEST']]
|
||||
else
|
||||
result = []
|
||||
result += @test_files.to_a if @test_files
|
||||
result << @pattern if @pattern
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def fix # :nodoc:
|
||||
case ruby_version
|
||||
when '1.8.2'
|
||||
"\"#{find_file 'rake/ruby182_test_unit_fix'}\""
|
||||
else
|
||||
nil
|
||||
end || ''
|
||||
end
|
||||
|
||||
def ruby_version # :nodoc:
|
||||
RUBY_VERSION
|
||||
end
|
||||
|
||||
def run_code # :nodoc:
|
||||
case @loader
|
||||
when :direct
|
||||
"-e \"ARGV.each{|f| require f}\""
|
||||
when :testrb
|
||||
"-S testrb #{fix}"
|
||||
when :rake
|
||||
"#{rake_include_arg} \"#{rake_loader}\""
|
||||
end
|
||||
end
|
||||
|
||||
def rake_loader # :nodoc:
|
||||
find_file('rake/rake_test_loader') or
|
||||
fail "unable to find rake test loader"
|
||||
end
|
||||
|
||||
def find_file(fn) # :nodoc:
|
||||
$LOAD_PATH.each do |path|
|
||||
file_path = File.join(path, "#{fn}.rb")
|
||||
return file_path if File.exist? file_path
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def rake_include_arg # :nodoc:
|
||||
spec = Gem.loaded_specs['rake']
|
||||
if spec.respond_to?(:default_gem?) && spec.default_gem?
|
||||
""
|
||||
else
|
||||
"-I\"#{rake_lib_dir}\""
|
||||
end
|
||||
end
|
||||
|
||||
def rake_lib_dir # :nodoc:
|
||||
find_dir('rake') or
|
||||
fail "unable to find rake lib"
|
||||
end
|
||||
|
||||
def find_dir(fn) # :nodoc:
|
||||
$LOAD_PATH.each do |path|
|
||||
file_path = File.join(path, "#{fn}.rb")
|
||||
return path if File.exist? file_path
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
require 'rake/private_reader'
|
||||
|
||||
module Rake
|
||||
|
||||
class ThreadHistoryDisplay # :nodoc: all
|
||||
include Rake::PrivateReader
|
||||
|
||||
private_reader :stats, :items, :threads
|
||||
|
||||
def initialize(stats)
|
||||
@stats = stats
|
||||
@items = { :_seq_ => 1 }
|
||||
@threads = { :_seq_ => "A" }
|
||||
end
|
||||
|
||||
def show
|
||||
puts "Job History:"
|
||||
stats.each do |stat|
|
||||
stat[:data] ||= {}
|
||||
rename(stat, :thread, threads)
|
||||
rename(stat[:data], :item_id, items)
|
||||
rename(stat[:data], :new_thread, threads)
|
||||
rename(stat[:data], :deleted_thread, threads)
|
||||
printf("%8d %2s %-20s %s\n",
|
||||
(stat[:time] * 1_000_000).round,
|
||||
stat[:thread],
|
||||
stat[:event],
|
||||
stat[:data].map do |k, v| "#{k}:#{v}" end.join(" "))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rename(hash, key, renames)
|
||||
if hash && hash[key]
|
||||
original = hash[key]
|
||||
value = renames[original]
|
||||
unless value
|
||||
value = renames[:_seq_]
|
||||
renames[:_seq_] = renames[:_seq_].succ
|
||||
renames[original] = value
|
||||
end
|
||||
hash[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,164 +0,0 @@
|
|||
require 'thread'
|
||||
require 'set'
|
||||
|
||||
require 'rake/promise'
|
||||
|
||||
module Rake
|
||||
|
||||
class ThreadPool # :nodoc: all
|
||||
|
||||
# Creates a ThreadPool object. The +thread_count+ parameter is the size
|
||||
# of the pool.
|
||||
def initialize(thread_count)
|
||||
@max_active_threads = [thread_count, 0].max
|
||||
@threads = Set.new
|
||||
@threads_mon = Monitor.new
|
||||
@queue = Queue.new
|
||||
@join_cond = @threads_mon.new_cond
|
||||
|
||||
@history_start_time = nil
|
||||
@history = []
|
||||
@history_mon = Monitor.new
|
||||
@total_threads_in_play = 0
|
||||
end
|
||||
|
||||
# Creates a future executed by the +ThreadPool+.
|
||||
#
|
||||
# The args are passed to the block when executing (similarly to
|
||||
# Thread#new) The return value is an object representing
|
||||
# a future which has been created and added to the queue in the
|
||||
# pool. Sending #value to the object will sleep the
|
||||
# current thread until the future is finished and will return the
|
||||
# result (or raise an exception thrown from the future)
|
||||
def future(*args, &block)
|
||||
promise = Promise.new(args, &block)
|
||||
promise.recorder = lambda { |*stats| stat(*stats) }
|
||||
|
||||
@queue.enq promise
|
||||
stat :queued, :item_id => promise.object_id
|
||||
start_thread
|
||||
promise
|
||||
end
|
||||
|
||||
# Waits until the queue of futures is empty and all threads have exited.
|
||||
def join
|
||||
@threads_mon.synchronize do
|
||||
begin
|
||||
stat :joining
|
||||
@join_cond.wait unless @threads.empty?
|
||||
stat :joined
|
||||
rescue Exception => e
|
||||
stat :joined
|
||||
$stderr.puts e
|
||||
$stderr.print "Queue contains #{@queue.size} items. " +
|
||||
"Thread pool contains #{@threads.count} threads\n"
|
||||
$stderr.print "Current Thread #{Thread.current} status = " +
|
||||
"#{Thread.current.status}\n"
|
||||
$stderr.puts e.backtrace.join("\n")
|
||||
@threads.each do |t|
|
||||
$stderr.print "Thread #{t} status = #{t.status}\n"
|
||||
# 1.8 doesn't support Thread#backtrace
|
||||
$stderr.puts t.backtrace.join("\n") if t.respond_to? :backtrace
|
||||
end
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Enable the gathering of history events.
|
||||
def gather_history #:nodoc:
|
||||
@history_start_time = Time.now if @history_start_time.nil?
|
||||
end
|
||||
|
||||
# Return a array of history events for the thread pool.
|
||||
#
|
||||
# History gathering must be enabled to be able to see the events
|
||||
# (see #gather_history). Best to call this when the job is
|
||||
# complete (i.e. after ThreadPool#join is called).
|
||||
def history # :nodoc:
|
||||
@history_mon.synchronize { @history.dup }.
|
||||
sort_by { |i| i[:time] }.
|
||||
each { |i| i[:time] -= @history_start_time }
|
||||
end
|
||||
|
||||
# Return a hash of always collected statistics for the thread pool.
|
||||
def statistics # :nodoc:
|
||||
{
|
||||
:total_threads_in_play => @total_threads_in_play,
|
||||
:max_active_threads => @max_active_threads,
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# processes one item on the queue. Returns true if there was an
|
||||
# item to process, false if there was no item
|
||||
def process_queue_item #:nodoc:
|
||||
return false if @queue.empty?
|
||||
|
||||
# Even though we just asked if the queue was empty, it
|
||||
# still could have had an item which by this statement
|
||||
# is now gone. For this reason we pass true to Queue#deq
|
||||
# because we will sleep indefinitely if it is empty.
|
||||
promise = @queue.deq(true)
|
||||
stat :dequeued, :item_id => promise.object_id
|
||||
promise.work
|
||||
return true
|
||||
|
||||
rescue ThreadError # this means the queue is empty
|
||||
false
|
||||
end
|
||||
|
||||
def safe_thread_count
|
||||
@threads_mon.synchronize do
|
||||
@threads.count
|
||||
end
|
||||
end
|
||||
|
||||
def start_thread # :nodoc:
|
||||
@threads_mon.synchronize do
|
||||
next unless @threads.count < @max_active_threads
|
||||
|
||||
t = Thread.new do
|
||||
begin
|
||||
while safe_thread_count <= @max_active_threads
|
||||
break unless process_queue_item
|
||||
end
|
||||
ensure
|
||||
@threads_mon.synchronize do
|
||||
@threads.delete Thread.current
|
||||
stat :ended, :thread_count => @threads.count
|
||||
@join_cond.broadcast if @threads.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@threads << t
|
||||
stat(
|
||||
:spawned,
|
||||
:new_thread => t.object_id,
|
||||
:thread_count => @threads.count)
|
||||
@total_threads_in_play = @threads.count if
|
||||
@threads.count > @total_threads_in_play
|
||||
end
|
||||
end
|
||||
|
||||
def stat(event, data=nil) # :nodoc:
|
||||
return if @history_start_time.nil?
|
||||
info = {
|
||||
:event => event,
|
||||
:data => data,
|
||||
:time => Time.now,
|
||||
:thread => Thread.current.object_id,
|
||||
}
|
||||
@history_mon.synchronize { @history << info }
|
||||
end
|
||||
|
||||
# for testing only
|
||||
|
||||
def __queue__ # :nodoc:
|
||||
@queue
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Rake
|
||||
module TraceOutput # :nodoc: all
|
||||
|
||||
# Write trace output to output stream +out+.
|
||||
#
|
||||
# The write is done as a single IO call (to print) to lessen the
|
||||
# chance that the trace output is interrupted by other tasks also
|
||||
# producing output.
|
||||
def trace_on(out, *strings)
|
||||
sep = $\ || "\n"
|
||||
if strings.empty?
|
||||
output = sep
|
||||
else
|
||||
output = strings.map { |s|
|
||||
next if s.nil?
|
||||
s =~ /#{sep}$/ ? s : s + sep
|
||||
}.join
|
||||
end
|
||||
out.print(output)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Rake
|
||||
module Version # :nodoc: all
|
||||
MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split '.'
|
||||
|
||||
NUMBERS = [MAJOR, MINOR, BUILD, *OTHER]
|
||||
end
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
|
||||
module Rake
|
||||
require 'rake/alt_system'
|
||||
|
||||
# Win 32 interface methods for Rake. Windows specific functionality
|
||||
# will be placed here to collect that knowledge in one spot.
|
||||
module Win32 # :nodoc: all
|
||||
|
||||
# Error indicating a problem in locating the home directory on a
|
||||
# Win32 system.
|
||||
class Win32HomeError < RuntimeError
|
||||
end
|
||||
|
||||
class << self
|
||||
# True if running on a windows system.
|
||||
def windows?
|
||||
AltSystem::WINDOWS
|
||||
end
|
||||
|
||||
# Run a command line on windows.
|
||||
def rake_system(*cmd)
|
||||
AltSystem.system(*cmd)
|
||||
end
|
||||
|
||||
# The standard directory containing system wide rake files on
|
||||
# Win 32 systems. Try the following environment variables (in
|
||||
# order):
|
||||
#
|
||||
# * HOME
|
||||
# * HOMEDRIVE + HOMEPATH
|
||||
# * APPDATA
|
||||
# * USERPROFILE
|
||||
#
|
||||
# If the above are not defined, the return nil.
|
||||
def win32_system_dir #:nodoc:
|
||||
win32_shared_path = ENV['HOME']
|
||||
if win32_shared_path.nil? && ENV['HOMEDRIVE'] && ENV['HOMEPATH']
|
||||
win32_shared_path = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
|
||||
end
|
||||
|
||||
win32_shared_path ||= ENV['APPDATA']
|
||||
win32_shared_path ||= ENV['USERPROFILE']
|
||||
raise Win32HomeError,
|
||||
"Unable to determine home path environment variable." if
|
||||
win32_shared_path.nil? or win32_shared_path.empty?
|
||||
normalize(File.join(win32_shared_path, 'Rake'))
|
||||
end
|
||||
|
||||
# Normalize a win32 path so that the slashes are all forward slashes.
|
||||
def normalize(path)
|
||||
path.gsub(/\\/, '/')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
module FileCreation
|
||||
OLDFILE = "old"
|
||||
NEWFILE = "new"
|
||||
|
||||
def create_timed_files(oldfile, *newfiles)
|
||||
return if (File.exist?(oldfile) &&
|
||||
newfiles.all? { |newfile|
|
||||
File.exist?(newfile) && File.stat(newfile).mtime > File.stat(oldfile).mtime
|
||||
})
|
||||
now = Time.now
|
||||
|
||||
create_file(oldfile, now - 60)
|
||||
|
||||
newfiles.each do |newfile|
|
||||
create_file(newfile, now)
|
||||
end
|
||||
end
|
||||
|
||||
def create_dir(dirname)
|
||||
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
|
||||
File.stat(dirname).mtime
|
||||
end
|
||||
|
||||
def create_file(name, file_time=nil)
|
||||
create_dir(File.dirname(name))
|
||||
FileUtils.touch(name) unless File.exist?(name)
|
||||
File.utime(file_time, file_time, name) unless file_time.nil?
|
||||
File.stat(name).mtime
|
||||
end
|
||||
|
||||
def delete_file(name)
|
||||
File.delete(name) rescue nil
|
||||
end
|
||||
end
|
|
@ -1,129 +0,0 @@
|
|||
require 'rubygems'
|
||||
$:.unshift File.expand_path('../../lib', __FILE__)
|
||||
|
||||
begin
|
||||
gem 'minitest', '~> 5'
|
||||
rescue Gem::LoadError
|
||||
end
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'rake'
|
||||
require 'tmpdir'
|
||||
require File.expand_path('../file_creation', __FILE__)
|
||||
|
||||
|
||||
begin
|
||||
require_relative 'support/ruby_runner'
|
||||
require_relative 'support/rakefile_definitions'
|
||||
rescue NoMethodError, LoadError
|
||||
# ruby 1.8
|
||||
require 'test/support/ruby_runner'
|
||||
require 'test/support/rakefile_definitions'
|
||||
end
|
||||
|
||||
class Rake::TestCase < Minitest::Test
|
||||
include FileCreation
|
||||
|
||||
include Rake::DSL
|
||||
|
||||
class TaskManager
|
||||
include Rake::TaskManager
|
||||
end
|
||||
|
||||
RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby
|
||||
|
||||
def setup
|
||||
ARGV.clear
|
||||
|
||||
test_dir = File.basename File.dirname File.expand_path __FILE__
|
||||
|
||||
@rake_root =
|
||||
if test_dir == 'test'
|
||||
# rake repository
|
||||
File.expand_path '../../', __FILE__
|
||||
else
|
||||
# ruby repository
|
||||
File.expand_path '../../../', __FILE__
|
||||
end
|
||||
|
||||
@verbose = ENV['VERBOSE']
|
||||
|
||||
@rake_exec = File.join @rake_root, 'bin', 'rake'
|
||||
@rake_lib = File.join @rake_root, 'lib'
|
||||
@ruby_options = ["-I#{@rake_lib}", "-I."]
|
||||
|
||||
@orig_pwd = Dir.pwd
|
||||
@orig_appdata = ENV['APPDATA']
|
||||
@orig_home = ENV['HOME']
|
||||
@orig_homedrive = ENV['HOMEDRIVE']
|
||||
@orig_homepath = ENV['HOMEPATH']
|
||||
@orig_rake_columns = ENV['RAKE_COLUMNS']
|
||||
@orig_rake_system = ENV['RAKE_SYSTEM']
|
||||
@orig_rakeopt = ENV['RAKEOPT']
|
||||
@orig_userprofile = ENV['USERPROFILE']
|
||||
ENV.delete 'RAKE_COLUMNS'
|
||||
ENV.delete 'RAKE_SYSTEM'
|
||||
ENV.delete 'RAKEOPT'
|
||||
|
||||
tmpdir = Dir.chdir Dir.tmpdir do Dir.pwd end
|
||||
@tempdir = File.join tmpdir, "test_rake_#{$$}"
|
||||
|
||||
FileUtils.mkdir_p @tempdir
|
||||
|
||||
Dir.chdir @tempdir
|
||||
|
||||
Rake.application = Rake::Application.new
|
||||
Rake::TaskManager.record_task_metadata = true
|
||||
RakeFileUtils.verbose_flag = false
|
||||
end
|
||||
|
||||
def teardown
|
||||
Dir.chdir @orig_pwd
|
||||
FileUtils.rm_rf @tempdir
|
||||
|
||||
if @orig_appdata
|
||||
ENV['APPDATA'] = @orig_appdata
|
||||
else
|
||||
ENV.delete 'APPDATA'
|
||||
end
|
||||
|
||||
ENV['HOME'] = @orig_home
|
||||
ENV['HOMEDRIVE'] = @orig_homedrive
|
||||
ENV['HOMEPATH'] = @orig_homepath
|
||||
ENV['RAKE_COLUMNS'] = @orig_rake_columns
|
||||
ENV['RAKE_SYSTEM'] = @orig_rake_system
|
||||
ENV['RAKEOPT'] = @orig_rakeopt
|
||||
ENV['USERPROFILE'] = @orig_userprofile
|
||||
end
|
||||
|
||||
def ignore_deprecations
|
||||
Rake.application.options.ignore_deprecate = true
|
||||
yield
|
||||
ensure
|
||||
Rake.application.options.ignore_deprecate = false
|
||||
end
|
||||
|
||||
def rake_system_dir
|
||||
@system_dir = 'system'
|
||||
|
||||
FileUtils.mkdir_p @system_dir
|
||||
|
||||
open File.join(@system_dir, 'sys1.rake'), 'w' do |io|
|
||||
io << <<-SYS
|
||||
task "sys1" do
|
||||
puts "SYS1"
|
||||
end
|
||||
SYS
|
||||
end
|
||||
|
||||
ENV['RAKE_SYSTEM'] = @system_dir
|
||||
end
|
||||
|
||||
def rakefile(contents)
|
||||
open 'Rakefile', 'w' do |io|
|
||||
io << contents
|
||||
end
|
||||
end
|
||||
|
||||
include RakefileDefinitions
|
||||
end
|
|
@ -1,478 +0,0 @@
|
|||
module RakefileDefinitions
|
||||
include FileUtils
|
||||
|
||||
def rakefile_access
|
||||
rakefile <<-ACCESS
|
||||
TOP_LEVEL_CONSTANT = 0
|
||||
|
||||
def a_top_level_function
|
||||
end
|
||||
|
||||
task :default => [:work, :obj, :const]
|
||||
|
||||
task :work do
|
||||
begin
|
||||
a_top_level_function
|
||||
puts "GOOD:M Top level methods can be called in tasks"
|
||||
rescue NameError => ex
|
||||
puts "BAD:M Top level methods can not be called in tasks"
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: remove `disabled_' when DeprecatedObjectDSL removed
|
||||
task :obj
|
||||
task :disabled_obj do
|
||||
begin
|
||||
Object.new.instance_eval { task :xyzzy }
|
||||
puts "BAD:D Rake DSL are polluting objects"
|
||||
rescue StandardError => ex
|
||||
puts "GOOD:D Rake DSL are not polluting objects"
|
||||
end
|
||||
end
|
||||
|
||||
task :const do
|
||||
begin
|
||||
TOP_LEVEL_CONSTANT
|
||||
puts "GOOD:C Top level constants are available in tasks"
|
||||
rescue StandardError => ex
|
||||
puts "BAD:C Top level constants are NOT available in tasks"
|
||||
end
|
||||
end
|
||||
ACCESS
|
||||
end
|
||||
|
||||
def rakefile_test_task
|
||||
rakefile <<-RAKEFILE
|
||||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new(:unit) do |t|
|
||||
t.description = "custom test task description"
|
||||
end
|
||||
RAKEFILE
|
||||
end
|
||||
|
||||
def rakefile_chains
|
||||
rakefile <<-DEFAULT
|
||||
task :default => "play.app"
|
||||
|
||||
file "play.scpt" => "base" do |t|
|
||||
cp t.prerequisites.first, t.name
|
||||
end
|
||||
|
||||
rule ".app" => ".scpt" do |t|
|
||||
cp t.source, t.name
|
||||
end
|
||||
|
||||
file 'base' do
|
||||
touch 'base'
|
||||
end
|
||||
DEFAULT
|
||||
end
|
||||
|
||||
def rakefile_comments
|
||||
rakefile <<-COMMENTS
|
||||
# comment for t1
|
||||
task :t1 do
|
||||
end
|
||||
|
||||
# no comment or task because there's a blank line
|
||||
|
||||
task :t2 do
|
||||
end
|
||||
|
||||
desc "override comment for t3"
|
||||
# this is not the description
|
||||
multitask :t3 do
|
||||
end
|
||||
|
||||
# this is not the description
|
||||
desc "override comment for t4"
|
||||
file :t4 do
|
||||
end
|
||||
COMMENTS
|
||||
end
|
||||
|
||||
def rakefile_default
|
||||
rakefile <<-DEFAULT
|
||||
if ENV['TESTTOPSCOPE']
|
||||
puts "TOPSCOPE"
|
||||
end
|
||||
|
||||
task :default do
|
||||
puts "DEFAULT"
|
||||
end
|
||||
|
||||
task :other => [:default] do
|
||||
puts "OTHER"
|
||||
end
|
||||
|
||||
task :task_scope do
|
||||
if ENV['TESTTASKSCOPE']
|
||||
puts "TASKSCOPE"
|
||||
end
|
||||
end
|
||||
DEFAULT
|
||||
end
|
||||
|
||||
def rakefile_dryrun
|
||||
rakefile <<-DRYRUN
|
||||
task :default => ["temp_main"]
|
||||
|
||||
file "temp_main" => [:all_apps] do touch "temp_main" end
|
||||
|
||||
task :all_apps => [:one, :two]
|
||||
task :one => ["temp_one"]
|
||||
task :two => ["temp_two"]
|
||||
|
||||
file "temp_one" do |t|
|
||||
touch "temp_one"
|
||||
end
|
||||
file "temp_two" do |t|
|
||||
touch "temp_two"
|
||||
end
|
||||
|
||||
task :clean do
|
||||
["temp_one", "temp_two", "temp_main"].each do |file|
|
||||
rm_f file
|
||||
end
|
||||
end
|
||||
DRYRUN
|
||||
|
||||
FileUtils.touch 'temp_main'
|
||||
FileUtils.touch 'temp_two'
|
||||
end
|
||||
|
||||
def rakefile_extra
|
||||
rakefile 'task :default'
|
||||
|
||||
FileUtils.mkdir_p 'rakelib'
|
||||
|
||||
open File.join('rakelib', 'extra.rake'), 'w' do |io|
|
||||
io << <<-EXTRA_RAKE
|
||||
# Added for testing
|
||||
|
||||
namespace :extra do
|
||||
desc "An Extra Task"
|
||||
task :extra do
|
||||
puts "Read all about it"
|
||||
end
|
||||
end
|
||||
EXTRA_RAKE
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_file_creation
|
||||
rakefile <<-'FILE_CREATION'
|
||||
N = 2
|
||||
|
||||
task :default => :run
|
||||
|
||||
BUILD_DIR = 'build'
|
||||
task :clean do
|
||||
rm_rf 'build'
|
||||
rm_rf 'src'
|
||||
end
|
||||
|
||||
task :run
|
||||
|
||||
TARGET_DIR = 'build/copies'
|
||||
|
||||
FileList['src/*'].each do |src|
|
||||
directory TARGET_DIR
|
||||
target = File.join TARGET_DIR, File.basename(src)
|
||||
file target => [src, TARGET_DIR] do
|
||||
cp src, target
|
||||
end
|
||||
task :run => target
|
||||
end
|
||||
|
||||
task :prep => :clean do
|
||||
mkdir_p 'src'
|
||||
N.times do |n|
|
||||
touch "src/foo#{n}"
|
||||
end
|
||||
end
|
||||
FILE_CREATION
|
||||
end
|
||||
|
||||
def rakefile_imports
|
||||
rakefile <<-IMPORTS
|
||||
require 'rake/loaders/makefile'
|
||||
|
||||
task :default
|
||||
|
||||
task :other do
|
||||
puts "OTHER"
|
||||
end
|
||||
|
||||
file "dynamic_deps" do |t|
|
||||
open(t.name, "w") do |f| f.puts "puts 'DYNAMIC'" end
|
||||
end
|
||||
|
||||
import "dynamic_deps"
|
||||
import "static_deps"
|
||||
import "static_deps"
|
||||
import "deps.mf"
|
||||
puts "FIRST"
|
||||
IMPORTS
|
||||
|
||||
open 'deps.mf', 'w' do |io|
|
||||
io << <<-DEPS
|
||||
default: other
|
||||
DEPS
|
||||
end
|
||||
|
||||
open "static_deps", "w" do |f|
|
||||
f.puts 'puts "STATIC"'
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_regenerate_imports
|
||||
rakefile <<-REGENERATE_IMPORTS
|
||||
task :default
|
||||
|
||||
task :regenerate do
|
||||
open("deps", "w") do |f|
|
||||
f << <<-CONTENT
|
||||
file "deps" => :regenerate
|
||||
puts "REGENERATED"
|
||||
CONTENT
|
||||
end
|
||||
end
|
||||
|
||||
import "deps"
|
||||
REGENERATE_IMPORTS
|
||||
|
||||
open "deps", "w" do |f|
|
||||
f << <<-CONTENT
|
||||
file "deps" => :regenerate
|
||||
puts "INITIAL"
|
||||
CONTENT
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_multidesc
|
||||
rakefile <<-MULTIDESC
|
||||
task :b
|
||||
|
||||
desc "A"
|
||||
task :a
|
||||
|
||||
desc "B"
|
||||
task :b
|
||||
|
||||
desc "A2"
|
||||
task :a
|
||||
|
||||
task :c
|
||||
|
||||
desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
task :d
|
||||
MULTIDESC
|
||||
end
|
||||
|
||||
def rakefile_namespace
|
||||
rakefile <<-NAMESPACE
|
||||
desc "copy"
|
||||
task :copy do
|
||||
puts "COPY"
|
||||
end
|
||||
|
||||
namespace "nest" do
|
||||
desc "nest copy"
|
||||
task :copy do
|
||||
puts "NEST COPY"
|
||||
end
|
||||
task :xx => :copy
|
||||
end
|
||||
|
||||
anon_ns = namespace do
|
||||
desc "anonymous copy task"
|
||||
task :copy do
|
||||
puts "ANON COPY"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Top level task to run the anonymous version of copy"
|
||||
task :anon => anon_ns[:copy]
|
||||
|
||||
namespace "very" do
|
||||
namespace "nested" do
|
||||
task "run" => "rake:copy"
|
||||
end
|
||||
end
|
||||
|
||||
namespace "a" do
|
||||
desc "Run task in the 'a' namespace"
|
||||
task "run" do
|
||||
puts "IN A"
|
||||
end
|
||||
end
|
||||
|
||||
namespace "b" do
|
||||
desc "Run task in the 'b' namespace"
|
||||
task "run" => "a:run" do
|
||||
puts "IN B"
|
||||
end
|
||||
end
|
||||
|
||||
namespace "file1" do
|
||||
file "xyz.rb" do
|
||||
puts "XYZ1"
|
||||
end
|
||||
end
|
||||
|
||||
namespace "file2" do
|
||||
file "xyz.rb" do
|
||||
puts "XYZ2"
|
||||
end
|
||||
end
|
||||
|
||||
namespace "scopedep" do
|
||||
task :prepare do
|
||||
touch "scopedep.rb"
|
||||
puts "PREPARE"
|
||||
end
|
||||
file "scopedep.rb" => [:prepare] do
|
||||
puts "SCOPEDEP"
|
||||
end
|
||||
end
|
||||
NAMESPACE
|
||||
end
|
||||
|
||||
def rakefile_nosearch
|
||||
FileUtils.touch 'dummy'
|
||||
end
|
||||
|
||||
def rakefile_rakelib
|
||||
FileUtils.mkdir_p 'rakelib'
|
||||
|
||||
Dir.chdir 'rakelib' do
|
||||
open 'test1.rb', 'w' do |io|
|
||||
io << <<-TEST1
|
||||
task :default do
|
||||
puts "TEST1"
|
||||
end
|
||||
TEST1
|
||||
end
|
||||
|
||||
open 'test2.rake', 'w' do |io|
|
||||
io << <<-TEST1
|
||||
task :default do
|
||||
puts "TEST2"
|
||||
end
|
||||
TEST1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_rbext
|
||||
open 'rakefile.rb', 'w' do |io|
|
||||
io << 'task :default do puts "OK" end'
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_unittest
|
||||
rakefile '# Empty Rakefile for Unit Test'
|
||||
|
||||
readme = File.join 'subdir', 'README'
|
||||
FileUtils.mkdir_p File.dirname readme
|
||||
|
||||
FileUtils.touch readme
|
||||
end
|
||||
|
||||
def rakefile_verbose
|
||||
rakefile <<-VERBOSE
|
||||
task :standalone_verbose_true do
|
||||
verbose true
|
||||
sh "#{RUBY} -e '0'"
|
||||
end
|
||||
|
||||
task :standalone_verbose_false do
|
||||
verbose false
|
||||
sh "#{RUBY} -e '0'"
|
||||
end
|
||||
|
||||
task :inline_verbose_default do
|
||||
sh "#{RUBY} -e '0'"
|
||||
end
|
||||
|
||||
task :inline_verbose_false do
|
||||
sh "#{RUBY} -e '0'", :verbose => false
|
||||
end
|
||||
|
||||
task :inline_verbose_true do
|
||||
sh "#{RUBY} -e '0'", :verbose => true
|
||||
end
|
||||
|
||||
task :block_verbose_true do
|
||||
verbose(true) do
|
||||
sh "#{RUBY} -e '0'"
|
||||
end
|
||||
end
|
||||
|
||||
task :block_verbose_false do
|
||||
verbose(false) do
|
||||
sh "#{RUBY} -e '0'"
|
||||
end
|
||||
end
|
||||
VERBOSE
|
||||
end
|
||||
|
||||
def rakefile_test_signal
|
||||
rakefile <<-TEST_SIGNAL
|
||||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new(:a) do |t|
|
||||
t.test_files = ['a_test.rb']
|
||||
end
|
||||
|
||||
Rake::TestTask.new(:b) do |t|
|
||||
t.test_files = ['b_test.rb']
|
||||
end
|
||||
|
||||
task :test do
|
||||
Rake::Task[:a].invoke
|
||||
Rake::Task[:b].invoke
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
TEST_SIGNAL
|
||||
open 'a_test.rb', 'w' do |io|
|
||||
io << 'puts "ATEST"' << "\n"
|
||||
io << '$stdout.flush' << "\n"
|
||||
io << 'Process.kill("TERM", $$)' << "\n"
|
||||
end
|
||||
open 'b_test.rb', 'w' do |io|
|
||||
io << 'puts "BTEST"' << "\n"
|
||||
io << '$stdout.flush' << "\n"
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_failing_test_task
|
||||
rakefile <<-TEST_TASK
|
||||
require 'rake/testtask'
|
||||
|
||||
task :default => :test
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.test_files = ['a_test.rb']
|
||||
end
|
||||
TEST_TASK
|
||||
open 'a_test.rb', 'w' do |io|
|
||||
io << "require 'minitest/autorun'\n"
|
||||
io << "class ExitTaskTest < Minitest::Test\n"
|
||||
io << " def test_exit\n"
|
||||
io << " assert false, 'this should fail'\n"
|
||||
io << " end\n"
|
||||
io << "end\n"
|
||||
end
|
||||
end
|
||||
|
||||
def rakefile_stand_alone_filelist
|
||||
open 'stand_alone_filelist.rb', 'w' do |io|
|
||||
io << "require 'rake/file_list'\n"
|
||||
io << "FL = Rake::FileList['*.rb']\n"
|
||||
io << "puts FL\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
module RubyRunner
|
||||
include FileUtils
|
||||
|
||||
# Run a shell Ruby command with command line options (using the
|
||||
# default test options). Output is captured in @out and @err
|
||||
def ruby(*option_list)
|
||||
run_ruby(@ruby_options + option_list)
|
||||
end
|
||||
|
||||
# Run a command line rake with the give rake options. Default
|
||||
# command line ruby options are included. Output is captured in
|
||||
# @out and @err
|
||||
def rake(*rake_options)
|
||||
run_ruby @ruby_options + [@rake_exec] + rake_options
|
||||
end
|
||||
|
||||
# Low level ruby command runner ...
|
||||
def run_ruby(option_list)
|
||||
puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
|
||||
|
||||
Open3.popen3(RUBY, *option_list) {|inn, out, err, wait|
|
||||
inn.close
|
||||
|
||||
@exit = wait ? wait.value : $?
|
||||
@out = out.read
|
||||
@err = err.read
|
||||
}
|
||||
|
||||
puts "OUTPUT: [#{@out}]" if @verbose
|
||||
puts "ERROR: [#{@err}]" if @verbose
|
||||
puts "EXIT: [#{@exit.inspect}]" if @verbose
|
||||
puts "PWD: [#{Dir.pwd}]" if @verbose
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'rake/private_reader'
|
||||
|
||||
class TestPrivateAttrs < Rake::TestCase
|
||||
|
||||
class Sample
|
||||
include Rake::PrivateReader
|
||||
|
||||
private_reader :reader, :a
|
||||
|
||||
def initialize
|
||||
@reader = :RVALUE
|
||||
end
|
||||
|
||||
def get_reader
|
||||
reader
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def setup
|
||||
super
|
||||
@sample = Sample.new
|
||||
end
|
||||
|
||||
def test_private_reader_is_private
|
||||
assert_private do @sample.reader end
|
||||
assert_private do @sample.a end
|
||||
end
|
||||
|
||||
def test_private_reader_returns_data
|
||||
assert_equal :RVALUE, @sample.get_reader
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_private
|
||||
ex = assert_raises(NoMethodError) do yield end
|
||||
assert_match(/private/, ex.message)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRake < Rake::TestCase
|
||||
def test_each_dir_parent
|
||||
assert_equal ['a'], alldirs('a')
|
||||
assert_equal ['a/b', 'a'], alldirs('a/b')
|
||||
assert_equal ['/a/b', '/a', '/'], alldirs('/a/b')
|
||||
if File.dirname("c:/foo") == "c:"
|
||||
# Under Unix
|
||||
assert_equal ['c:/a/b', 'c:/a', 'c:'], alldirs('c:/a/b')
|
||||
assert_equal ['c:a/b', 'c:a'], alldirs('c:a/b')
|
||||
else
|
||||
# Under Windows
|
||||
assert_equal ['c:/a/b', 'c:/a', 'c:/'], alldirs('c:/a/b')
|
||||
assert_equal ['c:a/b', 'c:a'], alldirs('c:a/b')
|
||||
end
|
||||
end
|
||||
|
||||
def alldirs(fn)
|
||||
result = []
|
||||
Rake.each_dir_parent(fn) { |d| result << d }
|
||||
result
|
||||
end
|
||||
|
||||
def test_can_override_application
|
||||
old_app = Rake.application
|
||||
fake_app = Object.new
|
||||
Rake.application = fake_app
|
||||
|
||||
assert_equal fake_app, Rake.application
|
||||
|
||||
ensure
|
||||
Rake.application = old_app
|
||||
end
|
||||
|
||||
def test_original_dir_reports_current_dir
|
||||
assert_equal @tempdir, Rake.original_dir
|
||||
end
|
||||
|
||||
end
|
|
@ -1,643 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeApplication < Rake::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
@app = Rake.application
|
||||
@app.options.rakelib = []
|
||||
end
|
||||
|
||||
def setup_command_line(*options)
|
||||
ARGV.clear
|
||||
options.each do |option|
|
||||
ARGV << option
|
||||
end
|
||||
end
|
||||
|
||||
def test_display_exception_details
|
||||
obj = Object.new
|
||||
obj.instance_eval("def #{__method__}; raise 'test'; end", "ruby")
|
||||
begin
|
||||
obj.__send__(__method__)
|
||||
rescue => ex
|
||||
end
|
||||
|
||||
out, err = capture_io do
|
||||
@app.display_error_message ex
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
|
||||
assert_match 'rake aborted!', err
|
||||
assert_match __method__.to_s, err
|
||||
end
|
||||
|
||||
def test_display_exception_details_cause
|
||||
skip 'Exception#cause not implemented' unless
|
||||
Exception.method_defined? :cause
|
||||
|
||||
begin
|
||||
raise 'cause a'
|
||||
rescue
|
||||
begin
|
||||
raise 'cause b'
|
||||
rescue => ex
|
||||
end
|
||||
end
|
||||
|
||||
out, err = capture_io do
|
||||
@app.display_error_message ex
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
|
||||
assert_match 'cause a', err
|
||||
assert_match 'cause b', err
|
||||
end
|
||||
|
||||
def test_display_exception_details_cause_loop
|
||||
skip 'Exception#cause not implemented' unless
|
||||
Exception.method_defined? :cause
|
||||
|
||||
begin
|
||||
begin
|
||||
raise 'cause a'
|
||||
rescue => a
|
||||
begin
|
||||
raise 'cause b'
|
||||
rescue
|
||||
raise a
|
||||
end
|
||||
end
|
||||
rescue => ex
|
||||
end
|
||||
|
||||
out, err = capture_io do
|
||||
@app.display_error_message ex
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
|
||||
assert_match 'cause a', err
|
||||
assert_match 'cause b', err
|
||||
end
|
||||
|
||||
def test_display_tasks
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
@app.last_description = "COMMENT"
|
||||
@app.define_task(Rake::Task, "t")
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
assert_match(/^rake t/, out)
|
||||
assert_match(/# COMMENT/, out)
|
||||
end
|
||||
|
||||
def test_display_tasks_with_long_comments
|
||||
@app.terminal_columns = 80
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
numbers = "1234567890" * 8
|
||||
@app.last_description = numbers
|
||||
@app.define_task(Rake::Task, "t")
|
||||
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
|
||||
assert_match(/^rake t/, out)
|
||||
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
|
||||
end
|
||||
|
||||
def test_display_tasks_with_task_name_wider_than_tty_display
|
||||
@app.terminal_columns = 80
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
task_name = "task name" * 80
|
||||
@app.last_description = "something short"
|
||||
@app.define_task(Rake::Task, task_name)
|
||||
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
|
||||
# Ensure the entire task name is output and we end up showing no description
|
||||
assert_match(/rake #{task_name} # .../, out)
|
||||
end
|
||||
|
||||
def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
@app.tty_output = false
|
||||
description = "something short"
|
||||
task_name = "task name" * 80
|
||||
@app.last_description = "something short"
|
||||
@app.define_task(Rake::Task, task_name)
|
||||
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
|
||||
# Ensure the entire task name is output and we end up showing no description
|
||||
assert_match(/rake #{task_name} # #{description}/, out)
|
||||
end
|
||||
|
||||
def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
@app.tty_output = false
|
||||
@app.last_description = "1234567890" * 8
|
||||
@app.define_task(Rake::Task, "t")
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
assert_match(/^rake t/, out)
|
||||
assert_match(/# #{@app.last_description}/, out)
|
||||
end
|
||||
|
||||
def test_truncating_comments_to_a_non_tty
|
||||
@app.terminal_columns = 80
|
||||
@app.options.show_tasks = :tasks
|
||||
@app.options.show_task_pattern = //
|
||||
@app.tty_output = false
|
||||
numbers = "1234567890" * 8
|
||||
@app.last_description = numbers
|
||||
@app.define_task(Rake::Task, "t")
|
||||
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
|
||||
assert_match(/^rake t/, out)
|
||||
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
|
||||
end
|
||||
|
||||
def test_describe_tasks
|
||||
@app.options.show_tasks = :describe
|
||||
@app.options.show_task_pattern = //
|
||||
@app.last_description = "COMMENT"
|
||||
@app.define_task(Rake::Task, "t")
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
assert_match(/^rake t$/, out)
|
||||
assert_match(/^ {4}COMMENT$/, out)
|
||||
end
|
||||
|
||||
def test_show_lines
|
||||
@app.options.show_tasks = :lines
|
||||
@app.options.show_task_pattern = //
|
||||
@app.last_description = "COMMENT"
|
||||
@app.define_task(Rake::Task, "t")
|
||||
@app['t'].locations << "HERE:1"
|
||||
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
|
||||
assert_match(/^rake t +[^:]+:\d+ *$/, out)
|
||||
end
|
||||
|
||||
def test_finding_rakefile
|
||||
rakefile_default
|
||||
|
||||
assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
|
||||
end
|
||||
|
||||
def test_not_finding_rakefile
|
||||
@app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
|
||||
assert(! @app.instance_eval do have_rakefile end)
|
||||
assert_nil @app.rakefile
|
||||
end
|
||||
|
||||
def test_load_rakefile
|
||||
rakefile_unittest
|
||||
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
load_rakefile
|
||||
end
|
||||
|
||||
assert_equal "rakefile", @app.rakefile.downcase
|
||||
assert_equal @tempdir, Dir.pwd
|
||||
end
|
||||
|
||||
def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
|
||||
rakefile_unittest
|
||||
|
||||
_, err = capture_io do
|
||||
@app.instance_eval do
|
||||
# pretend we started from the unittest dir
|
||||
@original_dir = File.expand_path(".")
|
||||
raw_load_rakefile
|
||||
end
|
||||
end
|
||||
|
||||
assert_empty err
|
||||
end
|
||||
|
||||
def test_load_rakefile_from_subdir
|
||||
rakefile_unittest
|
||||
Dir.chdir 'subdir'
|
||||
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
load_rakefile
|
||||
end
|
||||
|
||||
assert_equal "rakefile", @app.rakefile.downcase
|
||||
assert_equal @tempdir, Dir.pwd
|
||||
end
|
||||
|
||||
def test_load_rakefile_prints_rakefile_directory_from_subdir
|
||||
rakefile_unittest
|
||||
Dir.chdir 'subdir'
|
||||
|
||||
app = Rake::Application.new
|
||||
app.options.rakelib = []
|
||||
|
||||
_, err = capture_io do
|
||||
app.instance_eval do
|
||||
raw_load_rakefile
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal "(in #{@tempdir}\)\n", err
|
||||
end
|
||||
|
||||
def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
|
||||
rakefile_unittest
|
||||
Dir.chdir 'subdir'
|
||||
|
||||
_, err = capture_io do
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
raw_load_rakefile
|
||||
end
|
||||
end
|
||||
|
||||
assert_empty err
|
||||
end
|
||||
|
||||
def test_load_rakefile_not_found
|
||||
ARGV.clear
|
||||
Dir.chdir @tempdir
|
||||
ENV['RAKE_SYSTEM'] = 'not_exist'
|
||||
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
end
|
||||
|
||||
|
||||
ex = assert_raises(RuntimeError) do
|
||||
@app.instance_eval do
|
||||
raw_load_rakefile
|
||||
end
|
||||
end
|
||||
|
||||
assert_match(/no rakefile found/i, ex.message)
|
||||
end
|
||||
|
||||
def test_load_from_system_rakefile
|
||||
rake_system_dir
|
||||
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
options.load_system = true
|
||||
options.rakelib = []
|
||||
load_rakefile
|
||||
end
|
||||
|
||||
assert_equal @system_dir, @app.system_dir
|
||||
assert_nil @app.rakefile
|
||||
rescue SystemExit
|
||||
flunk 'failed to load rakefile'
|
||||
end
|
||||
|
||||
def test_load_from_calculated_system_rakefile
|
||||
rakefile_default
|
||||
def @app.standard_system_dir
|
||||
"__STD_SYS_DIR__"
|
||||
end
|
||||
|
||||
ENV['RAKE_SYSTEM'] = nil
|
||||
|
||||
@app.instance_eval do
|
||||
handle_options
|
||||
options.silent = true
|
||||
options.load_system = true
|
||||
options.rakelib = []
|
||||
load_rakefile
|
||||
end
|
||||
|
||||
assert_equal "__STD_SYS_DIR__", @app.system_dir
|
||||
rescue SystemExit
|
||||
flunk 'failed to find system rakefile'
|
||||
end
|
||||
|
||||
def test_terminal_columns
|
||||
old_rake_columns = ENV['RAKE_COLUMNS']
|
||||
|
||||
ENV['RAKE_COLUMNS'] = '42'
|
||||
|
||||
app = Rake::Application.new
|
||||
|
||||
assert_equal 42, app.terminal_columns
|
||||
ensure
|
||||
if old_rake_columns
|
||||
ENV['RAKE_COLUMNS'].delete
|
||||
else
|
||||
ENV['RAKE_COLUMNS'] = old_rake_columns
|
||||
end
|
||||
end
|
||||
|
||||
def test_windows
|
||||
assert ! (@app.windows? && @app.unix?)
|
||||
end
|
||||
|
||||
def test_loading_imports
|
||||
loader = util_loader
|
||||
|
||||
@app.instance_eval do
|
||||
add_loader("dummy", loader)
|
||||
add_import("x.dummy")
|
||||
load_imports
|
||||
end
|
||||
|
||||
# HACK no assertions
|
||||
end
|
||||
|
||||
def test_building_imported_files_on_demand
|
||||
loader = util_loader
|
||||
|
||||
@app.instance_eval do
|
||||
intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
|
||||
add_loader("dummy", loader)
|
||||
add_import("x.dummy")
|
||||
load_imports
|
||||
end
|
||||
|
||||
# HACK no assertions
|
||||
end
|
||||
|
||||
def test_handle_options_should_not_strip_options_from_argv
|
||||
assert !@app.options.trace
|
||||
|
||||
valid_option = '--trace'
|
||||
setup_command_line(valid_option)
|
||||
|
||||
@app.handle_options
|
||||
|
||||
assert ARGV.include?(valid_option)
|
||||
assert @app.options.trace
|
||||
end
|
||||
|
||||
def test_handle_options_trace_default_is_stderr
|
||||
setup_command_line("--trace")
|
||||
|
||||
@app.handle_options
|
||||
|
||||
assert_equal STDERR, @app.options.trace_output
|
||||
assert @app.options.trace
|
||||
end
|
||||
|
||||
def test_handle_options_trace_overrides_to_stdout
|
||||
setup_command_line("--trace=stdout")
|
||||
|
||||
@app.handle_options
|
||||
|
||||
assert_equal STDOUT, @app.options.trace_output
|
||||
assert @app.options.trace
|
||||
end
|
||||
|
||||
def test_handle_options_trace_does_not_eat_following_task_names
|
||||
assert !@app.options.trace
|
||||
|
||||
setup_command_line("--trace", "sometask")
|
||||
|
||||
@app.handle_options
|
||||
assert ARGV.include?("sometask")
|
||||
assert @app.options.trace
|
||||
end
|
||||
|
||||
def test_good_run
|
||||
ran = false
|
||||
|
||||
ARGV << '--rakelib=""'
|
||||
|
||||
@app.options.silent = true
|
||||
|
||||
@app.instance_eval do
|
||||
intern(Rake::Task, "default").enhance { ran = true }
|
||||
end
|
||||
|
||||
rakefile_default
|
||||
|
||||
out, err = capture_io do
|
||||
@app.run
|
||||
end
|
||||
|
||||
assert ran
|
||||
assert_empty err
|
||||
assert_equal "DEFAULT\n", out
|
||||
end
|
||||
|
||||
def test_display_task_run
|
||||
ran = false
|
||||
setup_command_line('-f', '-s', '--tasks', '--rakelib=""')
|
||||
@app.last_description = "COMMENT"
|
||||
@app.define_task(Rake::Task, "default")
|
||||
out, = capture_io { @app.run }
|
||||
assert @app.options.show_tasks
|
||||
assert ! ran
|
||||
assert_match(/rake default/, out)
|
||||
assert_match(/# COMMENT/, out)
|
||||
end
|
||||
|
||||
def test_display_prereqs
|
||||
ran = false
|
||||
setup_command_line('-f', '-s', '--prereqs', '--rakelib=""')
|
||||
@app.last_description = "COMMENT"
|
||||
t = @app.define_task(Rake::Task, "default")
|
||||
t.enhance([:a, :b])
|
||||
@app.define_task(Rake::Task, "a")
|
||||
@app.define_task(Rake::Task, "b")
|
||||
out, = capture_io { @app.run }
|
||||
assert @app.options.show_prereqs
|
||||
assert ! ran
|
||||
assert_match(/rake a$/, out)
|
||||
assert_match(/rake b$/, out)
|
||||
assert_match(/rake default\n( *(a|b)\n){2}/m, out)
|
||||
end
|
||||
|
||||
def test_bad_run
|
||||
@app.intern(Rake::Task, "default").enhance { fail }
|
||||
setup_command_line('-f', '-s', '--rakelib=""')
|
||||
_, err = capture_io {
|
||||
assert_raises(SystemExit){ @app.run }
|
||||
}
|
||||
assert_match(/see full trace/i, err)
|
||||
ensure
|
||||
ARGV.clear
|
||||
end
|
||||
|
||||
def test_bad_run_with_trace
|
||||
@app.intern(Rake::Task, "default").enhance { fail }
|
||||
setup_command_line('-f', '-s', '-t')
|
||||
_, err = capture_io {
|
||||
assert_raises(SystemExit) { @app.run }
|
||||
}
|
||||
refute_match(/see full trace/i, err)
|
||||
ensure
|
||||
ARGV.clear
|
||||
end
|
||||
|
||||
def test_bad_run_with_backtrace
|
||||
@app.intern(Rake::Task, "default").enhance { fail }
|
||||
setup_command_line('-f', '-s', '--backtrace')
|
||||
_, err = capture_io {
|
||||
assert_raises(SystemExit) {
|
||||
@app.run
|
||||
}
|
||||
}
|
||||
refute_match(/see full trace/, err)
|
||||
ensure
|
||||
ARGV.clear
|
||||
end
|
||||
|
||||
CustomError = Class.new(RuntimeError)
|
||||
|
||||
def test_bad_run_includes_exception_name
|
||||
@app.intern(Rake::Task, "default").enhance {
|
||||
raise CustomError, "intentional"
|
||||
}
|
||||
setup_command_line('-f', '-s')
|
||||
_, err = capture_io {
|
||||
assert_raises(SystemExit) {
|
||||
@app.run
|
||||
}
|
||||
}
|
||||
assert_match(/CustomError: intentional/, err)
|
||||
end
|
||||
|
||||
def test_rake_error_excludes_exception_name
|
||||
@app.intern(Rake::Task, "default").enhance {
|
||||
fail "intentional"
|
||||
}
|
||||
setup_command_line('-f', '-s')
|
||||
_, err = capture_io {
|
||||
assert_raises(SystemExit) {
|
||||
@app.run
|
||||
}
|
||||
}
|
||||
refute_match(/RuntimeError/, err)
|
||||
assert_match(/intentional/, err)
|
||||
end
|
||||
|
||||
def cause_supported?
|
||||
ex = StandardError.new
|
||||
ex.respond_to?(:cause)
|
||||
end
|
||||
|
||||
def test_printing_original_exception_cause
|
||||
custom_error = Class.new(StandardError)
|
||||
@app.intern(Rake::Task, "default").enhance {
|
||||
begin
|
||||
raise custom_error, "Original Error"
|
||||
rescue custom_error
|
||||
raise custom_error, "Secondary Error"
|
||||
end
|
||||
}
|
||||
setup_command_line('-f', '-s')
|
||||
_ ,err = capture_io {
|
||||
assert_raises(SystemExit) {
|
||||
@app.run
|
||||
}
|
||||
}
|
||||
if cause_supported?
|
||||
assert_match(/Original Error/, err)
|
||||
end
|
||||
assert_match(/Secondary Error/, err)
|
||||
ensure
|
||||
ARGV.clear
|
||||
end
|
||||
|
||||
def test_run_with_bad_options
|
||||
@app.intern(Rake::Task, "default").enhance { fail }
|
||||
setup_command_line('-f', '-s', '--xyzzy')
|
||||
assert_raises(SystemExit) {
|
||||
capture_io { @app.run }
|
||||
}
|
||||
ensure
|
||||
ARGV.clear
|
||||
end
|
||||
|
||||
def test_standard_exception_handling_invalid_option
|
||||
out, err = capture_io do
|
||||
e = assert_raises SystemExit do
|
||||
@app.standard_exception_handling do
|
||||
raise OptionParser::InvalidOption, 'blah'
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 1, e.status
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
assert_equal "invalid option: blah\n", err
|
||||
end
|
||||
|
||||
def test_standard_exception_handling_other
|
||||
out, err = capture_io do
|
||||
e = assert_raises SystemExit do
|
||||
@app.standard_exception_handling do
|
||||
raise 'blah'
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 1, e.status
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
assert_match "rake aborted!\n", err
|
||||
assert_match "blah\n", err
|
||||
end
|
||||
|
||||
def test_standard_exception_handling_system_exit
|
||||
out, err = capture_io do
|
||||
e = assert_raises SystemExit do
|
||||
@app.standard_exception_handling do
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 0, e.status
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
assert_empty err
|
||||
end
|
||||
|
||||
def test_standard_exception_handling_system_exit_nonzero
|
||||
out, err = capture_io do
|
||||
e = assert_raises SystemExit do
|
||||
@app.standard_exception_handling do
|
||||
exit 5
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 5, e.status
|
||||
end
|
||||
|
||||
assert_empty out
|
||||
assert_empty err
|
||||
end
|
||||
|
||||
def util_loader
|
||||
loader = Object.new
|
||||
|
||||
loader.instance_variable_set :@load_called, false
|
||||
def loader.load arg
|
||||
raise ArgumentError, arg unless arg == 'x.dummy'
|
||||
@load_called = true
|
||||
end
|
||||
|
||||
loader.instance_variable_set :@make_dummy_called, false
|
||||
def loader.make_dummy
|
||||
@make_dummy_called = true
|
||||
end
|
||||
|
||||
loader
|
||||
end
|
||||
|
||||
end
|
|
@ -1,468 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
TESTING_REQUIRE = []
|
||||
|
||||
class TestRakeApplicationOptions < Rake::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
@testkey = ENV['TESTKEY']
|
||||
clear_argv
|
||||
Rake::FileUtilsExt.verbose_flag = false
|
||||
Rake::FileUtilsExt.nowrite_flag = false
|
||||
TESTING_REQUIRE.clear
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV['TESTKEY'] = @testkey
|
||||
clear_argv
|
||||
Rake::FileUtilsExt.verbose_flag = false
|
||||
Rake::FileUtilsExt.nowrite_flag = false
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def clear_argv
|
||||
ARGV.pop until ARGV.empty?
|
||||
end
|
||||
|
||||
def test_default_options
|
||||
opts = command_line
|
||||
assert_nil opts.backtrace
|
||||
assert_nil opts.dryrun
|
||||
assert_nil opts.ignore_system
|
||||
assert_nil opts.load_system
|
||||
assert_nil opts.always_multitask
|
||||
assert_nil opts.nosearch
|
||||
assert_equal ['rakelib'], opts.rakelib
|
||||
assert_nil opts.show_prereqs
|
||||
assert_nil opts.show_task_pattern
|
||||
assert_nil opts.show_tasks
|
||||
assert_nil opts.silent
|
||||
assert_nil opts.trace
|
||||
assert_nil opts.thread_pool_size
|
||||
assert_equal ['rakelib'], opts.rakelib
|
||||
assert ! Rake::FileUtilsExt.verbose_flag
|
||||
assert ! Rake::FileUtilsExt.nowrite_flag
|
||||
end
|
||||
|
||||
def test_dry_run
|
||||
flags('--dry-run', '-n') do |opts|
|
||||
assert opts.dryrun
|
||||
assert opts.trace
|
||||
assert Rake::FileUtilsExt.verbose_flag
|
||||
assert Rake::FileUtilsExt.nowrite_flag
|
||||
end
|
||||
end
|
||||
|
||||
def test_describe
|
||||
flags('--describe') do |opts|
|
||||
assert_equal :describe, opts.show_tasks
|
||||
assert_equal(//.to_s, opts.show_task_pattern.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_describe_with_pattern
|
||||
flags('--describe=X') do |opts|
|
||||
assert_equal :describe, opts.show_tasks
|
||||
assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_execute
|
||||
$xyzzy = 0
|
||||
flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
|
||||
assert_equal 1, $xyzzy
|
||||
assert_equal :exit, @exit
|
||||
$xyzzy = 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_execute_and_continue
|
||||
$xyzzy = 0
|
||||
flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
|
||||
assert_equal 1, $xyzzy
|
||||
refute_equal :exit, @exit
|
||||
$xyzzy = 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_execute_and_print
|
||||
$xyzzy = 0
|
||||
out, = capture_io do
|
||||
flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
|
||||
assert_equal 'pugh', $xyzzy
|
||||
assert_equal :exit, @exit
|
||||
$xyzzy = 0
|
||||
end
|
||||
end
|
||||
|
||||
assert_match(/^pugh$/, out)
|
||||
end
|
||||
|
||||
def test_help
|
||||
out, = capture_io do
|
||||
flags '--help', '-H', '-h'
|
||||
end
|
||||
|
||||
assert_match(/\Arake/, out)
|
||||
assert_match(/\boptions\b/, out)
|
||||
assert_match(/\btargets\b/, out)
|
||||
assert_equal :exit, @exit
|
||||
end
|
||||
|
||||
def test_jobs
|
||||
flags([]) do |opts|
|
||||
assert_nil opts.thread_pool_size
|
||||
end
|
||||
flags(['--jobs', '0'], ['-j', '0']) do |opts|
|
||||
assert_equal 0, opts.thread_pool_size
|
||||
end
|
||||
flags(['--jobs', '1'], ['-j', '1']) do |opts|
|
||||
assert_equal 0, opts.thread_pool_size
|
||||
end
|
||||
flags(['--jobs', '4'], ['-j', '4']) do |opts|
|
||||
assert_equal 3, opts.thread_pool_size
|
||||
end
|
||||
flags(['--jobs', 'asdas'], ['-j', 'asdas']) do |opts|
|
||||
assert_equal Rake.suggested_thread_count-1, opts.thread_pool_size
|
||||
end
|
||||
flags('--jobs', '-j') do |opts|
|
||||
assert opts.thread_pool_size > 1_000_000, "thread pool size should be huge (was #{opts.thread_pool_size})"
|
||||
end
|
||||
end
|
||||
|
||||
def test_libdir
|
||||
flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
|
||||
$:.include?('xx')
|
||||
end
|
||||
ensure
|
||||
$:.delete('xx')
|
||||
end
|
||||
|
||||
def test_multitask
|
||||
flags('--multitask', '-m') do |opts|
|
||||
assert_equal opts.always_multitask, true
|
||||
end
|
||||
end
|
||||
|
||||
def test_rakefile
|
||||
flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
|
||||
assert_equal ['RF'], @app.instance_eval { @rakefiles }
|
||||
end
|
||||
end
|
||||
|
||||
def test_rakelib
|
||||
dirs = %w(A B C).join(File::PATH_SEPARATOR)
|
||||
flags(
|
||||
['--rakelibdir', dirs],
|
||||
["--rakelibdir=#{dirs}"],
|
||||
['-R', dirs],
|
||||
["-R#{dirs}"]) do |opts|
|
||||
assert_equal ['A', 'B', 'C'], opts.rakelib
|
||||
end
|
||||
end
|
||||
|
||||
def test_require
|
||||
$LOAD_PATH.unshift @tempdir
|
||||
|
||||
open 'reqfile.rb', 'w' do |io| io << 'TESTING_REQUIRE << 1' end
|
||||
open 'reqfile2.rb', 'w' do |io| io << 'TESTING_REQUIRE << 2' end
|
||||
open 'reqfile3.rake', 'w' do |io| io << 'TESTING_REQUIRE << 3' end
|
||||
|
||||
flags(['--require', 'reqfile'], '-rreqfile2', '-rreqfile3')
|
||||
|
||||
assert_includes TESTING_REQUIRE, 1
|
||||
assert_includes TESTING_REQUIRE, 2
|
||||
assert_includes TESTING_REQUIRE, 3
|
||||
|
||||
assert_equal 3, TESTING_REQUIRE.size
|
||||
ensure
|
||||
$LOAD_PATH.delete @tempdir
|
||||
end
|
||||
|
||||
def test_missing_require
|
||||
ex = assert_raises(LoadError) do
|
||||
flags(['--require', 'test/missing']) do |opts|
|
||||
end
|
||||
end
|
||||
assert_match(/such file/, ex.message)
|
||||
assert_match(/test\/missing/, ex.message)
|
||||
end
|
||||
|
||||
def test_prereqs
|
||||
flags('--prereqs', '-P') do |opts|
|
||||
assert opts.show_prereqs
|
||||
end
|
||||
end
|
||||
|
||||
def test_quiet
|
||||
Rake::FileUtilsExt.verbose_flag = true
|
||||
flags('--quiet', '-q') do |opts|
|
||||
assert ! Rake::FileUtilsExt.verbose_flag, "verbose flag should be false"
|
||||
assert ! opts.silent, "should not be silent"
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_search
|
||||
flags('--nosearch', '--no-search', '-N') do |opts|
|
||||
assert opts.nosearch
|
||||
end
|
||||
end
|
||||
|
||||
def test_silent
|
||||
Rake::FileUtilsExt.verbose_flag = true
|
||||
flags('--silent', '-s') do |opts|
|
||||
assert ! Rake::FileUtilsExt.verbose_flag, "verbose flag should be false"
|
||||
assert opts.silent, "should be silent"
|
||||
end
|
||||
end
|
||||
|
||||
def test_system
|
||||
flags('--system', '-g') do |opts|
|
||||
assert opts.load_system
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_system
|
||||
flags('--no-system', '-G') do |opts|
|
||||
assert opts.ignore_system
|
||||
end
|
||||
end
|
||||
|
||||
def test_trace
|
||||
flags('--trace', '-t') do |opts|
|
||||
assert opts.trace, "should enable trace option"
|
||||
assert opts.backtrace, "should enabled backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert Rake::FileUtilsExt.verbose_flag
|
||||
assert ! Rake::FileUtilsExt.nowrite_flag
|
||||
end
|
||||
end
|
||||
|
||||
def test_trace_with_stdout
|
||||
flags('--trace=stdout', '-tstdout') do |opts|
|
||||
assert opts.trace, "should enable trace option"
|
||||
assert opts.backtrace, "should enabled backtrace option"
|
||||
assert_equal $stdout, opts.trace_output
|
||||
assert Rake::FileUtilsExt.verbose_flag
|
||||
assert ! Rake::FileUtilsExt.nowrite_flag
|
||||
end
|
||||
end
|
||||
|
||||
def test_trace_with_stderr
|
||||
flags('--trace=stderr', '-tstderr') do |opts|
|
||||
assert opts.trace, "should enable trace option"
|
||||
assert opts.backtrace, "should enabled backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert Rake::FileUtilsExt.verbose_flag
|
||||
assert ! Rake::FileUtilsExt.nowrite_flag
|
||||
end
|
||||
end
|
||||
|
||||
def test_trace_with_error
|
||||
ex = assert_raises(Rake::CommandLineOptionError) do
|
||||
flags('--trace=xyzzy') do |opts| end
|
||||
end
|
||||
assert_match(/un(known|recognized).*\btrace\b.*xyzzy/i, ex.message)
|
||||
end
|
||||
|
||||
def test_trace_with_following_task_name
|
||||
flags(['--trace', 'taskname'], ['-t', 'taskname']) do |opts|
|
||||
assert opts.trace, "should enable trace option"
|
||||
assert opts.backtrace, "should enabled backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert Rake::FileUtilsExt.verbose_flag
|
||||
assert_equal ['taskname'], @app.top_level_tasks
|
||||
end
|
||||
end
|
||||
|
||||
def test_backtrace
|
||||
flags('--backtrace') do |opts|
|
||||
assert opts.backtrace, "should enable backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert ! opts.trace, "should not enable trace option"
|
||||
end
|
||||
end
|
||||
|
||||
def test_backtrace_with_stdout
|
||||
flags('--backtrace=stdout') do |opts|
|
||||
assert opts.backtrace, "should enable backtrace option"
|
||||
assert_equal $stdout, opts.trace_output
|
||||
assert ! opts.trace, "should not enable trace option"
|
||||
end
|
||||
end
|
||||
|
||||
def test_backtrace_with_stderr
|
||||
flags('--backtrace=stderr') do |opts|
|
||||
assert opts.backtrace, "should enable backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert ! opts.trace, "should not enable trace option"
|
||||
end
|
||||
end
|
||||
|
||||
def test_backtrace_with_error
|
||||
ex = assert_raises(Rake::CommandLineOptionError) do
|
||||
flags('--backtrace=xyzzy') do |opts| end
|
||||
end
|
||||
assert_match(/un(known|recognized).*\bbacktrace\b.*xyzzy/i, ex.message)
|
||||
end
|
||||
|
||||
def test_backtrace_with_following_task_name
|
||||
flags(['--backtrace', 'taskname']) do |opts|
|
||||
assert ! opts.trace, "should enable trace option"
|
||||
assert opts.backtrace, "should enabled backtrace option"
|
||||
assert_equal $stderr, opts.trace_output
|
||||
assert_equal ['taskname'], @app.top_level_tasks
|
||||
end
|
||||
end
|
||||
|
||||
def test_trace_rules
|
||||
flags('--rules') do |opts|
|
||||
assert opts.trace_rules
|
||||
end
|
||||
end
|
||||
|
||||
def test_tasks
|
||||
flags('--tasks', '-T') do |opts|
|
||||
assert_equal :tasks, opts.show_tasks
|
||||
assert_equal(//.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal nil, opts.show_all_tasks
|
||||
end
|
||||
flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
|
||||
assert_equal :tasks, opts.show_tasks
|
||||
assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal nil, opts.show_all_tasks
|
||||
end
|
||||
flags(['--tasks', 'xyz', '--comments']) do |opts|
|
||||
assert_equal :tasks, opts.show_tasks
|
||||
assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal false, opts.show_all_tasks
|
||||
end
|
||||
end
|
||||
|
||||
def test_where
|
||||
flags('--where', '-W') do |opts|
|
||||
assert_equal :lines, opts.show_tasks
|
||||
assert_equal(//.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal true, opts.show_all_tasks
|
||||
end
|
||||
flags(['--where', 'xyz'], ['-Wxyz']) do |opts|
|
||||
assert_equal :lines, opts.show_tasks
|
||||
assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal true, opts.show_all_tasks
|
||||
end
|
||||
flags(['--where', 'xyz', '--comments'], ['-Wxyz', '--comments']) do |opts|
|
||||
assert_equal :lines, opts.show_tasks
|
||||
assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
|
||||
assert_equal false, opts.show_all_tasks
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_deprecated_messages
|
||||
flags('--no-deprecation-warnings', '-X') do |opts|
|
||||
assert opts.ignore_deprecate
|
||||
end
|
||||
end
|
||||
|
||||
def test_verbose
|
||||
capture_io do
|
||||
flags('--verbose', '-v') do |opts|
|
||||
assert Rake::FileUtilsExt.verbose_flag, "verbose should be true"
|
||||
assert ! opts.silent, "opts should not be silent"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_version
|
||||
out, _ = capture_io do
|
||||
flags '--version', '-V'
|
||||
end
|
||||
|
||||
assert_match(/\bversion\b/, out)
|
||||
assert_match(/\b#{RAKEVERSION}\b/, out)
|
||||
assert_equal :exit, @exit
|
||||
end
|
||||
|
||||
def test_bad_option
|
||||
_, err = capture_io do
|
||||
ex = assert_raises(OptionParser::InvalidOption) do
|
||||
flags('--bad-option')
|
||||
end
|
||||
|
||||
if ex.message =~ /^While/ # Ruby 1.9 error message
|
||||
assert_match(/while parsing/i, ex.message)
|
||||
else # Ruby 1.8 error message
|
||||
assert_match(/(invalid|unrecognized) option/i, ex.message)
|
||||
assert_match(/--bad-option/, ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal '', err
|
||||
end
|
||||
|
||||
def test_task_collection
|
||||
command_line("a", "b")
|
||||
assert_equal ["a", "b"], @tasks.sort
|
||||
end
|
||||
|
||||
def test_default_task_collection
|
||||
command_line()
|
||||
assert_equal ["default"], @tasks
|
||||
end
|
||||
|
||||
def test_environment_definition
|
||||
ENV.delete('TESTKEY')
|
||||
command_line("TESTKEY=12")
|
||||
assert_equal '12', ENV['TESTKEY']
|
||||
end
|
||||
|
||||
def test_multiline_environment_definition
|
||||
ENV.delete('TESTKEY')
|
||||
command_line("TESTKEY=a\nb\n")
|
||||
assert_equal "a\nb\n", ENV['TESTKEY']
|
||||
end
|
||||
|
||||
def test_environment_and_tasks_together
|
||||
ENV.delete('TESTKEY')
|
||||
command_line("a", "b", "TESTKEY=12")
|
||||
assert_equal ["a", "b"], @tasks.sort
|
||||
assert_equal '12', ENV['TESTKEY']
|
||||
end
|
||||
|
||||
def test_rake_explicit_task_library
|
||||
Rake.add_rakelib 'app/task', 'other'
|
||||
|
||||
libs = Rake.application.options.rakelib
|
||||
|
||||
assert libs.include?("app/task")
|
||||
assert libs.include?("other")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def flags(*sets)
|
||||
sets.each do |set|
|
||||
ARGV.clear
|
||||
|
||||
@exit = catch(:system_exit) { command_line(*set) }
|
||||
|
||||
yield(@app.options) if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
def command_line(*options)
|
||||
options.each do |opt| ARGV << opt end
|
||||
@app = Rake::Application.new
|
||||
def @app.exit(*args)
|
||||
throw :system_exit, :exit
|
||||
end
|
||||
@app.instance_eval do
|
||||
args = handle_options
|
||||
collect_command_line_tasks(args)
|
||||
end
|
||||
@tasks = @app.top_level_tasks
|
||||
@app.options
|
||||
end
|
||||
end
|
|
@ -1,119 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'open3'
|
||||
|
||||
class TestBacktraceSuppression < Rake::TestCase
|
||||
def test_bin_rake_suppressed
|
||||
paths = ["something/bin/rake:12"]
|
||||
|
||||
actual = Rake::Backtrace.collapse(paths)
|
||||
|
||||
assert_equal [], actual
|
||||
end
|
||||
|
||||
def test_system_dir_suppressed
|
||||
path = RbConfig::CONFIG['rubylibprefix']
|
||||
skip if path.nil?
|
||||
path = File.expand_path path
|
||||
|
||||
paths = [path + ":12"]
|
||||
|
||||
actual = Rake::Backtrace.collapse(paths)
|
||||
|
||||
assert_equal [], actual
|
||||
end
|
||||
|
||||
def test_near_system_dir_isnt_suppressed
|
||||
path = RbConfig::CONFIG['rubylibprefix']
|
||||
skip if path.nil?
|
||||
path = File.expand_path path
|
||||
|
||||
paths = [" " + path + ":12"]
|
||||
|
||||
actual = Rake::Backtrace.collapse(paths)
|
||||
|
||||
assert_equal paths, actual
|
||||
end
|
||||
end
|
||||
|
||||
class TestRakeBacktrace < Rake::TestCase
|
||||
include RubyRunner
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
skip 'tmpdir is suppressed in backtrace' if
|
||||
Rake::Backtrace::SUPPRESS_PATTERN =~ Dir.pwd
|
||||
end
|
||||
|
||||
def invoke(*args)
|
||||
rake(*args)
|
||||
@err
|
||||
end
|
||||
|
||||
def test_single_collapse
|
||||
rakefile %q{
|
||||
task :foo do
|
||||
raise "foooo!"
|
||||
end
|
||||
}
|
||||
|
||||
lines = invoke("foo").split("\n")
|
||||
|
||||
assert_equal "rake aborted!", lines[0]
|
||||
assert_equal "foooo!", lines[1]
|
||||
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!i, lines
|
||||
assert_something_matches %r!\ATasks:!, lines
|
||||
end
|
||||
|
||||
def test_multi_collapse
|
||||
rakefile %q{
|
||||
task :foo do
|
||||
Rake.application.invoke_task(:bar)
|
||||
end
|
||||
task :bar do
|
||||
raise "barrr!"
|
||||
end
|
||||
}
|
||||
|
||||
lines = invoke("foo").split("\n")
|
||||
|
||||
assert_equal "rake aborted!", lines[0]
|
||||
assert_equal "barrr!", lines[1]
|
||||
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:6!i, lines
|
||||
assert_something_matches %r!\A#{Regexp.quote Dir.pwd}/Rakefile:3!i, lines
|
||||
assert_something_matches %r!\ATasks:!, lines
|
||||
end
|
||||
|
||||
def test_suppress_option
|
||||
rakefile %q{
|
||||
task :baz do
|
||||
raise "bazzz!"
|
||||
end
|
||||
}
|
||||
|
||||
lines = invoke("baz").split("\n")
|
||||
assert_equal "rake aborted!", lines[0]
|
||||
assert_equal "bazzz!", lines[1]
|
||||
assert_something_matches %r!Rakefile!i, lines
|
||||
|
||||
lines = invoke("--suppress-backtrace", ".ak.file", "baz").split("\n")
|
||||
assert_equal "rake aborted!", lines[0]
|
||||
assert_equal "bazzz!", lines[1]
|
||||
refute_match %r!Rakefile!i, lines[2]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Assert that the pattern matches at least one line in +lines+.
|
||||
def assert_something_matches(pattern, lines)
|
||||
lines.each do |ln|
|
||||
if pattern =~ ln
|
||||
assert_match pattern, ln
|
||||
return
|
||||
end
|
||||
end
|
||||
flunk "expected #{pattern.inspect} to match something in:\n" +
|
||||
"#{lines.join("\n ")}"
|
||||
end
|
||||
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'rake/clean'
|
||||
|
||||
class TestRakeClean < Rake::TestCase
|
||||
def test_clean
|
||||
load 'rake/clean.rb', true
|
||||
|
||||
assert Rake::Task['clean'], "Should define clean"
|
||||
assert Rake::Task['clobber'], "Should define clobber"
|
||||
assert Rake::Task['clobber'].prerequisites.include?("clean"),
|
||||
"Clobber should require clean"
|
||||
end
|
||||
|
||||
def test_cleanup
|
||||
file_name = create_undeletable_file
|
||||
|
||||
out, _ = capture_io do
|
||||
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
||||
end
|
||||
assert_match(/failed to remove/i, out)
|
||||
|
||||
ensure
|
||||
remove_undeletable_file
|
||||
end
|
||||
|
||||
def test_cleanup_ignores_missing_files
|
||||
file_name = File.join(@tempdir, "missing_directory", "no_such_file")
|
||||
|
||||
out, _ = capture_io do
|
||||
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
||||
end
|
||||
refute_match(/failed to remove/i, out)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_undeletable_file
|
||||
dir_name = File.join(@tempdir, "deletedir")
|
||||
file_name = File.join(dir_name, "deleteme")
|
||||
FileUtils.mkdir(dir_name)
|
||||
FileUtils.touch(file_name)
|
||||
FileUtils.chmod(0, file_name)
|
||||
FileUtils.chmod(0, dir_name)
|
||||
begin
|
||||
FileUtils.chmod(0644, file_name)
|
||||
rescue
|
||||
file_name
|
||||
else
|
||||
skip "Permission to delete files is different on thie system"
|
||||
end
|
||||
end
|
||||
|
||||
def remove_undeletable_file
|
||||
dir_name = File.join(@tempdir, "deletedir")
|
||||
file_name = File.join(dir_name, "deleteme")
|
||||
FileUtils.chmod(0777, dir_name)
|
||||
FileUtils.chmod(0777, file_name)
|
||||
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
||||
Rake::Cleaner.cleanup(dir_name, :verbose => false)
|
||||
end
|
||||
end
|
|
@ -1,68 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeCpuCounter < Rake::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
@cpu_counter = Rake::CpuCounter.new
|
||||
end
|
||||
|
||||
def test_count
|
||||
num = @cpu_counter.count
|
||||
skip 'cannot count CPU' if num == nil
|
||||
assert_kind_of Numeric, num
|
||||
assert_operator num, :>=, 1
|
||||
end
|
||||
|
||||
def test_count_with_default_nil
|
||||
def @cpu_counter.count; nil; end
|
||||
assert_equal(8, @cpu_counter.count_with_default(8))
|
||||
assert_equal(4, @cpu_counter.count_with_default)
|
||||
end
|
||||
|
||||
def test_count_with_default_raise
|
||||
def @cpu_counter.count; raise; end
|
||||
assert_equal(8, @cpu_counter.count_with_default(8))
|
||||
assert_equal(4, @cpu_counter.count_with_default)
|
||||
end
|
||||
|
||||
class TestClassMethod < Rake::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@klass = Class.new(Rake::CpuCounter)
|
||||
end
|
||||
|
||||
def test_count
|
||||
@klass.class_eval do
|
||||
def count; 8; end
|
||||
end
|
||||
assert_equal(8, @klass.count)
|
||||
end
|
||||
|
||||
def test_count_nil
|
||||
counted = false
|
||||
@klass.class_eval do
|
||||
define_method(:count) do
|
||||
counted = true
|
||||
nil
|
||||
end
|
||||
end
|
||||
assert_equal(4, @klass.count)
|
||||
assert_equal(true, counted)
|
||||
end
|
||||
|
||||
def test_count_raise
|
||||
counted = false
|
||||
@klass.class_eval do
|
||||
define_method(:count) do
|
||||
counted = true
|
||||
raise
|
||||
end
|
||||
end
|
||||
assert_equal(4, @klass.count)
|
||||
assert_equal(true, counted)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
|
||||
class TestRakeDefinitions < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
EXISTINGFILE = "existing"
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
Task.clear
|
||||
end
|
||||
|
||||
def test_task
|
||||
done = false
|
||||
task :one => [:two] do done = true end
|
||||
task :two
|
||||
task :three => [:one, :two]
|
||||
check_tasks(:one, :two, :three)
|
||||
assert done, "Should be done"
|
||||
end
|
||||
|
||||
def test_file_task
|
||||
done = false
|
||||
file "one" => "two" do done = true end
|
||||
file "two"
|
||||
file "three" => ["one", "two"]
|
||||
check_tasks("one", "two", "three")
|
||||
assert done, "Should be done"
|
||||
end
|
||||
|
||||
def check_tasks(n1, n2, n3)
|
||||
t = Task[n1]
|
||||
assert Task === t, "Should be a Task"
|
||||
assert_equal n1.to_s, t.name
|
||||
assert_equal [n2.to_s], t.prerequisites.map { |n| n.to_s }
|
||||
t.invoke
|
||||
t2 = Task[n2]
|
||||
assert_equal FileList[], t2.prerequisites
|
||||
t3 = Task[n3]
|
||||
assert_equal [n1.to_s, n2.to_s], t3.prerequisites.map { |n| n.to_s }
|
||||
end
|
||||
|
||||
def test_incremental_definitions
|
||||
runs = []
|
||||
task :t1 => [:t2] do runs << "A"; 4321 end
|
||||
task :t1 => [:t3] do runs << "B"; 1234 end
|
||||
task :t1 => [:t3]
|
||||
task :t2
|
||||
task :t3
|
||||
Task[:t1].invoke
|
||||
assert_equal ["A", "B"], runs
|
||||
assert_equal ["t2", "t3"], Task[:t1].prerequisites
|
||||
end
|
||||
|
||||
def test_missing_dependencies
|
||||
task :x => ["missing"]
|
||||
assert_raises(RuntimeError) { Task[:x].invoke }
|
||||
end
|
||||
|
||||
def test_falsey_dependencies
|
||||
task :x => nil
|
||||
assert_equal [], Task[:x].prerequisites
|
||||
end
|
||||
|
||||
def test_implicit_file_dependencies
|
||||
runs = []
|
||||
create_existing_file
|
||||
task :y => [EXISTINGFILE] do |t| runs << t.name end
|
||||
Task[:y].invoke
|
||||
assert_equal runs, ['y']
|
||||
end
|
||||
|
||||
private # ----------------------------------------------------------
|
||||
|
||||
def create_existing_file
|
||||
Dir.mkdir File.dirname(EXISTINGFILE) unless
|
||||
File.exist?(File.dirname(EXISTINGFILE))
|
||||
open(EXISTINGFILE, "w") do |f| f.puts "HI" end unless
|
||||
File.exist?(EXISTINGFILE)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,76 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
require 'pathname'
|
||||
|
||||
class TestRakeDirectoryTask < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
def test_directory
|
||||
desc "DESC"
|
||||
|
||||
directory "a/b/c"
|
||||
|
||||
assert_equal FileCreationTask, Task["a"].class
|
||||
assert_equal FileCreationTask, Task["a/b"].class
|
||||
assert_equal FileCreationTask, Task["a/b/c"].class
|
||||
|
||||
assert_nil Task["a"].comment
|
||||
assert_nil Task["a/b"].comment
|
||||
assert_equal "DESC", Task["a/b/c"].comment
|
||||
|
||||
verbose(false) {
|
||||
Task['a/b'].invoke
|
||||
}
|
||||
|
||||
assert File.exist?("a/b")
|
||||
refute File.exist?("a/b/c")
|
||||
end
|
||||
|
||||
def test_directory_colon
|
||||
directory "a:b"
|
||||
|
||||
assert_equal FileCreationTask, Task['a:b'].class
|
||||
end unless Rake::Win32.windows?
|
||||
|
||||
if Rake::Win32.windows?
|
||||
def test_directory_win32
|
||||
desc "WIN32 DESC"
|
||||
directory 'c:/a/b/c'
|
||||
assert_equal FileTask, Task['c:'].class
|
||||
assert_equal FileCreationTask, Task['c:/a'].class
|
||||
assert_equal FileCreationTask, Task['c:/a/b'].class
|
||||
assert_equal FileCreationTask, Task['c:/a/b/c'].class
|
||||
assert_nil Task['c:/'].comment
|
||||
assert_equal "WIN32 DESC", Task['c:/a/b/c'].comment
|
||||
assert_nil Task['c:/a/b'].comment
|
||||
end
|
||||
end
|
||||
|
||||
def test_can_use_blocks
|
||||
runlist = []
|
||||
|
||||
t1 = directory("a/b/c" => :t2) { |t| runlist << t.name }
|
||||
task(:t2) { |t| runlist << t.name }
|
||||
|
||||
verbose(false) {
|
||||
t1.invoke
|
||||
}
|
||||
|
||||
assert_equal Task["a/b/c"], t1
|
||||
assert_equal FileCreationTask, Task["a/b/c"].class
|
||||
assert_equal ["t2", "a/b/c"], runlist
|
||||
assert File.directory?("a/b/c")
|
||||
end
|
||||
|
||||
def test_can_use_pathname
|
||||
directory Pathname.new "a/b/c"
|
||||
|
||||
assert_equal FileCreationTask, Task["a/b/c"].class
|
||||
|
||||
verbose(false) {
|
||||
Task['a/b/c'].invoke
|
||||
}
|
||||
|
||||
assert File.directory?("a/b/c")
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeDsl < Rake::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
Rake::Task.clear
|
||||
end
|
||||
|
||||
def test_namespace_command
|
||||
namespace "n" do
|
||||
task "t"
|
||||
end
|
||||
refute_nil Rake::Task["n:t"]
|
||||
end
|
||||
|
||||
def test_namespace_command_with_bad_name
|
||||
ex = assert_raises(ArgumentError) do
|
||||
namespace 1 do end
|
||||
end
|
||||
assert_match(/string/i, ex.message)
|
||||
assert_match(/symbol/i, ex.message)
|
||||
end
|
||||
|
||||
def test_namespace_command_with_a_string_like_object
|
||||
name = Object.new
|
||||
def name.to_str
|
||||
"bob"
|
||||
end
|
||||
namespace name do
|
||||
task "t"
|
||||
end
|
||||
refute_nil Rake::Task["bob:t"]
|
||||
end
|
||||
|
||||
def test_no_commands_constant
|
||||
assert ! defined?(Commands), "should not define Commands"
|
||||
end
|
||||
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeEarlyTime < Rake::TestCase
|
||||
def test_create
|
||||
early = Rake::EarlyTime.instance
|
||||
assert early <= Time.now
|
||||
assert early < Time.now
|
||||
assert early != Time.now
|
||||
assert Time.now > early
|
||||
assert Time.now >= early
|
||||
assert Time.now != early
|
||||
end
|
||||
|
||||
def test_equality
|
||||
early = Rake::EarlyTime.instance
|
||||
assert_equal early, early, "two early times should be equal"
|
||||
end
|
||||
|
||||
def test_original_time_compare_is_not_messed_up
|
||||
t1 = Time.mktime(1970, 1, 1, 0, 0, 0)
|
||||
t2 = Time.now
|
||||
assert t1 < t2
|
||||
assert t2 > t1
|
||||
assert t1 == t1
|
||||
assert t2 == t2
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal "<EARLY TIME>", Rake::EARLY.to_s
|
||||
end
|
||||
end
|
|
@ -1,59 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'stringio'
|
||||
|
||||
class TestRakeExtension < Rake::TestCase
|
||||
|
||||
module Redirect
|
||||
def error_redirect
|
||||
old_err = $stderr
|
||||
result = StringIO.new
|
||||
$stderr = result
|
||||
yield
|
||||
result
|
||||
ensure
|
||||
$stderr = old_err
|
||||
end
|
||||
end
|
||||
|
||||
class Sample
|
||||
extend Redirect
|
||||
|
||||
def duplicate_method
|
||||
:original
|
||||
end
|
||||
|
||||
OK_ERRS = error_redirect do
|
||||
rake_extension("a") do
|
||||
def ok_method
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
DUP_ERRS = error_redirect do
|
||||
rake_extension("duplicate_method") do
|
||||
def duplicate_method
|
||||
:override
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_methods_actually_exist
|
||||
sample = Sample.new
|
||||
sample.ok_method
|
||||
sample.duplicate_method
|
||||
end
|
||||
|
||||
def test_no_warning_when_defining_ok_method
|
||||
assert_equal "", Sample::OK_ERRS.string
|
||||
end
|
||||
|
||||
def test_extension_complains_when_a_method_that_is_present
|
||||
assert_match(/warning:/i, Sample::DUP_ERRS.string)
|
||||
assert_match(/already exists/i, Sample::DUP_ERRS.string)
|
||||
assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
|
||||
assert_equal :original, Sample.new.duplicate_method
|
||||
end
|
||||
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
|
||||
######################################################################
|
||||
class TestRakeFileCreationTask < Rake::TestCase
|
||||
include Rake
|
||||
include Rake::DSL
|
||||
|
||||
DUMMY_DIR = 'dummy_dir'
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
Task.clear
|
||||
end
|
||||
|
||||
def test_file_needed
|
||||
create_dir DUMMY_DIR
|
||||
fc_task = Task[DUMMY_DIR]
|
||||
assert_equal DUMMY_DIR, fc_task.name
|
||||
FileUtils.rm_rf fc_task.name
|
||||
assert fc_task.needed?, "file should be needed"
|
||||
FileUtils.mkdir fc_task.name
|
||||
assert_equal nil, fc_task.prerequisites.map { |n| Task[n].timestamp }.max
|
||||
assert ! fc_task.needed?, "file should not be needed"
|
||||
end
|
||||
|
||||
def test_directory
|
||||
directory DUMMY_DIR
|
||||
fc_task = Task[DUMMY_DIR]
|
||||
assert_equal DUMMY_DIR, fc_task.name
|
||||
assert FileCreationTask === fc_task
|
||||
end
|
||||
|
||||
def test_no_retriggers_on_filecreate_task
|
||||
create_timed_files(OLDFILE, NEWFILE)
|
||||
t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
|
||||
t2 = Rake.application.intern(FileCreationTask, NEWFILE)
|
||||
assert ! t2.needed?, "Should not need to build new file"
|
||||
assert ! t1.needed?, "Should not need to rebuild old file because of new"
|
||||
end
|
||||
|
||||
def test_no_retriggers_on_file_task
|
||||
create_timed_files(OLDFILE, NEWFILE)
|
||||
t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
|
||||
t2 = Rake.application.intern(FileCreationTask, NEWFILE)
|
||||
assert ! t2.needed?, "Should not need to build new file"
|
||||
assert ! t1.needed?, "Should not need to rebuild old file because of new"
|
||||
end
|
||||
|
||||
def test_very_early_timestamp
|
||||
t1 = Rake.application.intern(FileCreationTask, OLDFILE)
|
||||
assert t1.timestamp < Time.now
|
||||
assert t1.timestamp < Time.now - 1_000_000
|
||||
end
|
||||
end
|
|
@ -1,655 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'pathname'
|
||||
|
||||
class TestRakeFileList < Rake::TestCase
|
||||
FileList = Rake::FileList
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
FileUtils.mkdir "CVS" rescue nil
|
||||
FileUtils.mkdir ".svn" rescue nil
|
||||
@cdir = "cfiles"
|
||||
FileUtils.mkdir @cdir rescue nil
|
||||
FileUtils.touch ".dummy"
|
||||
FileUtils.touch "x.bak"
|
||||
FileUtils.touch "x~"
|
||||
FileUtils.touch "core"
|
||||
FileUtils.touch "x.c"
|
||||
FileUtils.touch "xyz.c"
|
||||
FileUtils.touch "abc.c"
|
||||
FileUtils.touch "abc.h"
|
||||
FileUtils.touch "abc.x"
|
||||
FileUtils.touch "existing"
|
||||
|
||||
open 'xyzzy.txt', 'w' do |io|
|
||||
io.puts 'x'
|
||||
io.puts 'XYZZY'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_delegating_methods_do_not_include_to_a_or_to_ary
|
||||
assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
|
||||
assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
|
||||
assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
|
||||
assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
|
||||
end
|
||||
|
||||
def test_create
|
||||
fl = FileList.new
|
||||
assert_equal 0, fl.size
|
||||
end
|
||||
|
||||
def test_create_with_args
|
||||
fl = FileList.new("*.c", "x")
|
||||
assert_equal ["abc.c", "x.c", "xyz.c", "x"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_create_with_pathname
|
||||
fl = FileList.new(Pathname.new("*.c"))
|
||||
assert_equal ["abc.c", "x.c", "xyz.c"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_create_with_block
|
||||
fl = FileList.new { |f| f.include("x") }
|
||||
assert_equal ["x"], fl.resolve
|
||||
end
|
||||
|
||||
def test_create_with_brackets
|
||||
fl = FileList["*.c", "x"]
|
||||
assert_equal ["abc.c", "x.c", "xyz.c", "x"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_create_with_brackets_and_filelist
|
||||
fl = FileList[FileList["*.c", "x"]]
|
||||
assert_equal ["abc.c", "x.c", "xyz.c", "x"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_include_with_another_array
|
||||
fl = FileList.new.include(["x", "y", "z"])
|
||||
assert_equal ["x", "y", "z"].sort, fl.sort
|
||||
end
|
||||
|
||||
def test_include_with_another_filelist
|
||||
fl = FileList.new.include(FileList["*.c", "x"])
|
||||
assert_equal ["abc.c", "x.c", "xyz.c", "x"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_include_with_pathname
|
||||
fl = FileList.new.include(Pathname.new("*.c"))
|
||||
assert_equal ["abc.c", "x.c", "xyz.c"].sort,
|
||||
fl.sort
|
||||
end
|
||||
|
||||
def test_append
|
||||
fl = FileList.new
|
||||
fl << "a.rb" << "b.rb"
|
||||
assert_equal ['a.rb', 'b.rb'], fl
|
||||
end
|
||||
|
||||
def test_append_pathname
|
||||
fl = FileList.new
|
||||
fl << Pathname.new("a.rb")
|
||||
assert_equal ['a.rb'], fl
|
||||
end
|
||||
|
||||
def test_add_many
|
||||
fl = FileList.new
|
||||
fl.include %w(a d c)
|
||||
fl.include('x', 'y')
|
||||
assert_equal ['a', 'd', 'c', 'x', 'y'], fl
|
||||
assert_equal ['a', 'd', 'c', 'x', 'y'], fl.resolve
|
||||
end
|
||||
|
||||
def test_add_return
|
||||
f = FileList.new
|
||||
g = f << "x"
|
||||
assert_equal f.object_id, g.object_id
|
||||
h = f.include("y")
|
||||
assert_equal f.object_id, h.object_id
|
||||
end
|
||||
|
||||
def test_match
|
||||
fl = FileList.new
|
||||
fl.include '*.c'
|
||||
|
||||
assert_equal %w[abc.c x.c xyz.c], fl.sort
|
||||
end
|
||||
|
||||
def test_add_matching
|
||||
fl = FileList.new
|
||||
fl << "a.java"
|
||||
fl.include '*.c'
|
||||
|
||||
assert_equal %w[a.java abc.c x.c xyz.c], fl.sort
|
||||
end
|
||||
|
||||
def test_multiple_patterns
|
||||
fl = FileList.new
|
||||
fl.include('*.z', '*foo*')
|
||||
|
||||
assert_equal [], fl
|
||||
|
||||
fl.include('*.c', '*xist*')
|
||||
assert_equal %w[x.c xyz.c abc.c existing].sort, fl.sort
|
||||
end
|
||||
|
||||
def test_square_bracket_pattern
|
||||
fl = FileList.new
|
||||
fl.include("abc.[ch]")
|
||||
assert fl.size == 2
|
||||
assert fl.include?("abc.c")
|
||||
assert fl.include?("abc.h")
|
||||
end
|
||||
|
||||
def test_curly_bracket_pattern
|
||||
fl = FileList.new
|
||||
fl.include("abc.{c,h}")
|
||||
assert fl.size == 2
|
||||
assert fl.include?("abc.c")
|
||||
assert fl.include?("abc.h")
|
||||
end
|
||||
|
||||
def test_reject
|
||||
fl = FileList.new
|
||||
fl.include %w(x.c abc.c xyz.c existing)
|
||||
fl.reject! { |fn| fn =~ /^x/ }
|
||||
assert_equal %w[abc.c existing], fl
|
||||
end
|
||||
|
||||
def test_exclude
|
||||
fl = FileList['x.c', 'abc.c', 'xyz.c', 'existing']
|
||||
fl.each { |fn| touch fn, :verbose => false }
|
||||
|
||||
x = fl.exclude(%r{^x.+\.})
|
||||
|
||||
assert_equal FileList, x.class
|
||||
assert_equal %w(x.c abc.c existing), fl
|
||||
assert_equal fl.object_id, x.object_id
|
||||
|
||||
fl.exclude('*.c')
|
||||
|
||||
assert_equal ['existing'], fl
|
||||
|
||||
fl.exclude('existing')
|
||||
|
||||
assert_equal [], fl
|
||||
end
|
||||
|
||||
def test_exclude_pathname
|
||||
fl = FileList['x.c', 'abc.c', 'other']
|
||||
fl.each { |fn| touch fn, :verbose => false }
|
||||
|
||||
fl.exclude(Pathname.new('*.c'))
|
||||
|
||||
assert_equal ['other'], fl
|
||||
end
|
||||
|
||||
def test_excluding_via_block
|
||||
fl = FileList['a.c', 'b.c', 'xyz.c']
|
||||
fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
|
||||
assert fl.excluded_from_list?("xyz.c"), "Should exclude xyz.c"
|
||||
assert_equal ['a.c', 'b.c'], fl
|
||||
end
|
||||
|
||||
def test_exclude_return_on_create
|
||||
fl = FileList['*'].exclude(/.*\.[hcx]$/)
|
||||
assert_equal %w[cfiles existing xyzzy.txt], fl.sort
|
||||
assert_equal FileList, fl.class
|
||||
end
|
||||
|
||||
def test_exclude_with_string_return_on_create
|
||||
fl = FileList['*'].exclude('abc.c')
|
||||
assert_equal %w[abc.h abc.x cfiles existing x.c xyz.c xyzzy.txt], fl.sort
|
||||
assert_equal FileList, fl.class
|
||||
end
|
||||
|
||||
def test_default_exclude
|
||||
fl = FileList.new
|
||||
fl.clear_exclude
|
||||
fl.include("**/*~", "**/*.bak", "**/core")
|
||||
assert fl.member?("core"), "Should include core"
|
||||
assert fl.member?("x.bak"), "Should include .bak files"
|
||||
end
|
||||
|
||||
def test_unique
|
||||
fl = FileList.new
|
||||
fl << "x.c" << "a.c" << "b.rb" << "a.c"
|
||||
assert_equal ['x.c', 'a.c', 'b.rb', 'a.c'], fl
|
||||
fl.uniq!
|
||||
assert_equal ['x.c', 'a.c', 'b.rb'], fl
|
||||
end
|
||||
|
||||
def test_to_string
|
||||
fl = FileList.new
|
||||
fl << "a.java" << "b.java"
|
||||
assert_equal "a.java b.java", fl.to_s
|
||||
assert_equal "a.java b.java", "#{fl}"
|
||||
end
|
||||
|
||||
def test_to_array
|
||||
fl = FileList['a.java', 'b.java']
|
||||
assert_equal ['a.java', 'b.java'], fl.to_a
|
||||
assert_equal Array, fl.to_a.class
|
||||
assert_equal ['a.java', 'b.java'], fl.to_ary
|
||||
assert_equal Array, fl.to_ary.class
|
||||
end
|
||||
|
||||
def test_to_s_pending
|
||||
fl = FileList['abc.*']
|
||||
result = fl.to_s
|
||||
assert_match(%r{abc\.c}, result)
|
||||
assert_match(%r{abc\.h}, result)
|
||||
assert_match(%r{abc\.x}, result)
|
||||
assert_match(%r{(abc\..\b ?){2}}, result)
|
||||
end
|
||||
|
||||
def test_inspect_pending
|
||||
fl = FileList['abc.*']
|
||||
result = fl.inspect
|
||||
assert_match(%r{"abc\.c"}, result)
|
||||
assert_match(%r{"abc\.h"}, result)
|
||||
assert_match(%r{"abc\.x"}, result)
|
||||
assert_match(%r|^\[("abc\..", ){2}"abc\.."\]$|, result)
|
||||
end
|
||||
|
||||
def test_sub
|
||||
fl = FileList["*.c"]
|
||||
f2 = fl.sub(/\.c$/, ".o")
|
||||
assert_equal FileList, f2.class
|
||||
assert_equal ["abc.o", "x.o", "xyz.o"].sort,
|
||||
f2.sort
|
||||
f3 = fl.gsub(/\.c$/, ".o")
|
||||
assert_equal FileList, f3.class
|
||||
assert_equal ["abc.o", "x.o", "xyz.o"].sort,
|
||||
f3.sort
|
||||
end
|
||||
|
||||
def test_claim_to_be_a_kind_of_array
|
||||
fl = FileList['*.c']
|
||||
assert fl.is_a?(Array)
|
||||
assert fl.kind_of?(Array)
|
||||
end
|
||||
|
||||
def test_claim_to_be_a_kind_of_filelist
|
||||
fl = FileList['*.c']
|
||||
assert fl.is_a?(FileList)
|
||||
assert fl.kind_of?(FileList)
|
||||
end
|
||||
|
||||
def test_claim_to_be_a_filelist_instance
|
||||
fl = FileList['*.c']
|
||||
assert fl.instance_of?(FileList)
|
||||
end
|
||||
|
||||
def test_dont_claim_to_be_an_array_instance
|
||||
fl = FileList['*.c']
|
||||
assert ! fl.instance_of?(Array)
|
||||
end
|
||||
|
||||
def test_sub!
|
||||
f = "x/a.c"
|
||||
fl = FileList[f, "x/b.c"]
|
||||
res = fl.sub!(/\.c$/, ".o")
|
||||
assert_equal ["x/a.o", "x/b.o"].sort, fl.sort
|
||||
assert_equal "x/a.c", f
|
||||
assert_equal fl.object_id, res.object_id
|
||||
end
|
||||
|
||||
def test_sub_with_block
|
||||
fl = FileList["src/org/onestepback/a.java", "src/org/onestepback/b.java"]
|
||||
# The block version doesn't work the way I want it to ...
|
||||
# f2 = fl.sub(%r{^src/(.*)\.java$}) { |x| "classes/" + $1 + ".class" }
|
||||
f2 = fl.sub(%r{^src/(.*)\.java$}, "classes/\\1.class")
|
||||
assert_equal [
|
||||
"classes/org/onestepback/a.class",
|
||||
"classes/org/onestepback/b.class"
|
||||
].sort,
|
||||
f2.sort
|
||||
end
|
||||
|
||||
def test_string_ext
|
||||
assert_equal "one.net", "one.two".ext("net")
|
||||
assert_equal "one.net", "one.two".ext(".net")
|
||||
assert_equal "one.net", "one".ext("net")
|
||||
assert_equal "one.net", "one".ext(".net")
|
||||
assert_equal "one.two.net", "one.two.c".ext(".net")
|
||||
assert_equal "one/two.net", "one/two.c".ext(".net")
|
||||
assert_equal "one.x/two.net", "one.x/two.c".ext(".net")
|
||||
assert_equal "one.x/two.net", "one.x/two".ext(".net")
|
||||
assert_equal ".onerc.net", ".onerc.dot".ext("net")
|
||||
assert_equal ".onerc.net", ".onerc".ext("net")
|
||||
assert_equal ".a/.onerc.net", ".a/.onerc".ext("net")
|
||||
assert_equal "one", "one.two".ext('')
|
||||
assert_equal "one", "one.two".ext
|
||||
assert_equal ".one", ".one.two".ext
|
||||
assert_equal ".one", ".one".ext
|
||||
assert_equal ".", ".".ext("c")
|
||||
assert_equal "..", "..".ext("c")
|
||||
# These only need to work in windows
|
||||
if Rake::Win32.windows?
|
||||
assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net")
|
||||
assert_equal "one.x\\two.net", "one.x\\two".ext(".net")
|
||||
end
|
||||
end
|
||||
|
||||
def test_filelist_ext
|
||||
assert_equal FileList['one.c', '.one.c'],
|
||||
FileList['one.net', '.one'].ext('c')
|
||||
end
|
||||
|
||||
def test_gsub
|
||||
fl = FileList["*.c"]
|
||||
f2 = fl.gsub(/a/, "A")
|
||||
assert_equal ["Abc.c", "x.c", "xyz.c"].sort,
|
||||
f2.sort
|
||||
end
|
||||
|
||||
def test_gsub!
|
||||
f = FileList["*.c"]
|
||||
f.gsub!(/a/, "A")
|
||||
assert_equal ["Abc.c", "x.c", "xyz.c"].sort,
|
||||
f.sort
|
||||
end
|
||||
|
||||
def test_egrep_returns_0_if_no_matches
|
||||
files = FileList['test/lib/*_test.rb'].exclude("test/lib/filelist_test.rb")
|
||||
assert_equal 0, files.egrep(/XYZZY/) { }
|
||||
end
|
||||
|
||||
def test_egrep_with_output
|
||||
files = FileList['*.txt']
|
||||
|
||||
out, = capture_io do
|
||||
files.egrep(/XYZZY/)
|
||||
end
|
||||
|
||||
assert_equal "xyzzy.txt:2:XYZZY\n", out
|
||||
end
|
||||
|
||||
def test_egrep_with_block
|
||||
files = FileList['*.txt']
|
||||
found = nil
|
||||
|
||||
files.egrep(/XYZZY/) do |fn, ln, line|
|
||||
found = [fn, ln, line]
|
||||
end
|
||||
|
||||
assert_equal ["xyzzy.txt", 2, "XYZZY\n"], found
|
||||
end
|
||||
|
||||
def test_egrep_with_error
|
||||
files = FileList['*.txt']
|
||||
|
||||
_, err = capture_io do
|
||||
files.egrep(/XYZZY/) do |fn, ln, line |
|
||||
raise "_EGREP_FAILURE_"
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal "Error while processing 'xyzzy.txt': _EGREP_FAILURE_\n", err
|
||||
end
|
||||
|
||||
def test_existing
|
||||
fl = FileList['abc.c', 'notthere.c']
|
||||
assert_equal ["abc.c"], fl.existing
|
||||
assert fl.existing.is_a?(FileList)
|
||||
end
|
||||
|
||||
def test_existing!
|
||||
fl = FileList['abc.c', 'notthere.c']
|
||||
result = fl.existing!
|
||||
assert_equal ["abc.c"], fl
|
||||
assert_equal fl.object_id, result.object_id
|
||||
end
|
||||
|
||||
def test_ignore_special
|
||||
f = FileList['*']
|
||||
assert ! f.include?("CVS"), "Should not contain CVS"
|
||||
assert ! f.include?(".svn"), "Should not contain .svn"
|
||||
assert ! f.include?(".dummy"), "Should not contain dot files"
|
||||
assert ! f.include?("x.bak"), "Should not contain .bak files"
|
||||
assert ! f.include?("x~"), "Should not contain ~ files"
|
||||
assert ! f.include?("core"), "Should not contain core files"
|
||||
end
|
||||
|
||||
def test_clear_ignore_patterns
|
||||
f = FileList['*', '.svn']
|
||||
f.clear_exclude
|
||||
assert f.include?("abc.c")
|
||||
assert f.include?("xyz.c")
|
||||
assert f.include?("CVS")
|
||||
assert f.include?(".svn")
|
||||
assert f.include?("x.bak")
|
||||
assert f.include?("x~")
|
||||
end
|
||||
|
||||
def test_exclude_with_alternate_file_seps
|
||||
fl = FileList.new
|
||||
assert fl.excluded_from_list?("x/CVS/y")
|
||||
assert fl.excluded_from_list?("x\\CVS\\y")
|
||||
assert fl.excluded_from_list?("x/.svn/y")
|
||||
assert fl.excluded_from_list?("x\\.svn\\y")
|
||||
assert fl.excluded_from_list?("x/core")
|
||||
assert fl.excluded_from_list?("x\\core")
|
||||
end
|
||||
|
||||
def test_add_default_exclude_list
|
||||
fl = FileList.new
|
||||
fl.exclude(/~\d+$/)
|
||||
assert fl.excluded_from_list?("x/CVS/y")
|
||||
assert fl.excluded_from_list?("x\\CVS\\y")
|
||||
assert fl.excluded_from_list?("x/.svn/y")
|
||||
assert fl.excluded_from_list?("x\\.svn\\y")
|
||||
assert fl.excluded_from_list?("x/core")
|
||||
assert fl.excluded_from_list?("x\\core")
|
||||
assert fl.excluded_from_list?("x/abc~1")
|
||||
end
|
||||
|
||||
def test_basic_array_functions
|
||||
f = FileList['b', 'c', 'a']
|
||||
assert_equal 'b', f.first
|
||||
assert_equal 'b', f[0]
|
||||
assert_equal 'a', f.last
|
||||
assert_equal 'a', f[2]
|
||||
assert_equal 'a', f[-1]
|
||||
assert_equal ['a', 'b', 'c'], f.sort
|
||||
f.sort!
|
||||
assert_equal ['a', 'b', 'c'], f
|
||||
end
|
||||
|
||||
def test_flatten
|
||||
assert_equal ['a', 'x.c', 'xyz.c', 'abc.c'].sort,
|
||||
['a', FileList['*.c']].flatten.sort
|
||||
end
|
||||
|
||||
def test_clone_and_dup
|
||||
a = FileList['a', 'b', 'c']
|
||||
c = a.clone
|
||||
d = a.dup
|
||||
a << 'd'
|
||||
assert_equal ['a', 'b', 'c', 'd'], a
|
||||
assert_equal ['a', 'b', 'c'], c
|
||||
assert_equal ['a', 'b', 'c'], d
|
||||
end
|
||||
|
||||
def test_dup_and_clone_replicate_taint
|
||||
a = FileList['a', 'b', 'c']
|
||||
a.taint
|
||||
c = a.clone
|
||||
d = a.dup
|
||||
assert c.tainted?, "Clone should be tainted"
|
||||
assert d.tainted?, "Dup should be tainted"
|
||||
end
|
||||
|
||||
def test_duped_items_will_thaw
|
||||
a = FileList['a', 'b', 'c']
|
||||
a.freeze
|
||||
d = a.dup
|
||||
d << 'more'
|
||||
assert_equal ['a', 'b', 'c', 'more'], d
|
||||
end
|
||||
|
||||
def test_cloned_items_stay_frozen
|
||||
a = FileList['a', 'b', 'c']
|
||||
a.freeze
|
||||
c = a.clone
|
||||
assert_raises(TypeError, RuntimeError) do
|
||||
c << 'more'
|
||||
end
|
||||
end
|
||||
|
||||
def test_array_comparisons
|
||||
fl = FileList['b', 'b']
|
||||
a = ['b', 'a']
|
||||
b = ['b', 'b']
|
||||
c = ['b', 'c']
|
||||
assert_equal(1, fl <=> a)
|
||||
assert_equal(0, fl <=> b)
|
||||
assert_equal(-1, fl <=> c)
|
||||
assert_equal(-1, a <=> fl)
|
||||
assert_equal(0, b <=> fl)
|
||||
assert_equal(1, c <=> fl)
|
||||
end
|
||||
|
||||
def test_array_equality
|
||||
a = FileList['a', 'b']
|
||||
b = ['a', 'b']
|
||||
assert a == b
|
||||
assert b == a
|
||||
# assert a.eql?(b)
|
||||
# assert b.eql?(a)
|
||||
assert ! a.equal?(b)
|
||||
assert ! b.equal?(a)
|
||||
end
|
||||
|
||||
def test_enumeration_methods
|
||||
a = FileList['a', 'b']
|
||||
b = a.map { |it| it.upcase }
|
||||
assert_equal ['A', 'B'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.map { |it| it.upcase }
|
||||
assert_equal ['A', 'B'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.sort
|
||||
assert_equal ['a', 'b'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.sort_by { |it| it }
|
||||
assert_equal ['a', 'b'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.select { |it| it == 'b' }
|
||||
assert_equal ['b'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.select { |it| it.size == 1 }
|
||||
assert_equal ['a', 'b'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.reject { |it| it == 'b' }
|
||||
assert_equal ['a'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.grep(/./)
|
||||
assert_equal ['a', 'b'], b
|
||||
assert_equal FileList, b.class
|
||||
|
||||
b = a.partition { |it| it == 'b' }
|
||||
assert_equal [['b'], ['a']], b
|
||||
assert_equal Array, b.class
|
||||
assert_equal FileList, b[0].class
|
||||
assert_equal FileList, b[1].class
|
||||
|
||||
b = a.zip(['x', 'y']).to_a
|
||||
assert_equal [['a', 'x'], ['b', 'y']], b
|
||||
assert_equal Array, b.class
|
||||
assert_equal Array, b[0].class
|
||||
assert_equal Array, b[1].class
|
||||
end
|
||||
|
||||
def test_array_operators
|
||||
a = ['a', 'b']
|
||||
b = ['c', 'd']
|
||||
f = FileList['x', 'y']
|
||||
g = FileList['w', 'z']
|
||||
|
||||
r = f + g
|
||||
assert_equal ['x', 'y', 'w', 'z'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
r = a + g
|
||||
assert_equal ['a', 'b', 'w', 'z'], r
|
||||
assert_equal Array, r.class
|
||||
|
||||
r = f + b
|
||||
assert_equal ['x', 'y', 'c', 'd'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
r = FileList['w', 'x', 'y', 'z'] - f
|
||||
assert_equal ['w', 'z'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
r = FileList['w', 'x', 'y', 'z'] & f
|
||||
assert_equal ['x', 'y'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
r = f * 2
|
||||
assert_equal ['x', 'y', 'x', 'y'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
r = f * ','
|
||||
assert_equal 'x,y', r
|
||||
assert_equal String, r.class
|
||||
|
||||
r = f | ['a', 'x']
|
||||
assert_equal ['a', 'x', 'y'].sort, r.sort
|
||||
assert_equal FileList, r.class
|
||||
end
|
||||
|
||||
def test_other_array_returning_methods
|
||||
f = FileList['a', nil, 'b']
|
||||
r = f.compact
|
||||
assert_equal ['a', 'b'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
f = FileList['a', 'b']
|
||||
r = f.concat(['x', 'y'])
|
||||
assert_equal ['a', 'b', 'x', 'y'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
f = FileList['a', ['b', 'c'], FileList['d', 'e']]
|
||||
r = f.flatten
|
||||
assert_equal ['a', 'b', 'c', 'd', 'e'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
f = FileList['a', 'b', 'a']
|
||||
r = f.uniq
|
||||
assert_equal ['a', 'b'], r
|
||||
assert_equal FileList, r.class
|
||||
|
||||
f = FileList['a', 'b', 'c', 'd']
|
||||
r = f.values_at(1, 3)
|
||||
assert_equal ['b', 'd'], r
|
||||
assert_equal FileList, r.class
|
||||
end
|
||||
|
||||
def test_file_utils_can_use_filelists
|
||||
cfiles = FileList['*.c']
|
||||
|
||||
cp cfiles, @cdir, :verbose => false
|
||||
|
||||
assert File.exist?(File.join(@cdir, 'abc.c'))
|
||||
assert File.exist?(File.join(@cdir, 'xyz.c'))
|
||||
assert File.exist?(File.join(@cdir, 'x.c'))
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeFileListPathMap < Rake::TestCase
|
||||
def test_file_list_supports_pathmap
|
||||
assert_equal ['a', 'b'], FileList['dir/a.rb', 'dir/b.rb'].pathmap("%n")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
require 'pathname'
|
||||
|
||||
class TestRakeFileTask < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
Task.clear
|
||||
@runs = Array.new
|
||||
FileUtils.rm_f NEWFILE
|
||||
FileUtils.rm_f OLDFILE
|
||||
end
|
||||
|
||||
def test_file_need
|
||||
name = "dummy"
|
||||
file name
|
||||
|
||||
ftask = Task[name]
|
||||
|
||||
assert_equal name.to_s, ftask.name
|
||||
File.delete(ftask.name) rescue nil
|
||||
|
||||
assert ftask.needed?, "file should be needed"
|
||||
assert_equal Rake::LATE, ftask.timestamp
|
||||
|
||||
open(ftask.name, "w") { |f| f.puts "HI" }
|
||||
|
||||
assert_equal nil, ftask.prerequisites.map { |n| Task[n].timestamp }.max
|
||||
assert ! ftask.needed?, "file should not be needed"
|
||||
ensure
|
||||
File.delete(ftask.name) rescue nil
|
||||
end
|
||||
|
||||
def test_file_times_new_depends_on_old
|
||||
create_timed_files(OLDFILE, NEWFILE)
|
||||
|
||||
t1 = Rake.application.intern(FileTask, NEWFILE).enhance([OLDFILE])
|
||||
t2 = Rake.application.intern(FileTask, OLDFILE)
|
||||
assert ! t2.needed?, "Should not need to build old file"
|
||||
assert ! t1.needed?, "Should not need to rebuild new file because of old"
|
||||
end
|
||||
|
||||
def test_file_times_new_depend_on_regular_task_timestamps
|
||||
load_phony
|
||||
|
||||
name = "dummy"
|
||||
task name
|
||||
|
||||
create_timed_files(NEWFILE)
|
||||
|
||||
t1 = Rake.application.intern(FileTask, NEWFILE).enhance([name])
|
||||
|
||||
assert t1.needed?, "depending on non-file task uses Time.now"
|
||||
|
||||
task(name => :phony)
|
||||
|
||||
assert t1.needed?, "unless the non-file task has a timestamp"
|
||||
end
|
||||
|
||||
def test_file_times_old_depends_on_new
|
||||
create_timed_files(OLDFILE, NEWFILE)
|
||||
|
||||
t1 = Rake.application.intern(FileTask, OLDFILE).enhance([NEWFILE])
|
||||
t2 = Rake.application.intern(FileTask, NEWFILE)
|
||||
assert ! t2.needed?, "Should not need to build new file"
|
||||
preq_stamp = t1.prerequisites.map { |t| Task[t].timestamp }.max
|
||||
assert_equal t2.timestamp, preq_stamp
|
||||
assert t1.timestamp < preq_stamp, "T1 should be older"
|
||||
assert t1.needed?, "Should need to rebuild old file because of new"
|
||||
end
|
||||
|
||||
def test_file_depends_on_task_depend_on_file
|
||||
create_timed_files(OLDFILE, NEWFILE)
|
||||
|
||||
file NEWFILE => [:obj] do |t| @runs << t.name end
|
||||
task :obj => [OLDFILE] do |t| @runs << t.name end
|
||||
file OLDFILE do |t| @runs << t.name end
|
||||
|
||||
Task[:obj].invoke
|
||||
Task[NEWFILE].invoke
|
||||
assert @runs.include?(NEWFILE)
|
||||
end
|
||||
|
||||
def test_existing_file_depends_on_non_existing_file
|
||||
create_file(OLDFILE)
|
||||
delete_file(NEWFILE)
|
||||
file NEWFILE do |t| @runs << t.name end
|
||||
file OLDFILE => NEWFILE do |t| @runs << t.name end
|
||||
|
||||
Task[OLDFILE].invoke
|
||||
|
||||
assert_equal [NEWFILE, OLDFILE], @runs
|
||||
end
|
||||
|
||||
def test_needed_eh_build_all
|
||||
create_file 'a'
|
||||
|
||||
file 'a'
|
||||
|
||||
a_task = Task['a']
|
||||
|
||||
refute a_task.needed?
|
||||
|
||||
Rake.application.options.build_all = true
|
||||
|
||||
assert a_task.needed?
|
||||
ensure
|
||||
delete_file 'a'
|
||||
end
|
||||
|
||||
def test_needed_eh_dependency
|
||||
create_file 'a', Time.now
|
||||
create_file 'b', Time.now - 60
|
||||
|
||||
create_file 'c', Time.now
|
||||
create_file 'd', Time.now - 60
|
||||
|
||||
file 'b' => 'a'
|
||||
|
||||
b_task = Task['b']
|
||||
|
||||
assert b_task.needed?
|
||||
|
||||
file 'c' => 'd'
|
||||
|
||||
c_task = Task['c']
|
||||
|
||||
refute c_task.needed?
|
||||
ensure
|
||||
delete_file 'old'
|
||||
delete_file 'new'
|
||||
end
|
||||
|
||||
def test_needed_eh_exists
|
||||
name = "dummy"
|
||||
file name
|
||||
|
||||
ftask = Task[name]
|
||||
|
||||
assert ftask.needed?
|
||||
|
||||
create_file name
|
||||
|
||||
refute ftask.needed?
|
||||
ensure
|
||||
delete_file name
|
||||
end
|
||||
|
||||
def test_source_is_first_prerequisite
|
||||
t = file :f => ["preqA", "preqB"]
|
||||
assert_equal "preqA", t.source
|
||||
end
|
||||
|
||||
def test_sources_is_all_prerequisites
|
||||
t = file :f => ["preqA", "preqB"]
|
||||
assert_equal ["preqA", "preqB"], t.sources
|
||||
end
|
||||
|
||||
def test_task_can_be_pathname
|
||||
name = "dummy"
|
||||
file Pathname.new name
|
||||
|
||||
ftask = Task[name]
|
||||
|
||||
assert_equal name.to_s, ftask.name
|
||||
end
|
||||
|
||||
def test_prerequisite_can_be_pathname
|
||||
t = file :f => Pathname.new("preq")
|
||||
assert_equal "preq", t.source
|
||||
end
|
||||
|
||||
# I have currently disabled this test. I'm not convinced that
|
||||
# deleting the file target on failure is always the proper thing to
|
||||
# do. I'm willing to hear input on this topic.
|
||||
def ztest_file_deletes_on_failure
|
||||
task :obj
|
||||
file NEWFILE => [:obj] do |t|
|
||||
FileUtils.touch NEWFILE
|
||||
fail "Ooops"
|
||||
end
|
||||
assert Task[NEWFILE]
|
||||
begin
|
||||
Task[NEWFILE].invoke
|
||||
rescue Exception
|
||||
end
|
||||
assert(! File.exist?(NEWFILE), "NEWFILE should be deleted")
|
||||
end
|
||||
|
||||
def load_phony
|
||||
load File.join(@rake_lib, "rake/phony.rb")
|
||||
end
|
||||
|
||||
end
|
|
@ -1,314 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
require 'stringio'
|
||||
|
||||
class TestRakeFileUtils < Rake::TestCase
|
||||
def setup
|
||||
super
|
||||
@rake_test_sh = ENV['RAKE_TEST_SH']
|
||||
end
|
||||
|
||||
def teardown
|
||||
FileUtils::LN_SUPPORTED[0] = true
|
||||
RakeFileUtils.verbose_flag = Rake::FileUtilsExt::DEFAULT
|
||||
ENV['RAKE_TEST_SH'] = @rake_test_sh
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def test_rm_one_file
|
||||
create_file("a")
|
||||
FileUtils.rm_rf "a"
|
||||
refute File.exist?("a")
|
||||
end
|
||||
|
||||
def test_rm_two_files
|
||||
create_file("a")
|
||||
create_file("b")
|
||||
FileUtils.rm_rf ["a", "b"]
|
||||
refute File.exist?("a")
|
||||
refute File.exist?("b")
|
||||
end
|
||||
|
||||
def test_rm_filelist
|
||||
list = Rake::FileList.new << "a" << "b"
|
||||
list.each { |fn| create_file(fn) }
|
||||
FileUtils.rm_r list
|
||||
refute File.exist?("a")
|
||||
refute File.exist?("b")
|
||||
end
|
||||
|
||||
def test_ln
|
||||
open("a", "w") { |f| f.puts "TEST_LN" }
|
||||
|
||||
Rake::FileUtilsExt.safe_ln("a", "b", :verbose => false)
|
||||
|
||||
assert_equal "TEST_LN\n", File.read('b')
|
||||
end
|
||||
|
||||
class BadLink
|
||||
include Rake::FileUtilsExt
|
||||
attr_reader :cp_args
|
||||
|
||||
def initialize(klass)
|
||||
@failure_class = klass
|
||||
end
|
||||
|
||||
def cp(*args)
|
||||
@cp_args = args
|
||||
end
|
||||
|
||||
def ln(*args)
|
||||
fail @failure_class, "ln not supported"
|
||||
end
|
||||
|
||||
public :safe_ln
|
||||
end
|
||||
|
||||
def test_safe_ln_failover_to_cp_on_standard_error
|
||||
FileUtils::LN_SUPPORTED[0] = true
|
||||
c = BadLink.new(StandardError)
|
||||
c.safe_ln "a", "b"
|
||||
assert_equal ['a', 'b'], c.cp_args
|
||||
c.safe_ln "x", "y"
|
||||
assert_equal ['x', 'y'], c.cp_args
|
||||
end
|
||||
|
||||
def test_safe_ln_failover_to_cp_on_not_implemented_error
|
||||
FileUtils::LN_SUPPORTED[0] = true
|
||||
c = BadLink.new(NotImplementedError)
|
||||
c.safe_ln "a", "b"
|
||||
assert_equal ['a', 'b'], c.cp_args
|
||||
end
|
||||
|
||||
def test_safe_ln_fails_on_script_error
|
||||
FileUtils::LN_SUPPORTED[0] = true
|
||||
c = BadLink.new(ScriptError)
|
||||
assert_raises(ScriptError) do c.safe_ln "a", "b" end
|
||||
end
|
||||
|
||||
def test_verbose
|
||||
verbose true
|
||||
assert_equal true, verbose
|
||||
verbose false
|
||||
assert_equal false, verbose
|
||||
verbose(true) {
|
||||
assert_equal true, verbose
|
||||
}
|
||||
assert_equal false, verbose
|
||||
end
|
||||
|
||||
def test_nowrite
|
||||
nowrite true
|
||||
assert_equal true, nowrite
|
||||
nowrite false
|
||||
assert_equal false, nowrite
|
||||
nowrite(true) {
|
||||
assert_equal true, nowrite
|
||||
}
|
||||
assert_equal false, nowrite
|
||||
end
|
||||
|
||||
def test_file_utils_methods_are_available_at_top_level
|
||||
create_file("a")
|
||||
|
||||
capture_io do
|
||||
rm_rf "a"
|
||||
end
|
||||
|
||||
refute File.exist?("a")
|
||||
end
|
||||
|
||||
def test_fileutils_methods_dont_leak
|
||||
obj = Object.new
|
||||
assert_raises(NoMethodError) { obj.copy } # from FileUtils
|
||||
assert_raises(NoMethodError) { obj.ruby "-v" } # from RubyFileUtils
|
||||
end
|
||||
|
||||
def test_sh
|
||||
shellcommand
|
||||
|
||||
verbose(false) { sh %{#{Rake::TestCase::RUBY} shellcommand.rb} }
|
||||
assert true, "should not fail"
|
||||
end
|
||||
|
||||
def test_sh_with_a_single_string_argument
|
||||
check_expansion
|
||||
|
||||
ENV['RAKE_TEST_SH'] = 'someval'
|
||||
verbose(false) {
|
||||
sh %{#{RUBY} check_expansion.rb #{env_var} someval}
|
||||
}
|
||||
end
|
||||
|
||||
def test_sh_with_multiple_arguments
|
||||
check_no_expansion
|
||||
ENV['RAKE_TEST_SH'] = 'someval'
|
||||
|
||||
verbose(false) {
|
||||
sh RUBY, 'check_no_expansion.rb', env_var, 'someval'
|
||||
}
|
||||
end
|
||||
|
||||
def test_sh_failure
|
||||
shellcommand
|
||||
|
||||
assert_raises(RuntimeError) {
|
||||
verbose(false) { sh %{#{RUBY} shellcommand.rb 1} }
|
||||
}
|
||||
end
|
||||
|
||||
def test_sh_special_handling
|
||||
shellcommand
|
||||
|
||||
count = 0
|
||||
verbose(false) {
|
||||
sh(%{#{RUBY} shellcommand.rb}) do |ok, res|
|
||||
assert(ok)
|
||||
assert_equal 0, res.exitstatus
|
||||
count += 1
|
||||
end
|
||||
sh(%{#{RUBY} shellcommand.rb 1}) do |ok, res|
|
||||
assert(!ok)
|
||||
assert_equal 1, res.exitstatus
|
||||
count += 1
|
||||
end
|
||||
}
|
||||
assert_equal 2, count, "Block count should be 2"
|
||||
end
|
||||
|
||||
def test_sh_noop
|
||||
shellcommand
|
||||
|
||||
verbose(false) { sh %{shellcommand.rb 1}, :noop=>true }
|
||||
assert true, "should not fail"
|
||||
end
|
||||
|
||||
def test_sh_bad_option
|
||||
shellcommand
|
||||
|
||||
ex = assert_raises(ArgumentError) {
|
||||
verbose(false) { sh %{shellcommand.rb}, :bad_option=>true }
|
||||
}
|
||||
assert_match(/bad_option/, ex.message)
|
||||
end
|
||||
|
||||
def test_sh_verbose
|
||||
shellcommand
|
||||
|
||||
_, err = capture_io do
|
||||
verbose(true) {
|
||||
sh %{shellcommand.rb}, :noop=>true
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal "shellcommand.rb\n", err
|
||||
end
|
||||
|
||||
def test_sh_verbose_false
|
||||
shellcommand
|
||||
|
||||
_, err = capture_io do
|
||||
verbose(false) {
|
||||
sh %{shellcommand.rb}, :noop=>true
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal '', err
|
||||
end
|
||||
|
||||
def test_sh_verbose_flag_nil
|
||||
shellcommand
|
||||
|
||||
RakeFileUtils.verbose_flag = nil
|
||||
|
||||
assert_silent do
|
||||
sh %{shellcommand.rb}, :noop=>true
|
||||
end
|
||||
end
|
||||
|
||||
def test_ruby_with_a_single_string_argument
|
||||
check_expansion
|
||||
|
||||
ENV['RAKE_TEST_SH'] = 'someval'
|
||||
|
||||
verbose(false) {
|
||||
replace_ruby {
|
||||
ruby %{check_expansion.rb #{env_var} someval}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_ruby_with_multiple_arguments
|
||||
check_no_expansion
|
||||
|
||||
ENV['RAKE_TEST_SH'] = 'someval'
|
||||
verbose(false) {
|
||||
replace_ruby {
|
||||
ruby 'check_no_expansion.rb', env_var, 'someval'
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_split_all
|
||||
assert_equal ['a'], Rake::FileUtilsExt.split_all('a')
|
||||
assert_equal ['..'], Rake::FileUtilsExt.split_all('..')
|
||||
assert_equal ['/'], Rake::FileUtilsExt.split_all('/')
|
||||
assert_equal ['a', 'b'], Rake::FileUtilsExt.split_all('a/b')
|
||||
assert_equal ['/', 'a', 'b'], Rake::FileUtilsExt.split_all('/a/b')
|
||||
assert_equal ['..', 'a', 'b'], Rake::FileUtilsExt.split_all('../a/b')
|
||||
end
|
||||
|
||||
def command(name, text)
|
||||
open name, 'w', 0750 do |io|
|
||||
io << text
|
||||
end
|
||||
end
|
||||
|
||||
def check_no_expansion
|
||||
command 'check_no_expansion.rb', <<-CHECK_EXPANSION
|
||||
if ARGV[0] != ARGV[1]
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
end
|
||||
CHECK_EXPANSION
|
||||
end
|
||||
|
||||
def check_expansion
|
||||
command 'check_expansion.rb', <<-CHECK_EXPANSION
|
||||
if ARGV[0] != ARGV[1]
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
end
|
||||
CHECK_EXPANSION
|
||||
end
|
||||
|
||||
def replace_ruby
|
||||
ruby = FileUtils::RUBY
|
||||
FileUtils.send :remove_const, :RUBY
|
||||
FileUtils.const_set :RUBY, RUBY
|
||||
yield
|
||||
ensure
|
||||
FileUtils.send :remove_const, :RUBY
|
||||
FileUtils.const_set:RUBY, ruby
|
||||
end
|
||||
|
||||
def shellcommand
|
||||
command 'shellcommand.rb', <<-SHELLCOMMAND
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
exit((ARGV[0] || "0").to_i)
|
||||
SHELLCOMMAND
|
||||
end
|
||||
|
||||
def env_var
|
||||
windows? ? '%RAKE_TEST_SH%' : '$RAKE_TEST_SH'
|
||||
end
|
||||
|
||||
def windows?
|
||||
! File::ALT_SEPARATOR.nil?
|
||||
end
|
||||
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'date'
|
||||
require 'time'
|
||||
require 'rake/contrib/ftptools'
|
||||
|
||||
class FakeDate
|
||||
def self.today
|
||||
Date.new(2003, 10, 3)
|
||||
end
|
||||
|
||||
def self.now
|
||||
Time.local(2003, 10, 3, 12, 00, 00)
|
||||
end
|
||||
end
|
||||
|
||||
class TestRakeFtpFile < Rake::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
Rake::FtpFile.class_eval {
|
||||
@date_class = FakeDate
|
||||
@time_class = FakeDate
|
||||
}
|
||||
end
|
||||
|
||||
def test_general
|
||||
file = Rake::FtpFile.new(
|
||||
"here",
|
||||
"-rw-r--r-- 1 a279376 develop 121770 Mar 6 14:50 wiki.pl")
|
||||
assert_equal "wiki.pl", file.name
|
||||
assert_equal "here/wiki.pl", file.path
|
||||
assert_equal "a279376", file.owner
|
||||
assert_equal "develop", file.group
|
||||
assert_equal 0644, file.mode
|
||||
assert_equal 121_770, file.size
|
||||
assert_equal Time.mktime(2003, 3, 6, 14, 50, 0, 0), file.time
|
||||
assert ! file.directory?
|
||||
assert ! file.symlink?
|
||||
end
|
||||
|
||||
def test_far_date
|
||||
file = Rake::FtpFile.new(
|
||||
".",
|
||||
"drwxr-xr-x 3 a279376 develop 4096 Nov 26 2001 vss")
|
||||
assert_equal Time.mktime(2001, 11, 26, 0, 0, 0, 0), file.time
|
||||
end
|
||||
|
||||
def test_close_date
|
||||
file = Rake::FtpFile.new(
|
||||
".",
|
||||
"drwxr-xr-x 3 a279376 develop 4096 Nov 26 15:35 vss")
|
||||
assert_equal Time.mktime(2002, 11, 26, 15, 35, 0, 0), file.time
|
||||
end
|
||||
|
||||
def test_directory
|
||||
file = Rake::FtpFile.new(
|
||||
".",
|
||||
"drwxrwxr-x 9 a279376 develop 4096 Mar 13 14:32 working")
|
||||
assert file.directory?
|
||||
assert !file.symlink?
|
||||
end
|
||||
|
||||
def test_symlink
|
||||
file = Rake::FtpFile.new(
|
||||
".",
|
||||
"lrwxrwxrwx 1 a279376 develop 64 Mar 26 2002 " +
|
||||
"xtrac -> /home/a279376/working/ics/development/java/" +
|
||||
"com/fmr/fwp/ics/xtrac")
|
||||
assert_equal 'xtrac', file.name
|
||||
assert file.symlink?
|
||||
assert !file.directory?
|
||||
end
|
||||
end
|
|
@ -1,482 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'fileutils'
|
||||
require 'open3'
|
||||
|
||||
class TestRakeFunctional < Rake::TestCase
|
||||
include RubyRunner
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
if @verbose
|
||||
puts
|
||||
puts
|
||||
puts '-' * 80
|
||||
puts @__name__
|
||||
puts '-' * 80
|
||||
end
|
||||
end
|
||||
|
||||
def test_rake_default
|
||||
rakefile_default
|
||||
|
||||
rake
|
||||
|
||||
assert_match(/^DEFAULT$/, @out)
|
||||
end
|
||||
|
||||
def test_rake_error_on_bad_task
|
||||
rakefile_default
|
||||
|
||||
rake '-t', 'xyz'
|
||||
|
||||
assert_match(/rake aborted/, @err)
|
||||
end
|
||||
|
||||
def test_env_available_at_top_scope
|
||||
rakefile_default
|
||||
|
||||
rake "TESTTOPSCOPE=1"
|
||||
|
||||
assert_match(/^TOPSCOPE$/, @out)
|
||||
end
|
||||
|
||||
def test_env_available_at_task_scope
|
||||
rakefile_default
|
||||
|
||||
rake 'TESTTASKSCOPE=1', 'task_scope'
|
||||
|
||||
assert_match(/^TASKSCOPE$/, @out)
|
||||
end
|
||||
|
||||
def test_multi_desc
|
||||
ENV['RAKE_COLUMNS'] = '80'
|
||||
rakefile_multidesc
|
||||
|
||||
rake "-T"
|
||||
|
||||
assert_match %r{^rake a *# A / A2 *$}, @out
|
||||
assert_match %r{^rake b *# B *$}, @out
|
||||
refute_match %r{^rake c}, @out
|
||||
assert_match %r{^rake d *# x{65}\.\.\.$}, @out
|
||||
end
|
||||
|
||||
def test_long_description
|
||||
rakefile_multidesc
|
||||
|
||||
rake "--describe"
|
||||
|
||||
assert_match %r{^rake a\n *A\n *A2 *$}m, @out
|
||||
assert_match %r{^rake b\n *B *$}m, @out
|
||||
assert_match %r{^rake d\n *x{80}}m, @out
|
||||
refute_match %r{^rake c\n}m, @out
|
||||
end
|
||||
|
||||
def test_proper_namespace_access
|
||||
rakefile_access
|
||||
|
||||
rake
|
||||
|
||||
refute_match %r{^BAD:}, @out
|
||||
end
|
||||
|
||||
def test_rbext
|
||||
rakefile_rbext
|
||||
|
||||
rake "-N"
|
||||
|
||||
assert_match %r{^OK$}, @out
|
||||
end
|
||||
|
||||
def test_system
|
||||
rake_system_dir
|
||||
|
||||
rake '-g', "sys1"
|
||||
|
||||
assert_match %r{^SYS1}, @out
|
||||
end
|
||||
|
||||
def test_system_excludes_rakelib_files_too
|
||||
rake_system_dir
|
||||
|
||||
rake '-g', "sys1", '-T', 'extra'
|
||||
|
||||
refute_match %r{extra:extra}, @out
|
||||
end
|
||||
|
||||
def test_by_default_rakelib_files_are_included
|
||||
rake_system_dir
|
||||
rakefile_extra
|
||||
|
||||
rake '-T', 'extra', '--trace'
|
||||
|
||||
assert_match %r{extra:extra}, @out
|
||||
end
|
||||
|
||||
def test_implicit_system
|
||||
rake_system_dir
|
||||
Dir.chdir @tempdir
|
||||
|
||||
rake "sys1", "--trace"
|
||||
|
||||
assert_match %r{^SYS1}, @out
|
||||
end
|
||||
|
||||
def test_no_system
|
||||
rake_system_dir
|
||||
rakefile_extra
|
||||
|
||||
rake '-G', "sys1"
|
||||
|
||||
assert_match %r{^Don't know how to build task}, @err # emacs wart: '
|
||||
end
|
||||
|
||||
def test_nosearch_with_rakefile_uses_local_rakefile
|
||||
rakefile_default
|
||||
|
||||
rake "--nosearch"
|
||||
|
||||
assert_match %r{^DEFAULT}, @out
|
||||
end
|
||||
|
||||
def test_nosearch_without_rakefile_finds_system
|
||||
rakefile_nosearch
|
||||
rake_system_dir
|
||||
|
||||
rake "--nosearch", "sys1"
|
||||
|
||||
assert_match %r{^SYS1}, @out
|
||||
end
|
||||
|
||||
def test_nosearch_without_rakefile_and_no_system_fails
|
||||
rakefile_nosearch
|
||||
ENV['RAKE_SYSTEM'] = 'not_exist'
|
||||
|
||||
rake "--nosearch"
|
||||
|
||||
assert_match %r{^No Rakefile found}, @err
|
||||
end
|
||||
|
||||
def test_invalid_command_line_options
|
||||
rakefile_default
|
||||
|
||||
rake "--bad-options"
|
||||
|
||||
assert_match %r{invalid +option}i, @err
|
||||
end
|
||||
|
||||
def test_inline_verbose_default_should_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "inline_verbose_default"
|
||||
|
||||
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_inline_verbose_true_should_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "inline_verbose_true"
|
||||
|
||||
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_inline_verbose_false_should_not_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "inline_verbose_false"
|
||||
|
||||
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_block_verbose_false_should_not_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "block_verbose_false"
|
||||
|
||||
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_block_verbose_true_should_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "block_verbose_true"
|
||||
|
||||
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_standalone_verbose_true_should_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "standalone_verbose_true"
|
||||
|
||||
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_standalone_verbose_false_should_not_show_command
|
||||
rakefile_verbose
|
||||
|
||||
rake "standalone_verbose_false"
|
||||
|
||||
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
|
||||
end
|
||||
|
||||
def test_dry_run
|
||||
rakefile_default
|
||||
|
||||
rake "-n", "other"
|
||||
|
||||
assert_match %r{Execute \(dry run\) default}, @err
|
||||
assert_match %r{Execute \(dry run\) other}, @err
|
||||
refute_match %r{DEFAULT}, @out
|
||||
refute_match %r{OTHER}, @out
|
||||
end
|
||||
|
||||
# Test for the trace/dry_run bug found by Brian Chandler
|
||||
def test_dry_run_bug
|
||||
rakefile_dryrun
|
||||
|
||||
rake
|
||||
|
||||
FileUtils.rm_f 'temp_one'
|
||||
|
||||
rake "--dry-run"
|
||||
|
||||
refute_match(/No such file/, @out)
|
||||
end
|
||||
|
||||
# Test for the trace/dry_run bug found by Brian Chandler
|
||||
def test_trace_bug
|
||||
rakefile_dryrun
|
||||
|
||||
rake
|
||||
|
||||
FileUtils.rm_f 'temp_one'
|
||||
|
||||
rake "--trace"
|
||||
|
||||
refute_match(/No such file/, @out)
|
||||
end
|
||||
|
||||
def test_imports
|
||||
rakefile_imports
|
||||
|
||||
rake
|
||||
|
||||
assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
|
||||
"'dynamic_deps' file should exist"
|
||||
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
|
||||
end
|
||||
|
||||
def test_regenerate_imports
|
||||
rakefile_regenerate_imports
|
||||
|
||||
rake
|
||||
|
||||
assert_match(/^INITIAL\s+^REGENERATED$/, @out)
|
||||
end
|
||||
|
||||
def test_rules_chaining_to_file_task
|
||||
rakefile_chains
|
||||
|
||||
rake
|
||||
|
||||
assert File.exist?(File.join(@tempdir, 'play.app')),
|
||||
"'play.app' file should exist"
|
||||
end
|
||||
|
||||
def test_file_creation_task
|
||||
rakefile_file_creation
|
||||
|
||||
rake "prep"
|
||||
rake "run"
|
||||
rake "run"
|
||||
|
||||
assert(@err !~ /^cp src/, "Should not recopy data")
|
||||
end
|
||||
|
||||
def test_dash_f_with_no_arg_foils_rakefile_lookup
|
||||
rakefile_rakelib
|
||||
|
||||
rake '-I', 'rakelib', '-rtest1', '-f'
|
||||
|
||||
assert_match(/^TEST1$/, @out)
|
||||
end
|
||||
|
||||
def test_dot_rake_files_can_be_loaded_with_dash_r
|
||||
rakefile_rakelib
|
||||
|
||||
rake '-I', 'rakelib', '-rtest2', '-f'
|
||||
|
||||
assert_empty @err
|
||||
assert_match(/^TEST2$/, @out)
|
||||
end
|
||||
|
||||
def test_can_invoke_task_in_toplevel_namespace
|
||||
rakefile_namespace
|
||||
|
||||
rake "copy"
|
||||
|
||||
assert_match(/^COPY$/, @out)
|
||||
end
|
||||
|
||||
def test_can_invoke_task_in_nested_namespace
|
||||
rakefile_namespace
|
||||
|
||||
rake "nest:copy"
|
||||
|
||||
assert_match(/^NEST COPY$/, @out)
|
||||
end
|
||||
|
||||
def test_tasks_can_reference_task_in_same_namespace
|
||||
rakefile_namespace
|
||||
|
||||
rake "nest:xx"
|
||||
|
||||
assert_match(/^NEST COPY$/m, @out)
|
||||
end
|
||||
|
||||
def test_tasks_can_reference_task_in_other_namespaces
|
||||
rakefile_namespace
|
||||
|
||||
rake "b:run"
|
||||
|
||||
assert_match(/^IN A\nIN B$/m, @out)
|
||||
end
|
||||
|
||||
def test_anonymous_tasks_can_be_invoked_indirectly
|
||||
rakefile_namespace
|
||||
|
||||
rake "anon"
|
||||
|
||||
assert_match(/^ANON COPY$/m, @out)
|
||||
end
|
||||
|
||||
def test_rake_namespace_refers_to_toplevel
|
||||
rakefile_namespace
|
||||
|
||||
rake "very:nested:run"
|
||||
|
||||
assert_match(/^COPY$/m, @out)
|
||||
end
|
||||
|
||||
def test_file_task_are_not_scoped_by_namespaces
|
||||
rakefile_namespace
|
||||
|
||||
rake "xyz.rb"
|
||||
|
||||
assert_match(/^XYZ1\nXYZ2$/m, @out)
|
||||
end
|
||||
|
||||
def test_file_task_dependencies_scoped_by_namespaces
|
||||
rakefile_namespace
|
||||
|
||||
rake "scopedep.rb"
|
||||
|
||||
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
|
||||
end
|
||||
|
||||
def test_test_task_descriptions
|
||||
rakefile_test_task
|
||||
|
||||
rake "-T"
|
||||
|
||||
assert_match(/custom test task description/, @out)
|
||||
end
|
||||
|
||||
def test_comment_before_task_acts_like_desc
|
||||
rakefile_comments
|
||||
|
||||
rake "-T"
|
||||
|
||||
refute_match(/comment for t1/, @out)
|
||||
end
|
||||
|
||||
def test_comment_separated_from_task_by_blank_line_is_not_picked_up
|
||||
rakefile_comments
|
||||
|
||||
rake "-T"
|
||||
|
||||
refute_match("t2", @out)
|
||||
end
|
||||
|
||||
def test_comment_after_desc_is_ignored
|
||||
rakefile_comments
|
||||
|
||||
rake "-T"
|
||||
|
||||
assert_match("override comment for t3", @out)
|
||||
end
|
||||
|
||||
def test_comment_before_desc_is_ignored
|
||||
rakefile_comments
|
||||
|
||||
rake "-T"
|
||||
|
||||
assert_match("override comment for t4", @out)
|
||||
end
|
||||
|
||||
def test_correct_number_of_tasks_reported
|
||||
rakefile_comments
|
||||
|
||||
rake "-T"
|
||||
|
||||
assert_equal(2, @out.split(/\n/).grep(/t\d/).size)
|
||||
end
|
||||
|
||||
def test_file_list_is_requirable_separately
|
||||
ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size'
|
||||
assert_equal "1\n", @out
|
||||
end
|
||||
|
||||
def can_detect_signals?
|
||||
system RUBY, '-e', 'Process.kill "TERM", $$'
|
||||
status = $?
|
||||
if @verbose
|
||||
puts " SIG status = #{$?.inspect}"
|
||||
puts " SIG status.respond_to?(:signaled?) = " +
|
||||
"#{$?.respond_to?(:signaled?).inspect}"
|
||||
puts " SIG status.signaled? = #{status.signaled?}" if
|
||||
status.respond_to?(:signaled?)
|
||||
end
|
||||
status.respond_to?(:signaled?) && status.signaled?
|
||||
end
|
||||
|
||||
def test_signal_propagation_in_tests
|
||||
if can_detect_signals?
|
||||
rakefile_test_signal
|
||||
rake
|
||||
assert_match(/ATEST/, @out)
|
||||
refute_match(/BTEST/, @out)
|
||||
else
|
||||
skip "Signal detect seems broken on this system"
|
||||
end
|
||||
end
|
||||
|
||||
def test_failing_test_sets_exit_status
|
||||
skip if uncertain_exit_status?
|
||||
rakefile_failing_test_task
|
||||
rake
|
||||
assert @exit.exitstatus > 0, "should be non-zero"
|
||||
end
|
||||
|
||||
def test_stand_alone_filelist
|
||||
rakefile_stand_alone_filelist
|
||||
|
||||
run_ruby @ruby_options + ["stand_alone_filelist.rb"]
|
||||
|
||||
assert_match(/^stand_alone_filelist\.rb$/, @out)
|
||||
assert_equal 0, @exit.exitstatus unless uncertain_exit_status?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# We are unable to accurately verify that Rake returns a proper
|
||||
# error exit status using popen3 in Ruby 1.8.7 and JRuby. This
|
||||
# predicate function can be used to skip tests or assertions as
|
||||
# needed.
|
||||
def uncertain_exit_status?
|
||||
RUBY_VERSION < "1.9" || defined?(JRUBY_VERSION)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeInvocationChain < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
@empty = InvocationChain.empty
|
||||
|
||||
@first_member = "A"
|
||||
@second_member = "B"
|
||||
@one = @empty.append(@first_member)
|
||||
@two = @one.append(@second_member)
|
||||
end
|
||||
|
||||
def test_conj_on_invocation_chains
|
||||
list = InvocationChain.empty.conj("B").conj("A")
|
||||
assert_equal InvocationChain.make("A", "B"), list
|
||||
assert_equal InvocationChain, list.class
|
||||
end
|
||||
|
||||
def test_make_on_invocation_chains
|
||||
assert_equal @empty, InvocationChain.make()
|
||||
assert_equal @one, InvocationChain.make(@first_member)
|
||||
assert_equal @two, InvocationChain.make(@second_member, @first_member)
|
||||
end
|
||||
|
||||
def test_append_with_one_argument
|
||||
chain = @empty.append("A")
|
||||
|
||||
assert_equal 'TOP => A', chain.to_s # HACK
|
||||
end
|
||||
|
||||
def test_append_one_circular
|
||||
ex = assert_raises RuntimeError do
|
||||
@one.append(@first_member)
|
||||
end
|
||||
assert_match(/circular +dependency/i, ex.message)
|
||||
assert_match(/A.*=>.*A/, ex.message)
|
||||
end
|
||||
|
||||
def test_append_two_circular
|
||||
ex = assert_raises RuntimeError do
|
||||
@two.append(@first_member)
|
||||
end
|
||||
assert_match(/A.*=>.*B.*=>.*A/, ex.message)
|
||||
end
|
||||
|
||||
def test_member_eh_one
|
||||
assert @one.member?(@first_member)
|
||||
end
|
||||
|
||||
def test_member_eh_two
|
||||
assert @two.member?(@first_member)
|
||||
assert @two.member?(@second_member)
|
||||
end
|
||||
|
||||
def test_to_s_empty
|
||||
assert_equal "TOP", @empty.to_s
|
||||
assert_equal "TOP => A", @one.to_s
|
||||
end
|
||||
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeLateTime < Rake::TestCase
|
||||
def test_late_time_comparisons
|
||||
late = Rake::LATE
|
||||
assert_equal late, late
|
||||
assert late >= Time.now
|
||||
assert late > Time.now
|
||||
assert late != Time.now
|
||||
assert Time.now < late
|
||||
assert Time.now <= late
|
||||
assert Time.now != late
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal '<LATE TIME>', Rake::LATE.to_s
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestLinkedList < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
def test_empty_list
|
||||
empty = LinkedList::EMPTY
|
||||
assert empty.empty?, "should be empty"
|
||||
end
|
||||
|
||||
def test_list_with_one_item
|
||||
list = LinkedList.make(:one)
|
||||
assert ! list.empty?, "should not be empty"
|
||||
assert_equal :one, list.head
|
||||
assert_equal LinkedList::EMPTY, list.tail
|
||||
end
|
||||
|
||||
def test_make_with_no_arguments
|
||||
empty = LinkedList.make()
|
||||
assert_equal LinkedList::EMPTY, empty
|
||||
end
|
||||
|
||||
def test_make_with_one_argument
|
||||
list = LinkedList.make(:one)
|
||||
assert ! list.empty?
|
||||
assert_equal :one, list.head
|
||||
assert_equal LinkedList::EMPTY, list.tail
|
||||
end
|
||||
|
||||
def test_make_with_two_arguments
|
||||
list = LinkedList.make(:one, :two)
|
||||
assert ! list.empty?
|
||||
assert_equal :one, list.head
|
||||
assert_equal :two, list.tail.head
|
||||
assert_equal LinkedList::EMPTY, list.tail.tail
|
||||
end
|
||||
|
||||
def test_list_with_several_items
|
||||
list = LinkedList.make(:one, :two, :three)
|
||||
|
||||
assert ! list.empty?, "should not be empty"
|
||||
assert_equal :one, list.head
|
||||
assert_equal :two, list.tail.head
|
||||
assert_equal :three, list.tail.tail.head
|
||||
assert_equal LinkedList::EMPTY, list.tail.tail.tail
|
||||
end
|
||||
|
||||
def test_lists_are_structurally_equivalent
|
||||
list = LinkedList.make(1, 2, 3)
|
||||
same = LinkedList.make(1, 2, 3)
|
||||
diff = LinkedList.make(1, 2, 4)
|
||||
short = LinkedList.make(1, 2)
|
||||
|
||||
assert_equal list, same
|
||||
refute_equal list, diff
|
||||
refute_equal list, short
|
||||
refute_equal short, list
|
||||
end
|
||||
|
||||
def test_conversion_to_string
|
||||
list = LinkedList.make(:one, :two, :three)
|
||||
assert_equal "LL(one, two, three)", list.to_s
|
||||
assert_equal "LL()", LinkedList.make().to_s
|
||||
end
|
||||
|
||||
def test_conversion_with_inspect
|
||||
list = LinkedList.make(:one, :two, :three)
|
||||
assert_equal "LL(:one, :two, :three)", list.inspect
|
||||
assert_equal "LL()", LinkedList.make().inspect
|
||||
end
|
||||
|
||||
def test_lists_are_enumerable
|
||||
list = LinkedList.make(1, 2, 3)
|
||||
new_list = list.map { |item| item + 10 }
|
||||
expected = [11, 12, 13]
|
||||
assert_equal expected, new_list
|
||||
end
|
||||
|
||||
def test_conjunction
|
||||
list = LinkedList.make.conj("C").conj("B").conj("A")
|
||||
assert_equal LinkedList.make("A", "B", "C"), list
|
||||
end
|
||||
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'rake/loaders/makefile'
|
||||
|
||||
class TestRakeMakefileLoader < Rake::TestCase
|
||||
include Rake
|
||||
|
||||
def test_parse
|
||||
Dir.chdir @tempdir
|
||||
|
||||
open 'sample.mf', 'w' do |io|
|
||||
io << <<-'SAMPLE_MF'
|
||||
# Comments
|
||||
a: a1 a2 a3 a4
|
||||
b: b1 b2 b3 \
|
||||
b4 b5 b6\
|
||||
# Mid: Comment
|
||||
b7
|
||||
|
||||
a : a5 a6 a7
|
||||
c: c1
|
||||
d: d1 d2 \
|
||||
|
||||
e f : e1 f1
|
||||
|
||||
g\ 0: g1 g\ 2 g\ 3 g4
|
||||
SAMPLE_MF
|
||||
end
|
||||
|
||||
Task.clear
|
||||
loader = Rake::MakefileLoader.new
|
||||
loader.load 'sample.mf'
|
||||
%w(a b c d).each do |t|
|
||||
assert Task.task_defined?(t), "#{t} should be a defined task"
|
||||
end
|
||||
assert_equal %w(a1 a2 a3 a4 a5 a6 a7).sort, Task['a'].prerequisites.sort
|
||||
assert_equal %w(b1 b2 b3 b4 b5 b6 b7).sort, Task['b'].prerequisites.sort
|
||||
assert_equal %w(c1).sort, Task['c'].prerequisites.sort
|
||||
assert_equal %w(d1 d2).sort, Task['d'].prerequisites.sort
|
||||
assert_equal %w(e1 f1).sort, Task['e'].prerequisites.sort
|
||||
assert_equal %w(e1 f1).sort, Task['f'].prerequisites.sort
|
||||
assert_equal(
|
||||
["g1", "g 2", "g 3", "g4"].sort,
|
||||
Task['g 0'].prerequisites.sort)
|
||||
assert_equal 7, Task.tasks.size
|
||||
end
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'thread'
|
||||
|
||||
class TestRakeMultiTask < Rake::TestCase
|
||||
include Rake
|
||||
include Rake::DSL
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
Task.clear
|
||||
@runs = Array.new
|
||||
@mutex = Mutex.new
|
||||
end
|
||||
|
||||
def teardown
|
||||
Rake.application.thread_pool.join
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def add_run(obj)
|
||||
@mutex.synchronize do
|
||||
@runs << obj
|
||||
end
|
||||
end
|
||||
|
||||
def test_running_multitasks
|
||||
task :a do 3.times do |i| add_run("A#{i}"); sleep 0.01; end end
|
||||
task :b do 3.times do |i| add_run("B#{i}"); sleep 0.01; end end
|
||||
multitask :both => [:a, :b]
|
||||
Task[:both].invoke
|
||||
assert_equal 6, @runs.size
|
||||
assert @runs.index("A0") < @runs.index("A1")
|
||||
assert @runs.index("A1") < @runs.index("A2")
|
||||
assert @runs.index("B0") < @runs.index("B1")
|
||||
assert @runs.index("B1") < @runs.index("B2")
|
||||
end
|
||||
|
||||
def test_all_multitasks_wait_on_slow_prerequisites
|
||||
task :slow do 3.times do |i| add_run("S#{i}"); sleep 0.05 end end
|
||||
task :a => [:slow] do 3.times do |i| add_run("A#{i}"); sleep 0.01 end end
|
||||
task :b => [:slow] do 3.times do |i| add_run("B#{i}"); sleep 0.01 end end
|
||||
multitask :both => [:a, :b]
|
||||
Task[:both].invoke
|
||||
assert_equal 9, @runs.size
|
||||
assert @runs.index("S0") < @runs.index("S1")
|
||||
assert @runs.index("S1") < @runs.index("S2")
|
||||
assert @runs.index("S2") < @runs.index("A0")
|
||||
assert @runs.index("S2") < @runs.index("B0")
|
||||
assert @runs.index("A0") < @runs.index("A1")
|
||||
assert @runs.index("A1") < @runs.index("A2")
|
||||
assert @runs.index("B0") < @runs.index("B1")
|
||||
assert @runs.index("B1") < @runs.index("B2")
|
||||
end
|
||||
|
||||
def test_multitasks_with_parameters
|
||||
task :a, [:arg] do |t, args| add_run(args[:arg]) end
|
||||
multitask :b, [:arg] => [:a] do |t, args| add_run(args[:arg] + 'mt') end
|
||||
Task[:b].invoke "b"
|
||||
assert @runs[0] == "b"
|
||||
assert @runs[1] == "bmt"
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeNameSpace < Rake::TestCase
|
||||
|
||||
class TM
|
||||
include Rake::TaskManager
|
||||
end
|
||||
|
||||
def test_namespace_creation
|
||||
mgr = TM.new
|
||||
ns = Rake::NameSpace.new(mgr, [])
|
||||
refute_nil ns
|
||||
end
|
||||
|
||||
def test_namespace_lookup
|
||||
mgr = TM.new
|
||||
ns = mgr.in_namespace("n") do
|
||||
mgr.define_task(Rake::Task, "t")
|
||||
end
|
||||
|
||||
refute_nil ns["t"]
|
||||
assert_equal mgr["n:t"], ns["t"]
|
||||
end
|
||||
|
||||
def test_namespace_reports_tasks_it_owns
|
||||
mgr = TM.new
|
||||
nns = nil
|
||||
ns = mgr.in_namespace("n") do
|
||||
mgr.define_task(Rake::Task, :x)
|
||||
mgr.define_task(Rake::Task, :y)
|
||||
nns = mgr.in_namespace("nn") do
|
||||
mgr.define_task(Rake::Task, :z)
|
||||
end
|
||||
end
|
||||
mgr.in_namespace("m") do
|
||||
mgr.define_task(Rake::Task, :x)
|
||||
end
|
||||
|
||||
assert_equal ["n:nn:z", "n:x", "n:y"],
|
||||
ns.tasks.map { |tsk| tsk.name }
|
||||
assert_equal ["n:nn:z"], nns.tasks.map { |t| t.name }
|
||||
end
|
||||
|
||||
def test_scope
|
||||
mgr = TM.new
|
||||
|
||||
scope = Rake::LinkedList.new 'b'
|
||||
scope = scope.conj 'a'
|
||||
|
||||
ns = Rake::NameSpace.new mgr, scope
|
||||
|
||||
assert_equal scope, ns.scope
|
||||
|
||||
refute_same scope, ns.scope
|
||||
end
|
||||
|
||||
end
|
|
@ -1,79 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'rake/packagetask'
|
||||
|
||||
class TestRakePackageTask < Rake::TestCase
|
||||
|
||||
def test_initialize
|
||||
touch 'install.rb'
|
||||
touch 'a.c'
|
||||
touch 'b.c'
|
||||
mkdir 'CVS'
|
||||
touch 'a.rb~'
|
||||
|
||||
pkg = Rake::PackageTask.new("pkgr", "1.2.3") { |p|
|
||||
p.package_files << "install.rb"
|
||||
p.package_files.include '*.c'
|
||||
p.package_files.exclude(/\bCVS\b/)
|
||||
p.package_files.exclude(/~$/)
|
||||
p.package_dir = 'pkg'
|
||||
p.need_tar = true
|
||||
p.need_tar_gz = true
|
||||
p.need_tar_bz2 = true
|
||||
p.need_zip = true
|
||||
}
|
||||
|
||||
assert_equal "pkg", pkg.package_dir
|
||||
|
||||
assert_includes pkg.package_files, 'a.c'
|
||||
|
||||
assert_equal 'pkgr', pkg.name
|
||||
assert_equal '1.2.3', pkg.version
|
||||
assert Rake::Task[:package]
|
||||
assert Rake::Task['pkg/pkgr-1.2.3.tgz']
|
||||
assert Rake::Task['pkg/pkgr-1.2.3.tar.gz']
|
||||
assert Rake::Task['pkg/pkgr-1.2.3.tar.bz2']
|
||||
assert Rake::Task['pkg/pkgr-1.2.3.zip']
|
||||
assert Rake::Task['pkg/pkgr-1.2.3']
|
||||
assert Rake::Task[:clobber_package]
|
||||
assert Rake::Task[:repackage]
|
||||
end
|
||||
|
||||
def test_initialize_no_version
|
||||
e = assert_raises RuntimeError do
|
||||
Rake::PackageTask.new 'pkgr'
|
||||
end
|
||||
|
||||
assert_equal 'Version required (or :noversion)', e.message
|
||||
end
|
||||
|
||||
def test_initialize_noversion
|
||||
pkg = Rake::PackageTask.new 'pkgr', :noversion
|
||||
|
||||
assert_equal 'pkg', pkg.package_dir
|
||||
assert_equal 'pkgr', pkg.name
|
||||
assert_equal nil, pkg.version
|
||||
end
|
||||
|
||||
def test_clone
|
||||
pkg = Rake::PackageTask.new("x", :noversion)
|
||||
p2 = pkg.clone
|
||||
pkg.package_files << "y"
|
||||
p2.package_files << "x"
|
||||
assert_equal ["y"], pkg.package_files
|
||||
assert_equal ["x"], p2.package_files
|
||||
end
|
||||
|
||||
def test_package_name
|
||||
pkg = Rake::PackageTask.new 'a', '1'
|
||||
|
||||
assert_equal 'a-1', pkg.package_name
|
||||
end
|
||||
|
||||
def test_package_name_noversion
|
||||
pkg = Rake::PackageTask.new 'a', :noversion
|
||||
|
||||
assert_equal 'a', pkg.package_name
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakePathMap < Rake::TestCase
|
||||
|
||||
def test_returns_self_with_no_args
|
||||
assert_equal "abc.rb", "abc.rb".pathmap
|
||||
end
|
||||
|
||||
def test_s_returns_file_separator
|
||||
sep = File::ALT_SEPARATOR || File::SEPARATOR
|
||||
assert_equal sep, "abc.rb".pathmap("%s")
|
||||
assert_equal sep, "".pathmap("%s")
|
||||
assert_equal "a#{sep}b", "a/b".pathmap("%d%s%f")
|
||||
end
|
||||
|
||||
def test_f_returns_basename
|
||||
assert_equal "abc.rb", "abc.rb".pathmap("%f")
|
||||
assert_equal "abc.rb", "this/is/a/dir/abc.rb".pathmap("%f")
|
||||
assert_equal "abc.rb", "/this/is/a/dir/abc.rb".pathmap("%f")
|
||||
end
|
||||
|
||||
def test_n_returns_basename_without_extension
|
||||
assert_equal "abc", "abc.rb".pathmap("%n")
|
||||
assert_equal "abc", "abc".pathmap("%n")
|
||||
assert_equal "abc", "this/is/a/dir/abc.rb".pathmap("%n")
|
||||
assert_equal "abc", "/this/is/a/dir/abc.rb".pathmap("%n")
|
||||
assert_equal "abc", "/this/is/a/dir/abc".pathmap("%n")
|
||||
end
|
||||
|
||||
def test_d_returns_dirname
|
||||
assert_equal ".", "abc.rb".pathmap("%d")
|
||||
assert_equal "/", "/abc".pathmap("%d")
|
||||
assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%d")
|
||||
assert_equal "/this/is/a/dir", "/this/is/a/dir/abc.rb".pathmap("%d")
|
||||
end
|
||||
|
||||
def test_9d_returns_partial_dirname
|
||||
assert_equal "this/is", "this/is/a/dir/abc.rb".pathmap("%2d")
|
||||
assert_equal "this", "this/is/a/dir/abc.rb".pathmap("%1d")
|
||||
assert_equal ".", "this/is/a/dir/abc.rb".pathmap("%0d")
|
||||
assert_equal "dir", "this/is/a/dir/abc.rb".pathmap("%-1d")
|
||||
assert_equal "a/dir", "this/is/a/dir/abc.rb".pathmap("%-2d")
|
||||
assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%100d")
|
||||
assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%-100d")
|
||||
end
|
||||
|
||||
def test_x_returns_extension
|
||||
assert_equal "", "abc".pathmap("%x")
|
||||
assert_equal ".rb", "abc.rb".pathmap("%x")
|
||||
assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
|
||||
assert_equal "", ".depends".pathmap("%x")
|
||||
assert_equal "", "dir/.depends".pathmap("%x")
|
||||
end
|
||||
|
||||
def test_x_returns_everything_but_extension
|
||||
assert_equal "abc", "abc".pathmap("%X")
|
||||
assert_equal "abc", "abc.rb".pathmap("%X")
|
||||
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
|
||||
assert_equal "ab.xyz", "ab.xyz.rb".pathmap("%X")
|
||||
assert_equal "a.xyz", "a.xyz.rb".pathmap("%X")
|
||||
assert_equal "abc", "abc.rb".pathmap("%X")
|
||||
assert_equal "ab", "ab.rb".pathmap("%X")
|
||||
assert_equal "a", "a.rb".pathmap("%X")
|
||||
assert_equal ".depends", ".depends".pathmap("%X")
|
||||
assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
|
||||
assert_equal "/.depends", "/.depends".pathmap("%X")
|
||||
end
|
||||
|
||||
def test_p_returns_entire_pathname
|
||||
assert_equal "abc.rb", "abc.rb".pathmap("%p")
|
||||
assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
|
||||
assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
|
||||
end
|
||||
|
||||
def test_dash_returns_empty_string
|
||||
assert_equal "", "abc.rb".pathmap("%-")
|
||||
assert_equal "abc.rb", "abc.rb".pathmap("%X%-%x")
|
||||
end
|
||||
|
||||
def test_percent_percent_returns_percent
|
||||
assert_equal "a%b", "".pathmap("a%%b")
|
||||
end
|
||||
|
||||
def test_undefined_percent_causes_error
|
||||
assert_raises(ArgumentError) {
|
||||
"dir/abc.rb".pathmap("%z")
|
||||
}
|
||||
end
|
||||
|
||||
def test_pattern_returns_substitutions
|
||||
assert_equal "bin/org/osb",
|
||||
"src/org/osb/Xyz.java".pathmap("%{src,bin}d")
|
||||
end
|
||||
|
||||
def test_pattern_can_use_backreferences
|
||||
assert_equal "dir/hi/is", "dir/this/is".pathmap("%{t(hi)s,\\1}p")
|
||||
end
|
||||
|
||||
def test_pattern_with_star_replacement_string_uses_block
|
||||
assert_equal "src/ORG/osb",
|
||||
"src/org/osb/Xyz.java".pathmap("%{/org,*}d") { |d| d.upcase }
|
||||
assert_equal "Xyz.java",
|
||||
"src/org/osb/Xyz.java".pathmap("%{.*,*}f") { |f| f.capitalize }
|
||||
end
|
||||
|
||||
def test_pattern_with_no_replacement_nor_block_substitutes_empty_string
|
||||
assert_equal "bc.rb", "abc.rb".pathmap("%{a}f")
|
||||
end
|
||||
|
||||
def test_pattern_works_with_certain_valid_operators
|
||||
assert_equal "dir/xbc.rb", "dir/abc.rb".pathmap("%{a,x}p")
|
||||
assert_equal "d1r", "dir/abc.rb".pathmap("%{i,1}d")
|
||||
assert_equal "xbc.rb", "dir/abc.rb".pathmap("%{a,x}f")
|
||||
assert_equal ".Rb", "dir/abc.rb".pathmap("%{r,R}x")
|
||||
assert_equal "xbc", "dir/abc.rb".pathmap("%{a,x}n")
|
||||
end
|
||||
|
||||
def test_multiple_patterns
|
||||
assert_equal "this/is/b/directory/abc.rb",
|
||||
"this/is/a/dir/abc.rb".pathmap("%{a,b;dir,\\0ectory}p")
|
||||
end
|
||||
|
||||
def test_partial_directory_selection_works_with_patterns
|
||||
assert_equal "this/is/a/long",
|
||||
"this/is/a/really/long/path/ok.rb".pathmap("%{/really/,/}5d")
|
||||
end
|
||||
|
||||
def test_pattern_with_invalid_operator
|
||||
ex = assert_raises(ArgumentError) do
|
||||
"abc.xyz".pathmap("%{src,bin}z")
|
||||
end
|
||||
assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
|
||||
end
|
||||
|
||||
def test_works_with_windows_separators
|
||||
if File::ALT_SEPARATOR
|
||||
assert_equal "abc", 'dir\abc.rb'.pathmap("%n")
|
||||
assert_equal 'this\is\a\dir',
|
||||
'this\is\a\dir\abc.rb'.pathmap("%d")
|
||||
end
|
||||
end
|
||||
|
||||
def test_complex_patterns
|
||||
sep = "".pathmap("%s")
|
||||
assert_equal(
|
||||
"dir/abc.rb",
|
||||
"dir/abc.rb".pathmap("%d/%n%x"))
|
||||
assert_equal(
|
||||
"./abc.rb",
|
||||
"abc.rb".pathmap("%d/%n%x"))
|
||||
assert_equal(
|
||||
"Your file extension is '.rb'",
|
||||
"dir/abc.rb".pathmap("Your file extension is '%x'"))
|
||||
assert_equal(
|
||||
"bin/org/onestepback/proj/A.class",
|
||||
"src/org/onestepback/proj/A.java".pathmap("%{src,bin}d/%n.class"))
|
||||
assert_equal(
|
||||
"src_work/bin/org/onestepback/proj/A.class",
|
||||
"src_work/src/org/onestepback/proj/A.java".
|
||||
pathmap('%{\bsrc\b,bin}X.class'))
|
||||
assert_equal(
|
||||
".depends.bak",
|
||||
".depends".pathmap("%X.bak"))
|
||||
assert_equal(
|
||||
"d#{sep}a/b/c#{sep}file.txt",
|
||||
"a/b/c/d/file.txt".pathmap("%-1d%s%3d%s%f"))
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakePathMapExplode < Rake::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
String.class_eval { public :pathmap_explode }
|
||||
end
|
||||
|
||||
def teardown
|
||||
String.class_eval { protected :pathmap_explode }
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def test_explode
|
||||
assert_equal ['a'], 'a'.pathmap_explode
|
||||
assert_equal ['a', 'b'], 'a/b'.pathmap_explode
|
||||
assert_equal ['a', 'b', 'c'], 'a/b/c'.pathmap_explode
|
||||
assert_equal ['/', 'a'], '/a'.pathmap_explode
|
||||
assert_equal ['/', 'a', 'b'], '/a/b'.pathmap_explode
|
||||
assert_equal ['/', 'a', 'b', 'c'], '/a/b/c'.pathmap_explode
|
||||
|
||||
if File::ALT_SEPARATOR
|
||||
assert_equal ['c:.', 'a'], 'c:a'.pathmap_explode
|
||||
assert_equal ['c:.', 'a', 'b'], 'c:a/b'.pathmap_explode
|
||||
assert_equal ['c:.', 'a', 'b', 'c'], 'c:a/b/c'.pathmap_explode
|
||||
assert_equal ['c:/', 'a'], 'c:/a'.pathmap_explode
|
||||
assert_equal ['c:/', 'a', 'b'], 'c:/a/b'.pathmap_explode
|
||||
assert_equal ['c:/', 'a', 'b', 'c'], 'c:/a/b/c'.pathmap_explode
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakePathMapPartial < Rake::TestCase
|
||||
def test_pathmap_partial
|
||||
@path = "1/2/file"
|
||||
def @path.call(n)
|
||||
pathmap_partial(n)
|
||||
end
|
||||
assert_equal("1", @path.call(1))
|
||||
assert_equal("1/2", @path.call(2))
|
||||
assert_equal("1/2", @path.call(3))
|
||||
assert_equal(".", @path.call(0))
|
||||
assert_equal("2", @path.call(-1))
|
||||
assert_equal("1/2", @path.call(-2))
|
||||
assert_equal("1/2", @path.call(-3))
|
||||
end
|
||||
end
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'rake/ext/pathname'
|
||||
|
||||
class TestRakePathnameExtensions < Rake::TestCase
|
||||
def test_ext_works_on_pathnames
|
||||
pathname = Pathname.new("abc.foo")
|
||||
assert_equal Pathname.new("abc.bar"), pathname.ext("bar")
|
||||
end
|
||||
|
||||
def test_path_map_works_on_pathnames
|
||||
pathname = Pathname.new("this/is/a/dir/abc.rb")
|
||||
assert_equal Pathname.new("abc.rb"), pathname.pathmap("%f")
|
||||
assert_equal Pathname.new("this/is/a/dir"), pathname.pathmap("%d")
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakePseudoStatus < Rake::TestCase
|
||||
def test_with_zero_exit_status
|
||||
s = Rake::PseudoStatus.new
|
||||
assert_equal 0, s.exitstatus
|
||||
assert_equal 0, s.to_i
|
||||
assert_equal 0, s >> 8
|
||||
refute s.stopped?
|
||||
assert s.exited?
|
||||
end
|
||||
|
||||
def test_with_99_exit_status
|
||||
s = Rake::PseudoStatus.new(99)
|
||||
assert_equal 99, s.exitstatus
|
||||
assert_equal 25344, s.to_i
|
||||
assert_equal 99, s >> 8
|
||||
refute s.stopped?
|
||||
assert s.exited?
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestRakeRakeTestLoader < Rake::TestCase
|
||||
|
||||
def test_pattern
|
||||
orig_loaded_features = $:.dup
|
||||
FileUtils.touch 'foo.rb'
|
||||
FileUtils.touch 'test_a.rb'
|
||||
FileUtils.touch 'test_b.rb'
|
||||
|
||||
ARGV.replace %w[foo.rb test_*.rb -v]
|
||||
|
||||
load File.join(@rake_lib, 'rake/rake_test_loader.rb')
|
||||
|
||||
assert_equal %w[-v], ARGV
|
||||
ensure
|
||||
$:.replace orig_loaded_features
|
||||
end
|
||||
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require File.expand_path('../helper', __FILE__)
|
||||
require 'open3'
|
||||
|
||||
class TestRakeReduceCompat < Rake::TestCase
|
||||
include RubyRunner
|
||||
|
||||
def invoke_normal(task_name)
|
||||
rake task_name.to_s
|
||||
@out
|
||||
end
|
||||
|
||||
def test_no_deprecated_dsl
|
||||
rakefile %q{
|
||||
task :check_task do
|
||||
Module.new { p defined?(task) }
|
||||
end
|
||||
|
||||
task :check_file do
|
||||
Module.new { p defined?(file) }
|
||||
end
|
||||
}
|
||||
|
||||
assert_equal "nil", invoke_normal(:check_task).chomp
|
||||
assert_equal "nil", invoke_normal(:check_file).chomp
|
||||
end
|
||||
end
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче