tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bmake's :[range] modifier (was: Cryptic idiom)
Am 19.12.2025 um 11:00 schrieb Frédéric Fauberteau:
>>> It selects the first word in TOOLS_PLATFORM.${_t_} in the case that it
>>> is
>>> a sequence of words.
>> Was that from before bmake learned :[1]?
No, interestingly not. The code in mk/tools/replace.mk is from July
2005, and the :[...] modifier was added in September 2003 (see "blame"
from the netbsd-9 branch), which is almost 2 years earlier. But I guess
at that time, the code in replace.mk was supposed to be
backwards-compatible with earlier versions of NetBSD.
> What makes me want to write:
>
> ```
> TOOLS_CREATE+= ${_t_}
> TOOLS_PATH.${_t_}?= \
> ${TOOLS_PLATFORM.${_t_}:[1]}
That's fine, and when you run pkglint on mk/tools/replace.mk, it
suggests exactly this replacement.
> TOOLS_ARGS.${_t_}?= \
> ${TOOLS_PLATFORM.${_t_}:[2..-1]}
Pkglint doesn't suggest anything for this case, and even if it did, it
might have been fallen for the same trap.
> But it seems to work as expected only if there are several words in
> TOOLS_PLATFORM.${_t_}. In case where TOOLS_PLATFORM.bash would contain
> /bin/bash, both TOOLS_PATH.bash and TOOLS_ARGS.bash are /bin/bash while
> TOOLS_ARGS.bash should be empty.
>
> To me, it looks like a bug. But I wonder if this isn't the expected
> behavior according to bmake(1):
>
>> If start is greater than end, the words are output in reverse order.
The sentence before that is even more interesting, it says:
> For example, `:[2..-1]' selects all words from the second word to the last word.
This contradicts the single-word case. Interestingly,
usr.bin/make/unit-tests/varmod-select-words.mk does not test for an
empty list or a single-element list.
Fixing this bug sounds good, but it has its tricky edge cases, as this
modifier performs both select-words and reverse-list, using a single
syntax. In my view, the modifier ":[2..-1]" does not intend to reverse
the list in some of the cases but not in others. It may be clearer to
say ":[2..]" instead, like in Python or Go. I'll think about the details
in the next few days.
Roland
Home |
Main Index |
Thread Index |
Old Index