Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 867934 - flag-o-matic.eclass: test-flags-* docs do not describe output
Summary: flag-o-matic.eclass: test-flags-* docs do not describe output
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-01 23:53 UTC by Sam James
Modified: 2022-09-03 02:02 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-09-01 23:53:48 UTC
Docs say:
```
test-flags-CC <flags>
    Returns shell true if <flags> are supported by the C compiler, else returns shell false. 
test-flags-CXX <flags>
    Returns shell true if <flags> are supported by the C++ compiler, else returns shell false. 
test-flags-F77 <flags>
    Returns shell true if <flags> are supported by the Fortran 77 compiler, else returns shell false. 
test-flags-FC <flags>
    Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false. 
test-flags-CCLD <flags>
    Returns shell true if <flags> are supported by the C compiler and default linker, else returns shell false. 
test-flags <flags>
    Short-hand that should hopefully work for both C and C++ compiler, but its really only present due to the append-flags() abomination. 
```

But they actually return the flags tested:
```
$ grep -rsin "test-flags-"
dev-lang/cfortran/cfortran-20110621.ebuild:42:  use sparc && append-fflags $(test-flags-FC -fno-store-merging -fno-tree-slp-vectorize) # bug 818400
dev-lang/cfortran/cfortran-20210827.ebuild:43:  use sparc && append-fflags $(test-flags-FC -fno-store-merging -fno-tree-slp-vectorize) # bug 818400
dev-lang/c-intercal/c-intercal-31.0.ebuild:51:  append-cflags $(test-flags-CC -fno-toplevel-reorder)    #722862
dev-lang/python/python-3.10.6_p2.ebuild:163:            append-cflags $(test-flags-CC -ffat-lto-objects)
dev-lang/python/python-3.8.13_p6.ebuild:149:            append-cflags $(test-flags-CC -ffat-lto-objects)
dev-lang/python/python-3.9.13_p4.ebuild:159:            append-cflags $(test-flags-CC -ffat-lto-objects)
dev-lang/python/python-3.11.0_rc1.ebuild:150:           append-cflags $(test-flags-CC -ffat-lto-objects)
```

We even document this usage as an example in the eclass:
```
# @FUNCTION: append-cflags
# @USAGE: <flags>
# @DESCRIPTION:
# Add extra <flags> to the current CFLAGS.  If a flag might not be supported
# with different compilers (or versions), then use test-flags-CC like so:
# @CODE
# append-cflags $(test-flags-CC -funky-flag)
# @CODE
[...]
```

We should just fix the docs for test-flag(s?)* to mention it returns the relevant flags.
Comment 1 Arfrever Frehtes Taifersar Arahesis 2022-09-02 06:04:42 UTC
Functions in BASH can only RETURN number (integer), not string, but they can OUTPUT string.

Descriptions of test-flags-CC etc. are correct and they mean that it is possible to use these functions in this way:
if test-flags-CC -flag1 -flag2; then
    ....
else
    ....
fi

There are test-flag-* and test-flags-* variants of these functions.
test-flag-* can be actually called with multiple arguments.
test-flag-* returns true only if all specified flags are supported, and currently does not output anything.
test-flags-* returns true if at least one of specified flags is supported, and outputs only these flags which are supported (some subset of flags passed to function).

If current behavior is to remain, then descriptions of test-flags-*, but not test-flag-*, can be extended:
# @FUNCTION: test-flags-CC
# @USAGE: <flags>
# @DESCRIPTION:
# Returns shell true if <flags> are supported by the C compiler, else returns shell false.
# Outputs supported flags.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-09-02 06:06:03 UTC
I know. Let me rephrase: "people may be relying on undocumented behaviour of functions".
Comment 3 Arfrever Frehtes Taifersar Arahesis 2022-09-02 06:22:27 UTC
use() has verbose usev() equivalent.
Maybe it would be cleaner to have 4 groups of functions. E.g.:
  test-flags-all-* (e.g. test-flags-all-CC)
  test-flags-verbose-all-* (e.g. test-flags-verbose-all-CC)
  test-flags-any-* (e.g. test-flags-any-CC)
  test-flags-verbose-any-* (e.g. test-flags-verbose-any-CC)