Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new --reduce-compat option removes Module#const_missing and Deprecate…

…dObjectDSL
  • Loading branch information...
commit c150beb92a30ee1dd550bc26fdf1f335837473b0 1 parent e16aae7
@quix quix authored
View
4 bin/rake
@@ -28,6 +28,10 @@ begin
rescue LoadError
end
+module Rake
+ REDUCE_COMPAT = true if ARGV.include?("--reduce-compat")
+end
+
require 'rake'
Rake.application.run
View
5 lib/rake/application.rb
@@ -349,6 +349,11 @@ def standard_rake_options
# HACK Use File::PATH_SEPARATOR
lambda { |value| options.rakelib = value.split(':') }
],
+ ['--reduce-compat', "Remove DSL in Object; remove Module#const_missing which defines ::Task etc.",
+ # Load-time option.
+ # Handled in bin/rake where Rake::REDUCE_COMPAT is defined (or not).
+ lambda { |_| }
+ ],
['--require', '-r MODULE', "Require MODULE before executing rakefile.",
lambda { |value|
begin
View
4 lib/rake/dsl_definition.rb
@@ -165,10 +165,10 @@ def #{name}(*args, &block)
private :#{name}
}, __FILE__, line
end
- end
+ end unless defined? Rake::REDUCE_COMPAT
extend FileUtilsExt
end
self.extend Rake::DSL
-include Rake::DeprecatedObjectDSL
+include Rake::DeprecatedObjectDSL unless defined? Rake::REDUCE_COMPAT
View
2  lib/rake/ext/module.rb
@@ -36,4 +36,4 @@ def const_missing(const_name)
rake_original_const_missing(const_name)
end
end
-end
+end unless defined? Rake::REDUCE_COMPAT
View
65 test/test_rake_reduce_compat.rb
@@ -0,0 +1,65 @@
+require File.expand_path('../helper', __FILE__)
+require 'open3'
+
+class TestRakeReduceCompat < Rake::TestCase
+ # TODO: factor out similar code in test_rake_functional.rb
+ def rake(*args)
+ lib = File.join(@orig_PWD, "lib")
+ bin_rake = File.join(@orig_PWD, "bin", "rake")
+ Open3.popen3(RUBY, "-I", lib, bin_rake, *args) { |_, out, _, _| out.read }
+ end
+
+ def invoke_normal(task_name)
+ rake task_name.to_s
+ end
+
+ def invoke_reduce_compat(task_name)
+ rake "--reduce-compat", task_name.to_s
+ 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 %{"method"}, invoke_normal(:check_task).chomp
+ assert_equal %{"method"}, invoke_normal(:check_file).chomp
+
+ assert_equal "nil", invoke_reduce_compat(:check_task).chomp
+ assert_equal "nil", invoke_reduce_compat(:check_file).chomp
+ end
+
+ def test_no_classic_namespace
+ rakefile %q{
+ task :check_task do
+ begin
+ Task
+ print "present"
+ rescue NameError
+ print "absent"
+ end
+ end
+
+ task :check_file_task do
+ begin
+ FileTask
+ print "present"
+ rescue NameError
+ print "absent"
+ end
+ end
+ }
+
+ assert_equal "present", invoke_normal(:check_task)
+ assert_equal "present", invoke_normal(:check_file_task)
+
+ assert_equal "absent", invoke_reduce_compat(:check_task)
+ assert_equal "absent", invoke_reduce_compat(:check_file_task)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.