Skip to content

Commit 822d21b

Browse files
committed
(PUP-11597) Generate types when any module libs are updated
1 parent 477a7b3 commit 822d21b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/puppet/generate/type.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,24 @@ def format=(format)
4646
# @return [Boolean] Returns true if the output is up-to-date or false if not.
4747
def up_to_date?(outputdir)
4848
f = effective_output_path(outputdir)
49-
Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
49+
# Check the fast-path scenarios first.
50+
unless Puppet::FileSystem::exist?(f)
51+
Puppet.debug("#{f} does not exist.")
52+
return false
53+
end
54+
unless (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
55+
Puppet.debug("#{@path} is newer than #{f}")
56+
return false
57+
end
58+
# Check for updates to any module lib files.
59+
module_lib_files = Dir.glob(File.join(@base, "lib", "**", "*.rb"))
60+
module_lib_files.each do |lib|
61+
unless (Puppet::FileSystem::stat(lib) <=> Puppet::FileSystem::stat(f)) <= 0
62+
Puppet.debug("#{lib} is newer than #{f}")
63+
return false
64+
end
65+
end
66+
return true
5067
end
5168

5269
# Gets the filename of the output file.

spec/unit/face/generate_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module Puppet
6666
} }
6767
},
6868
},
69-
'm2' => {
69+
'm2' => {
7070
'lib' => { 'puppet' => { 'type' => {
7171
'test2.rb' => <<-EOF
7272
module Puppet
@@ -220,6 +220,18 @@ module Puppet
220220
expect(stat_before <=> stats_after).to be(0)
221221
end
222222

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

225237
context "in an environment with a faulty type" do

0 commit comments

Comments
 (0)