summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-09-26 16:09:06 -0700
committerlamont-granquist <lamont@scriptkiddie.org>2014-09-26 16:09:06 -0700
commitee64fbe29e8a6820152dae99b2b3568b0bb75ae7 (patch)
tree8ce6ef6f31288c379d83431303702a493a3396a7
parent097c135ffe922a6fc37068b97586181ac55cba33 (diff)
parent19a8128f4c03572d779db8a6c03a42b249338860 (diff)
downloadchef-ee64fbe29e8a6820152dae99b2b3568b0bb75ae7.tar.gz
Merge pull request #2046 from opscode/lcg/remove-shellout-syntax-checks
removing shelling out to erubis/ruby
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/chef/cookbook/syntax_check.rb48
2 files changed, 6 insertions, 45 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe182840e0..fdd449f218 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -75,6 +75,9 @@
### Chef Contributions
+* Removed shelling out to erubis/ruby for syntax checks (>= 1.9 has been able
+ to do this in the ruby vm itself for awhile now and we've dropped 1.8.7 which
+ could not do this and had to shell_out)
* Report the request and response when a non-200 error code happens
* [FEATURE] Upgrade `knife upload` and `knife download` to download
**everything** in an organization, now including the organization definition
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index 3b35f77de9..69c194516b 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -164,31 +164,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
@@ -215,20 +200,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]
@@ -239,7 +210,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
@@ -264,18 +234,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)