Skip to content

Commit

Permalink
fixing problems with system rakefile changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Aug 25, 2008
1 parent f192729 commit dea6228
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
26 changes: 17 additions & 9 deletions lib/rake.rb
Expand Up @@ -2267,7 +2267,7 @@ def rake_require(file_name, paths=$LOAD_PATH, loaded=$")
def raw_load_rakefile # :nodoc:
here = Dir.pwd
if (options.load_system || ! have_curdir_rakefile) && ! options.ignore_system && have_system_rakefiles
Dir["#{rake_home_path}/*.rake"].each do |name|
Dir["#{system_dir}/*.rake"].each do |name|
add_import name
end
else
Expand All @@ -2281,36 +2281,44 @@ def raw_load_rakefile # :nodoc:
end
puts "(in #{Dir.pwd})" unless options.silent
$rakefile = @rakefile
puts "DBG: @rakefile=#{@rakefile.inspect}"
load File.expand_path(@rakefile) if @rakefile != ''
load File.expand_path(@rakefile) if @rakefile && @rakefile != ''
options.rakelib.each do |rlib|
Dir["#{rlib}/*.rake"].each do |name| add_import name end
end
load_imports
end

def have_system_rakefiles
Dir[File.join(rake_home_path, '*.rake')].size > 0
Dir[File.join(system_dir, '*.rake')].size > 0
end

# The platform-aware home_path
def rake_home_path
# The directory path containing the system wide rakefiles.
def system_dir
if ENV['RAKE_SYSTEM']
ENV['RAKE_SYSTEM']
elsif windows?
win32_home_path
win32_system_dir
else
File.join(File.expand_path('~'), '.rake')
standard_system_dir
end
end

def win32_rake_home_path #:nodoc:
# 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.
Expand Down
2 changes: 0 additions & 2 deletions lib/rake/loaders/makefile.rb
Expand Up @@ -25,8 +25,6 @@ def process_line(line)
return if args.nil?
dependents = args.split
file_tasks.strip.split.each do |file_task|
puts "DBG: file_task=#{file_task.inspect}"
puts "DBG: dependents=#{dependents.inspect}"
file file_task => dependents
end
end
Expand Down
1 change: 0 additions & 1 deletion test/data/imports/dynamic_deps

This file was deleted.

1 change: 0 additions & 1 deletion test/data/imports/static_deps

This file was deleted.

74 changes: 46 additions & 28 deletions test/test_application.rb
Expand Up @@ -150,37 +150,31 @@ def test_load_rakefile_from_subdir
end

def test_load_rakefile_not_found
original_dir = Dir.pwd
Dir.chdir("/")
@app.instance_eval do
handle_options
options.silent = true
options.ignore_system = true
end
ex = assert_raise(RuntimeError) do
@app.instance_eval do raw_load_rakefile end
in_environment("PWD" => "/") do
@app.instance_eval do
handle_options
options.silent = true
options.ignore_system = true
end
ex = assert_raise(RuntimeError) do
@app.instance_eval do raw_load_rakefile end
end
assert_match(/no rakefile found/i, ex.message)
end
assert_match(/no rakefile found/i, ex.message)
ensure
Dir.chdir(original_dir)
end

def test_load_from_system_rakefile
original_dir = Dir.pwd
flexmock(@app, :home_path=>"test/data/unittest/subdir")
@app = Rake::Application.new
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
load_rakefile
in_environment('RAKE_SYSTEM' => 'test') do
@app.options.rakelib = []
@app.instance_eval do
handle_options
options.silent = true
options.load_system = true
load_rakefile
end
assert_equal "test", @app.system_dir
assert_nil @app.rakefile
end
assert_equal "test", @app.home_path
assert_equal "rakefile", @app.rakefile.downcase
assert_match(%r(unittest$), Dir.pwd)
ensure
Dir.chdir(original_dir)
end

def test_not_caring_about_finding_rakefile
Expand Down Expand Up @@ -288,6 +282,29 @@ def test_run_with_bad_options
ARGV.clear
end

private

def set_env(settings)
result = {}
settings.each do |k, v|
result[k] = ENV[k]
if k == 'PWD'
Dir.chdir(v)
else
ENV[k] = v
end
end
result
end

def in_environment(settings)
original_dir = Dir.pwd
original_settings = set_env(settings)
yield
ensure
set_env(original_settings)
end

end


Expand All @@ -299,6 +316,7 @@ def setup
clear_argv
RakeFileUtils.verbose_flag = false
RakeFileUtils.nowrite_flag = false
TESTING_REQUIRE.clear
end

def teardown
Expand Down Expand Up @@ -346,13 +364,13 @@ def test_trace_option
end

def test_system_option
flags('--system', '-m') do |opts|
flags('--system', '-G') do |opts|
assert opts.load_system
end
end

def test_no_system_option
flags('--no-system', '-M') do |opts|
flags('--no-system', '-g') do |opts|
assert opts.ignore_system
end
end
Expand Down

0 comments on commit dea6228

Please sign in to comment.