summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-09-11 14:42:11 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-09-11 14:42:11 -0700
commite309a2271647fe412c81318978b7ac34a6ff2cb6 (patch)
tree93d3344c00da5648b31ea400b4b3b788da3a13d2
parent34d956c6b96087e6ca4bfbc9080037ded481709d (diff)
downloadchef-lcg/remove-shellout-syntax-checks.tar.gz
removing shelling out to erubis/rubylcg/remove-shellout-syntax-checks
ruby-1.8.7 is dropped so we don't do this any more.
-rw-r--r--lib/chef/cookbook/syntax_check.rb48
1 files changed, 3 insertions, 45 deletions
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index 092fb47eba..3983986e31 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -163,31 +163,16 @@ class Chef
def validate_template(erb_file)
Chef::Log.debug("Testing template #{erb_file} for syntax errors...")
- if validate_inline?
- validate_erb_file_inline(erb_file)
- else
- validate_erb_via_subcommand(erb_file)
- end
+ validate_erb_file_inline(erb_file)
end
def validate_ruby_file(ruby_file)
Chef::Log.debug("Testing #{ruby_file} for syntax errors...")
- if validate_inline?
- validate_ruby_file_inline(ruby_file)
- else
- validate_ruby_by_subcommand(ruby_file)
- end
- end
-
- # Whether or not we're running on a version of ruby that can support
- # inline validation. Inline validation relies on the `RubyVM` features
- # introduced with ruby 1.9, so 1.8 cannot be supported.
- def validate_inline?
- defined?(RubyVM::InstructionSequence)
+ validate_ruby_file_inline(ruby_file)
end
# Validate the ruby code in an erb template. Uses RubyVM to do syntax
- # checking, so callers should check #validate_inline? before calling.
+ # checking.
def validate_erb_file_inline(erb_file)
old_stderr = $stderr
@@ -214,20 +199,6 @@ class Chef
$stderr = old_stderr if defined?(old_stderr) && old_stderr
end
- # Validate the ruby code in an erb template. Pipes the output of `erubis
- # -x` to `ruby -c`, so it works with any ruby version, but is much slower
- # than the inline version.
- # --
- # TODO: This can be removed when ruby 1.8 support is dropped.
- def validate_erb_via_subcommand(erb_file)
- result = shell_out("erubis -x #{erb_file} | #{ruby} -c")
- result.error!
- true
- rescue Mixlib::ShellOut::ShellCommandFailed
- invalid_erb_file(erb_file, result.stderr)
- false
- end
-
# Debug a syntax error in a template.
def invalid_erb_file(erb_file, error_message)
file_relative_path = erb_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1]
@@ -238,7 +209,6 @@ class Chef
# Validate the syntax of a ruby file. Uses (Ruby 1.9+ only) RubyVM to
# compile the code without evaluating it or spawning a new process.
- # Callers should check #validate_inline? before calling.
def validate_ruby_file_inline(ruby_file)
# Even when we're compiling the code w/ RubyVM, syntax errors just
# print to $stderr. We want to capture this and handle the printing
@@ -263,18 +233,6 @@ class Chef
$stderr = old_stderr if defined?(old_stderr) && old_stderr
end
- # Validate the syntax of a ruby file by shelling out to `ruby -c`. Should
- # work for all ruby versions, but is slower and uses more resources than
- # the inline strategy.
- def validate_ruby_by_subcommand(ruby_file)
- result = shell_out("#{ruby} -c #{ruby_file}")
- result.error!
- true
- rescue Mixlib::ShellOut::ShellCommandFailed
- invalid_ruby_file(ruby_file, result.stderr)
- false
- end
-
# Debugs ruby syntax errors by printing the path to the file and any
# diagnostic info given in +error_message+
def invalid_ruby_file(ruby_file, error_message)