pkgcore / pkgcheck

pkgcore-based QA utility for ebuild repos
https://pkgcore.github.io/pkgcheck
BSD 3-Clause "New" or "Revised" License
34 stars 29 forks source link

[New Check]: Warn on unconditional `use foo` where `foo` is not in `IUSE` #654

Open thesamesam opened 5 months ago

thesamesam commented 5 months ago

Is there an existing such new check request for this?

Explain

use foo is illegal if foo is not in IUSE.

We can check if foo is in IUSE and whether there's an unconditional simple use of use, like:

src_prepare() {
    if use foo || ... ; then
        ...
    fi
}

In such a case, use foo is definitely illegal as there's no in_iuse call.

It will fail like:

 * ERROR: app-misc/bar-1::gentoo failed (prepare phase):
 *   USE Flag 'foo' not in IUSE for app-misc/bar-1

Examples

https://bugs.gentoo.org/921303

See dev-php/pecl-memcache in ::gentoo, fixed in commit bc4be3473afc1a1992475fd58df256bde6df7fcb.

Output message

MissingIuse

Documentation

USE flag not in IUSE referenced via use command.

Result level

error

thesamesam commented 5 months ago

We've had quite a lot of other examples of this where we forget to fully cleanup a USE flag but I can't recall any right now.

EDIT: https://bugs.gentoo.org/buglist.cgi?quicksearch=ALL%20%22not%20in%20IUSE%22&list_id=7051610

thesamesam commented 5 months ago

Another common case for this is where a flag is removed from IUSE but not in configure (say, a call to econf).

arthurzam commented 5 months ago

Well, Now I found the issues with automating this check:

$ pkgcheck scan -c UnknownUseFlagsCheck
app-office/kmymoney
  MissingIuse: version 5.1.3: line 89: USE flag 'experimental' not in IUSE, called: use experimental
  MissingIuse: version 5.1.3: line 110: USE flag 'experimental' not in IUSE, called: usex experimental

games-action/descent2-freedata
  MissingIuse: version 1: line 48: USE flag 'textures' not in IUSE, called: use textures

sys-firmware/sigrok-firmware-fx2lafw
  MissingIuse: version 9999: line 36: USE flag 'binary' not in IUSE, called: use binary
  MissingIuse: version 9999: line 46: USE flag 'binary' not in IUSE, called: use binary

All of them are behind a weird if logic, which for me stands for close to abuse.

thesamesam commented 5 months ago

If we check IUSE in metadata for that versinon, we should avoid the FPs, even if those matches you gave look suspicious (they look valid but easy to get wrong).

arthurzam commented 5 months ago

If we check IUSE in metadata for that versinon, we should avoid the FPs, even if those matches you gave look suspicious (they look valid but easy to get wrong).

Sorry, I failed at understanding this reply. How would metadata scan help us, since this is protected behind magic if, for example:

src_install() {
        if [[ ${PV} != "9999" ]] && use binary ; then # <--- notice magic here
                insinto /usr/share/sigrok-firmware
                doins *.fw
                dodoc ChangeLog NEWS README
        else
                default
        fi
}
thesamesam commented 5 months ago

Ah, I see. OK, let's just skip it if the line has non-use conditionals?