From 4ba23329269ed1fb26dbaf64b56b618b391bf678 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 23 Apr 2014 14:45:57 -0700 Subject: [PATCH] Warn when incorrectly using `replaces` This DSL line was introduced only to deal with the renaming of the "chef-full" artifacts to "chef" back in the dark ages. It has been copypasta'd around to other projects to the point where there was a completely inaccurate @todo added to make replaces default to a broken configuration. Very few projects should be using replaces and including a replaces line which is the same as the package_name will break RPM upgrades. Patch validates that replaces != package_name and yells at the user to knock if off if they're doing that. --- lib/omnibus/exceptions.rb | 21 +++++++++++++++++++++ lib/omnibus/generator_files/project.rb.erb | 1 - lib/omnibus/project.rb | 15 ++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/omnibus/exceptions.rb b/lib/omnibus/exceptions.rb index 6524ca768..266c76380 100644 --- a/lib/omnibus/exceptions.rb +++ b/lib/omnibus/exceptions.rb @@ -82,6 +82,27 @@ def to_s end end + class BadReplacesLine < RuntimeError + def to_s + <<-EOH +The `replaces` project DSL statement should never equal the `package_name` or +`name` of a project. The `replaces` option should only be used when you have +published an artifact under one name and then later renamed the packages that +you are publishing and you must obsolete the old package name. For example this +is used, correctly, in chef-client builds: + + name 'chef' + replaces 'chef-full' + +The RPMs and debs which were originally published were named "chef-full" and +this was later renamed, and in order to upgrade the (very old) "chef-full" +packages the new "chef" packages needed to know to uninstall any "chef-full" +packages that were found. Projects which have never been renamed, however, +should never use the replaces line. + EOH + end + end + class NoPackageFile < RuntimeError def initialize(package_path) @package_path = package_path diff --git a/lib/omnibus/generator_files/project.rb.erb b/lib/omnibus/generator_files/project.rb.erb index 77e8e6344..4e59fe1c1 100644 --- a/lib/omnibus/generator_files/project.rb.erb +++ b/lib/omnibus/generator_files/project.rb.erb @@ -3,7 +3,6 @@ name '<%= config[:name] %>' maintainer 'CHANGE ME' homepage 'CHANGEME.com' -replaces '<%= config[:name] %>' install_path '<%= config[:install_path] %>' build_version Omnibus::BuildVersion.new.semver build_iteration 1 diff --git a/lib/omnibus/project.rb b/lib/omnibus/project.rb index 68b0c613b..2efb66ad1 100644 --- a/lib/omnibus/project.rb +++ b/lib/omnibus/project.rb @@ -141,11 +141,15 @@ def package_me # Ensures that certain project information has been set # - # @raise [MissingProjectConfiguration] if a required parameter has - # not been set + # @todo raise MissingProjectConfiguration instead of printing the warning + # in the next major release + # # @return [void] def validate name && install_path && maintainer && homepage + if package_name == replaces + log.warn { BadReplacesLine.new.message } + end end # @!group DSL methods @@ -300,11 +304,12 @@ def description(val = NULL_ARG) # Ultimately used as the value for the `--replaces` flag in # {https://github.com/jordansissel/fpm fpm}. # + # This should only be used when renaming a package and obsoleting the old + # name of the package. Setting this to the same name as package_name will + # cause RPM upgrades to fail. + # # @param val [String] the name of the package to replace # @return [String] - # - # @todo Consider having this default to {#package_name}; many uses of this - # method effectively do this already. def replaces(val = NULL_ARG) @replaces = val unless val.equal?(NULL_ARG) @replaces