When running puppet doc, if the directory containing the user's specified manifest file overlaps with the modules directory (i.e. they are the same directory or one contains the other), Puppet doc would try to parse the overlapping files twice, triggering an exception which made the documentation run fail.
Fixed the bug by adding a check to the RDoc::Parser#scan method to prevent re-parsing of files that have already been parsed. Also added a spec test to verify that this works. Signed-off-by: Paul Berry <[email protected]> --- lib/puppet/util/rdoc/parser.rb | 15 +++++---- spec/integration/application/doc_spec.rb | 48 ++++++++++++++++++++++++++++++ spec/lib/puppet_spec/files.rb | 1 + spec/unit/util/rdoc/parser_spec.rb | 2 +- 4 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 spec/integration/application/doc_spec.rb diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index 63df38a..8414843 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -33,13 +33,16 @@ class Parser # main entry point def scan - Puppet.info "rdoc: scanning #...@input_file_name}" - if @input_file_name =~ /\.pp$/ - @parser = Puppet::Parser::Parser.new(Puppet[:environment]) - @parser.file = @input_file_name - @ast = @parser.parse + env = Puppet::Node::Environment.new + unless env.known_resource_types.watching_file?(@input_file_name) + Puppet.info "rdoc: scanning #...@input_file_name}" + if @input_file_name =~ /\.pp$/ + @parser = Puppet::Parser::Parser.new(env) + @parser.file = @input_file_name + @ast = @parser.parse + end + scan_top_level(@top_level) end - scan_top_level(@top_level) @top_level end diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb new file mode 100644 index 0000000..cb9f478 --- /dev/null +++ b/spec/integration/application/doc_spec.rb @@ -0,0 +1,48 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet_spec/files' + +describe Puppet::Application::Doc do + include PuppetSpec::Files + + it "should not generate an error when module dir overlaps parent of site.pp (#4798)" do + begin + # Note: the directory structure below is more complex than it + # needs to be, but it's representative of the directory structure + # used in bug #4798. + old_dir = Dir.getwd # Note: can't use chdir with a block because it will generate bogus warnings + tmpdir = tmpfile('doc_spec') + Dir.mkdir(tmpdir) + Dir.chdir(tmpdir) + site_file = 'site.pp' + File.open(site_file, 'w') do |f| + f.puts '# A comment' + end + modules_dir = 'modules' + Dir.mkdir(modules_dir) + rt_dir = File.join(modules_dir, 'rt') + Dir.mkdir(rt_dir) + manifests_dir = File.join(rt_dir, 'manifests') + Dir.mkdir(manifests_dir) + rt_file = File.join(manifests_dir, 'rt.pp') + File.open(rt_file, 'w') do |f| + f.puts '# A class' + f.puts 'class foo { }' + f.puts '# A definition' + f.puts 'define bar { }' + end + + puppet = Puppet::Application[:doc] + Puppet[:modulepath] = modules_dir + Puppet[:manifest] = site_file + puppet.options[:mode] = :rdoc + puppet.expects(:exit).with(0) + puppet.run_command + + File.should be_exist('doc') + ensure + Dir.chdir(old_dir) + end + end +end diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index cab4a1e..52ed903 100644 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'tempfile' # A support module for testing files. module PuppetSpec::Files diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index 79195e6..3614c0a 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -19,7 +19,7 @@ describe RDoc::Parser do it "should parse puppet files with the puppet parser" do @parser.stubs(:scan_top_level) parser = stub 'parser' - Puppet::Parser::Parser.expects(:new).returns(parser) + Puppet::Parser::Parser.stubs(:new).returns(parser) parser.expects(:parse) parser.expects(:file=).with("module/manifests/init.pp") -- 1.7.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
