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 Nov 15, 2023
1 parent 810bf8e commit 37c4da9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/puppet/generate/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@ 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.
Dir.glob(File.join(@base, "lib", "**", "*.rb")) 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
16 changes: 15 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,20 @@ 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'))]
# Sorry. The sleep is needed because Puppet::FileSystem.touch(<path>, :mtime => Time.now + 1000) doesn't work on Windows.
sleep(1)
Puppet::FileSystem.touch(puppet_x_lib)
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 37c4da9

Please sign in to comment.