Skip to content

Commit

Permalink
(PUP-11597) Generate types when any module libs are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
natemccurdy committed Jan 13, 2023
1 parent 477a7b3 commit 822d21b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/puppet/generate/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,24 @@ def format=(format)
# @return [Boolean] Returns true if the output is up-to-date or false if not.
def up_to_date?(outputdir)
f = effective_output_path(outputdir)
Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
# Check the fast-path scenarios first.
unless Puppet::FileSystem::exist?(f)
Puppet.debug("#{f} does not exist.")
return false
end
unless (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
Puppet.debug("#{@path} is newer than #{f}")
return false
end
# Check for updates to any module lib files.
module_lib_files = Dir.glob(File.join(@base, "lib", "**", "*.rb"))
module_lib_files.each do |lib|
unless (Puppet::FileSystem::stat(lib) <=> Puppet::FileSystem::stat(f)) <= 0
Puppet.debug("#{lib} is newer than #{f}")
return false
end
end
return true
end

# Gets the filename of the output file.
Expand Down
14 changes: 13 additions & 1 deletion spec/unit/face/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Puppet
} }
},
},
'm2' => {
'm2' => {
'lib' => { 'puppet' => { 'type' => {
'test2.rb' => <<-EOF
module Puppet
Expand Down Expand Up @@ -220,6 +220,18 @@ module Puppet
expect(stat_before <=> stats_after).to be(0)
end

it 'overwrites all files if ruby files in lib/puppet_x/ are updated' do
# create them (first run)
puppet_x_lib = File.join(m1, 'lib', 'puppet_x', 'foo', 'library.rb')
Puppet::FileSystem.mkpath(puppet_x_lib)
genface.types
stats_before = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))]
Puppet::FileSystem.touch(puppet_x_lib, :mtime => Time.now + 1000)
genface.types
stats_after = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))]
expect(stats_before <=> stats_after).to eq(-1)
end

end

context "in an environment with a faulty type" do
Expand Down

0 comments on commit 822d21b

Please sign in to comment.