From 4c111e7f0f2ea21fa60bc50509040e1b6afd6d6f Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 2 Jun 2023 18:03:19 +0100 Subject: [PATCH] Pass calling scope to `stdlib::ensure_packages` from shim Make the `ensure_packages` shim an Internal function and pass scope to the namespaced version so as to not change the behaviour of where packages are contained. When the function was first ported to the new API, it was discussed that the existing behaviour might not be 'correct', but changing it would be a breaking change that might have consequences for many users. In namespacing the function in 9.0.0 we accidentally created a situation where the namespaced version worked as before, but the non-namespaced version, (the shim), now behaved differently. Fixes #1365 --- Rakefile | 7 ++++++- lib/puppet/functions/ensure_packages.rb | 9 ++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 3767a06d4..a647c6f93 100644 --- a/Rakefile +++ b/Rakefile @@ -92,11 +92,16 @@ task :regenerate_unamespaced_shims do Dir['lib/puppet/functions/*.rb'].each do |filename| content = File.read(filename) - unless content =~ /@summary DEPRECATED. Use the namespaced function/ + unless content =~ /@summary DEPRECATED\. Use the namespaced function/ warn("#{filename} does not look like a deprecation shim (skipping)") next end + if content =~ /InternalFunction/ + warn("#{filename} is a special case. Not regenerating a shim for this file") + next + end + function_name = File.basename(filename, '.rb') File.write(filename, <<~CODE) diff --git a/lib/puppet/functions/ensure_packages.rb b/lib/puppet/functions/ensure_packages.rb index 0d8c5a773..fd26cbc11 100644 --- a/lib/puppet/functions/ensure_packages.rb +++ b/lib/puppet/functions/ensure_packages.rb @@ -1,14 +1,13 @@ # frozen_string_literal: true -# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` - # @summary DEPRECATED. Use the namespaced function [`stdlib::ensure_packages`](#stdlibensure_packages) instead. -Puppet::Functions.create_function(:ensure_packages) do +Puppet::Functions.create_function(:ensure_packages, Puppet::Functions::InternalFunction) do dispatch :deprecation_gen do + scope_param repeated_param 'Any', :args end - def deprecation_gen(*args) + def deprecation_gen(scope, *args) call_function('deprecation', 'ensure_packages', 'This function is deprecated, please use stdlib::ensure_packages instead.') - call_function('stdlib::ensure_packages', *args) + scope.call_function('stdlib::ensure_packages', args) end end