From 37c4da90751139366db8c75d70c178c0a2853ce0 Mon Sep 17 00:00:00 2001 From: Nate McCurdy Date: Tue, 26 Jul 2022 13:37:39 -0700 Subject: [PATCH] (PUP-11597) Generate types when any module libs are updated --- lib/puppet/generate/type.rb | 18 +++++++++++++++++- spec/unit/face/generate_spec.rb | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/puppet/generate/type.rb b/lib/puppet/generate/type.rb index 866d85ba284..e9249d45111 100644 --- a/lib/puppet/generate/type.rb +++ b/lib/puppet/generate/type.rb @@ -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. diff --git a/spec/unit/face/generate_spec.rb b/spec/unit/face/generate_spec.rb index 95b78e459ba..1198cacd9a5 100644 --- a/spec/unit/face/generate_spec.rb +++ b/spec/unit/face/generate_spec.rb @@ -66,7 +66,7 @@ module Puppet } } }, }, - 'm2' => { + 'm2' => { 'lib' => { 'puppet' => { 'type' => { 'test2.rb' => <<-EOF module Puppet @@ -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(, :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