Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
40.87k stars 9.59k forks source link

`outdated` and `cleanup` have false positives #2629

Closed chdiza closed 7 years ago

chdiza commented 7 years ago

I have a custom formula foo in a local tap. The version is "2.1.20_1". Only one version of foo is installed in the cellar, and brew outdated keeps giving me:

chdiza/dizaone/foo (2.1.20_1) < 2.1.20_1

which is wrong. Also, brew cleanup -n gives:

Warning: Skipping (old) /usr/local/Cellar/foo/2.1.20_1 due to it being linked

which is also wrong: that's not an old version of anything.

I only noticed this problem because I just bumped to "2.1.20_1" from "2.1.20_0". Apparently the latter gets transformed by brew internals into "2.1.20", which failed to fool brew internals.

The formula foo.rb, by the way, looks like this (shrunken to show a minimally reproducible test case):

class Foo < Formula
  url "file:///usr/local/hb/ChangeLog.md"
  version "2.1.20_1"

  def install
     system "touch", "#{prefix}/foofoo"
  end
end

Here's the relevant stuff:

brew config
HOMEBREW_VERSION: 1.2.0-66-g459fef3b0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 459fef3b09b25d3e24cce6aa6f2e3a7bd5460a2b
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 151887da68c0678c594b6909ac2c271958ada9a8
Core tap last commit: 9 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/hb
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: quad-core 64-bit ivybridge
Homebrew Ruby: 2.0.0-p648
Clang: 8.1 build 802
Git: 2.13.0 => /usr/local/bin/git
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: N/A
macOS: 10.12.4-x86_64
Xcode: 8.3.2
CLT: 8.3.2.0.1.1492020469
X11: N/A
$ brew doctor
Your system is ready to brew
alyssais commented 7 years ago

This is definitely a bug. Think I know what's going on; should have a fix shortly. Thanks for the lovely detailed report @chdiza.

alyssais commented 7 years ago

The problem comes from the "_1" being stripped in one part of the code, but not in another, which messes up as comparison.

alyssais commented 7 years ago

@chdiza Homebrew treats underscores in versions a bit specially, and I think that's what's causing the problem here. I'm interested to know where the version scheme with underscores is coming from? Is there a reason it has to use underscores?

ilovezfs commented 7 years ago

There are at least a few of them

gnu-cobol.rb:25:    version "2.0_nightly_r658"
tbb.rb:5:  version "2017_U6"
tmpreaper.rb:6:  version "1.6.13_nmu1"
vbindiff.rb:5:  version "3.0_beta4"
alyssais commented 7 years ago

Not at computer now so can't confirm, but I think it's only a problem when it's an underscore followed exclusively by digits.

chdiza commented 7 years ago

I'm interested to know where the version scheme with underscores is coming from? Is there a reason it has to use underscores?

It comes from me :) There's no reason why it has to use underscores. It just looks better, and I know that there are other formulas that use underscores so I thought those are allowed.

alyssais commented 7 years ago

Yeah, Homebrew expresses versions ending in /_\d+\Z/ as Homebrew-specific revisions to formulae, so '1.0.0_2' would be 'revision 2 of the formula for 1.0.0'.

It would probably be possible to make Homebrew handle this correctly, but since it doesn't affect any of our formulae (I checked) it probably isn't something we're going to work on ourselves. We'd definitely accept a PR though!