Skip to content

Commit

Permalink
partial implementation of system rakefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Aug 30, 2008
1 parent 4b4bce1 commit 2da66fd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
46 changes: 38 additions & 8 deletions lib/rake.rb
Expand Up @@ -2213,9 +2213,6 @@ def handle_options

options.rakelib = ['rakelib']

# opts = GetoptLong.new(*command_line_options)
# opts.each { |opt, value| do_option(opt, value) }

parsed_argv = nil
opts = OptionParser.new do |opts|
opts.banner = "rake [-f rakefile] {options} targets..."
Expand Down Expand Up @@ -2277,17 +2274,50 @@ def find_rakefile_location

def raw_load_rakefile # :nodoc:
rakefile, location = find_rakefile_location
@rakefile = rakefile
Dir.chdir(location)
puts "(in #{Dir.pwd})" unless options.silent
$rakefile = @rakefile
load File.expand_path(@rakefile) if @rakefile != ''
if (! options.ignore_system) && (options.load_system || rakefile.nil?)
puts "(in #{Dir.pwd})" unless options.silent
puts "NO SYSTEM HERE"
else
@rakefile = rakefile
Dir.chdir(location)
puts "(in #{Dir.pwd})" unless options.silent
$rakefile = @rakefile
load File.expand_path(@rakefile) if @rakefile && @rakefile != ''
end
options.rakelib.each do |rlib|
Dir["#{rlib}/*.rake"].each do |name| add_import name end
end
load_imports
end

# The directory path containing the system wide rakefiles.
def system_dir
if ENV['RAKE_SYSTEM']
ENV['RAKE_SYSTEM']
elsif windows?
win32_system_dir
else
standard_system_dir
end
end

# The standard directory containing system wide rake files.
def standard_system_dir #:nodoc:
File.join(File.expand_path('~'), '.rake')
end
private :standard_system_dir

# The standard directory containing system wide rake files on Win
# 32 systems.
def win32_system_dir #:nodoc:
unless File.exists?(win32home = File.join(ENV['APPDATA'], 'Rake'))
raise Win32HomeError, "# Unable to determine home path environment variable."
else
win32home
end
end
private :win32_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.
Expand Down
3 changes: 3 additions & 0 deletions test/data/sys/sys1.rake
@@ -0,0 +1,3 @@
task "sys1" do
puts "SYS1"
end
14 changes: 14 additions & 0 deletions test/test_application.rb
Expand Up @@ -153,6 +153,20 @@ def test_load_rakefile_not_found
end
end

def test_load_from_system_rakefile
in_environment('RAKE_SYSTEM' => 'test/data/sys') do
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
load_rakefile
end
assert_equal "test/data/sys", @app.system_dir
assert_nil @app.rakefile
end
end

def test_loading_imports
mock = flexmock("loader")
mock.should_receive(:load).with("x.dummy").once
Expand Down

0 comments on commit 2da66fd

Please sign in to comment.