From 14b4150fb853d3ffd73739040606e7decbef3861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 4 May 2023 08:48:06 -1000 Subject: [PATCH] Add a function to update / regenerate deprecated shims In order to move existing unamespaced functions to the stdlib namespace (#1346) without breaking backwards compatibility, we need some compatibility shims. They will all look-like the same, so add a rake task to regenerate them if we need to update them. --- Rakefile | 30 ++++++++++++++++++++++ lib/puppet/functions/has_interface_with.rb | 4 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 9aa3a64e3..3767a06d4 100644 --- a/Rakefile +++ b/Rakefile @@ -87,3 +87,33 @@ EOM end end +desc 'Regenerate the deprecated unamespaced shims' +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/ + warn("#{filename} does not look like a deprecation shim (skipping)") + next + end + + function_name = File.basename(filename, '.rb') + + File.write(filename, <<~CODE) + # frozen_string_literal: true + + # THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + + # @summary DEPRECATED. Use the namespaced function [`stdlib::#{function_name}`](#stdlib#{function_name}) instead. + Puppet::Functions.create_function(:#{function_name}) do + dispatch :deprecation_gen do + repeated_param 'Any', :args + end + def deprecation_gen(*args) + call_function('deprecation', '#{function_name}', 'This function is deprecated, please use stdlib::#{function_name} instead.') + call_function('stdlib::#{function_name}', *args) + end + end + CODE + end +end diff --git a/lib/puppet/functions/has_interface_with.rb b/lib/puppet/functions/has_interface_with.rb index d166bb42f..002ca6e2d 100644 --- a/lib/puppet/functions/has_interface_with.rb +++ b/lib/puppet/functions/has_interface_with.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + # @summary DEPRECATED. Use the namespaced function [`stdlib::has_interface_with`](#stdlibhas_interface_with) instead. Puppet::Functions.create_function(:has_interface_with) do dispatch :deprecation_gen do repeated_param 'Any', :args end def deprecation_gen(*args) - call_function('deprecation', 'has_interface_with', 'This method is deprecated, please use stdlib::has_interface_with instead.') + call_function('deprecation', 'has_interface_with', 'This function is deprecated, please use stdlib::has_interface_with instead.') call_function('stdlib::has_interface_with', *args) end end