Skip to content

Commit

Permalink
Warn when incorrectly using replaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lamont-granquist authored and sethvargo committed May 14, 2014
1 parent dba13e4 commit 4ba2332
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
21 changes: 21 additions & 0 deletions lib/omnibus/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/omnibus/generator_files/project.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions lib/omnibus/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ba2332

Please sign in to comment.