Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-dev] [PATCH 3/5] cmake.eclass: Support dev-util/samurai

7 views
Skip to first unread message

Sam James

unread,
May 8, 2022, 7:10:03 PM5/8/22
to
From: orbea <or...@riseup.net>

samurai is a ninja-compatible build tool written in C which
works with cmake, meson and other users of ninja.

It is feature-complete and supports most of the same options
as ninja.

Signed-off-by: orbea <or...@riseup.net>
Signed-off-by: Sam James <s...@gentoo.org>
---
eclass/cmake.eclass | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
index 59e5b60957c2..7ad0f6a7d45e 100644
--- a/eclass/cmake.eclass
+++ b/eclass/cmake.eclass
@@ -136,7 +136,7 @@ case ${CMAKE_MAKEFILE_GENERATOR} in
BDEPEND="sys-devel/make"
;;
ninja)
- BDEPEND="dev-util/ninja"
+ BDEPEND="${NINJA_DEPEND}"
;;
*)
eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
@@ -365,7 +365,7 @@ cmake_src_prepare() {

# if ninja is enabled but not installed, the build could fail
# this could happen if ninja is manually enabled (eg. make.conf) but not installed
- if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
+ if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b "${NINJA_DEPEND}"; then
eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
fi
@@ -703,12 +703,17 @@ cmake_src_test() {
# @DESCRIPTION:
# Function for installing the package. Automatically detects the build type.
cmake_src_install() {
+ local generator=${CMAKE_MAKEFILE_GENERATOR}
+ case ${CMAKE_MAKEFILE_GENERATOR} in
+ ninja) generator="eninja" ;;
+ esac
+
debug-print-function ${FUNCNAME} "$@"

_cmake_check_build_dir
pushd "${BUILD_DIR}" > /dev/null || die
- DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
- die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
+ DESTDIR="${D}" ${generator} install "$@" ||
+ die "died running ${generator} install"
popd > /dev/null || die

if [[ ${EAPI} == 7 ]]; then
--
2.35.1

Sam James

unread,
May 8, 2022, 7:10:03 PM5/8/22
to
From: orbea <or...@riseup.net>

samurai is a ninja-compatible build tool written in C which
works with cmake, meson and other users of ninja.

It is feature-complete and supports most of the same options
as ninja.

Signed-off-by: orbea <or...@riseup.net>
Signed-off-by: Sam James <s...@gentoo.org>
---
eclass/ninja-utils.eclass | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/eclass/ninja-utils.eclass b/eclass/ninja-utils.eclass
index c5f34934192f..67f7a6b5e8a7 100644
--- a/eclass/ninja-utils.eclass
+++ b/eclass/ninja-utils.eclass
@@ -26,6 +26,15 @@ esac
if [[ -z ${_NINJA_UTILS_ECLASS} ]]; then
_NINJA_UTILS_ECLASS=1

+# @ECLASS_VARIABLE: NINJA
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Specify a compatible ninja implementation to be used by eninja.
+# At this point only "ninja" and "samu" are supported.
+# The default is set to "ninja".
+: ${NINJA:=ninja}
+
# @ECLASS_VARIABLE: NINJAOPTS
# @DEFAULT_UNSET
# @DESCRIPTION:
@@ -35,6 +44,19 @@ _NINJA_UTILS_ECLASS=1

inherit multiprocessing

+case "${NINJA}" in
+ ninja)
+ NINJA_DEPEND=">=dev-util/ninja-1.8.2"
+ ;;
+ samu)
+ NINJA_DEPEND="dev-util/samurai"
+ ;;
+ *)
+ eerror "Unknown value for \${NINJA}"
+ die "Value ${NINJA} is not supported"
+ ;;
+esac
+
# @FUNCTION: eninja
# @USAGE: [<args>...]
# @DESCRIPTION:
@@ -48,7 +70,7 @@ eninja() {
if [[ -z ${NINJAOPTS+set} ]]; then
NINJAOPTS="-j$(makeopts_jobs "${MAKEOPTS}" 999) -l$(makeopts_loadavg "${MAKEOPTS}" 0)"
fi
- set -- ninja -v ${NINJAOPTS} "$@"
+ set -- "${NINJA}" -v ${NINJAOPTS} "$@"
echo "$@" >&2
"$@" || die "${nonfatal_args[@]}" "${*} failed"
}
--
2.35.1

Michał Górny

unread,
May 9, 2022, 3:20:03 AM5/9/22
to
I'm sorry for missing this earlier but could we perhaps reuse
cmake_build here? Instead of this whole block above, something like:

DESTDIR="${D}" cmake_build install "$@"

>
> if [[ ${EAPI} == 7 ]]; then

--
Best regards,
Michał Górny

Pacho Ramos

unread,
May 9, 2022, 8:00:02 AM5/9/22
to
El lun, 09-05-2022 a las 13:50 +0200, Pacho Ramos escribió:
> Personally I would add "samurai" as value instead of the abbreviated "samu"
> form
> (that could come from other words than "samurai")... but has you wish :), it
> is
> only a cosmetic change anyway
>
> Thanks
>
>
*as you wish

signature.asc

Pacho Ramos

unread,
May 9, 2022, 8:00:02 AM5/9/22
to
El dom, 08-05-2022 a las 23:07 +0000, Sam James escribió:
signature.asc

Mike Gilbert

unread,
May 9, 2022, 11:00:02 AM5/9/22
to
This is tagged as @DEFAULT_UNSET, but the description and
implementation indicate that it defaults to "ninja".

> # @ECLASS_VARIABLE: NINJAOPTS
> # @DEFAULT_UNSET
> # @DESCRIPTION:
> @@ -35,6 +44,19 @@ _NINJA_UTILS_ECLASS=1
>
> inherit multiprocessing
>
> +case "${NINJA}" in
> + ninja)
> + NINJA_DEPEND=">=dev-util/ninja-1.8.2"
> + ;;
> + samu)
> + NINJA_DEPEND="dev-util/samurai"
> + ;;
> + *)
> + eerror "Unknown value for \${NINJA}"
> + die "Value ${NINJA} is not supported"
> + ;;
> +esac

The NINJA environment variable is used directly by meson and may
contain an absolute path. I don't think it makes sense to restrict
possible values to just "ninja" and "samu". That will make it more
difficult for users to override it with a local copy of either tool,
or to use a different implementation should someone write one in the
future.

It might make sense to introduce a different eclass variable to
control NINJA_DEPEND and the default value for NINJA.

Mike Gilbert

unread,
May 9, 2022, 2:00:03 PM5/9/22
to
On Mon, May 9, 2022 at 1:13 PM orbea <or...@riseup.net> wrote:
>
> On Mon, 9 May 2022 10:59:03 -0400
> Mike Gilbert <flo...@gentoo.org> wrote:
> > The NINJA environment variable is used directly by meson and may
> > contain an absolute path. I don't think it makes sense to restrict
> > possible values to just "ninja" and "samu". That will make it more
> > difficult for users to override it with a local copy of either tool,
> > or to use a different implementation should someone write one in the
> > future.
> >
> > It might make sense to introduce a different eclass variable to
> > control NINJA_DEPEND and the default value for NINJA.
>
> The game antares (https://github.com/arescentral/antares) has a custom
> python based build system that also respects the NINJA variable.
>
> Your point is a good one, but I'm unsure how this would work? The
> NINJA_DEPEND variable has to be set to a valid package elsewhere in the
> eclass scripts, for example the 'has_version -b' check in the cmake
> eclass.
>
> Allowing the user to set an arbitrary value will require they also
> being able to set NINJA_DEPEND to a correct value. In some of these
> cases there may not be an applicable ebuild to set it to even. Maybe
> I'm missing something, but this seems like a good way to complicate the
> process and possibly introduce pebkac. Maybe it would be preferable to
> just add additional ninja implementations to the list as they are
> available?
>
> Also if its just testing local versions I think it could be worked
> around by setting the PATH and / or using symlinks? A user could
> create a dummy ebuild as well.

We could make the eclass ewarn on unknown NINJA values, and set
NINJA_DEPEND to empty in that case. Just don't call "die".

That would allow users to override NINJA without triggering a failure,
and still alerts ebuild maintainers in case they make a typo when
setting NINJA in an ebuild.

Anna “CyberTailor”

unread,
May 30, 2022, 4:00:02 PM5/30/22
to
On 2022-05-08 23:07, Sam James wrote:
> From: orbea <or...@riseup.net>
>
> samurai is a ninja-compatible build tool written in C which
> works with cmake, meson and other users of ninja.
>
> It is feature-complete and supports most of the same options
> as ninja.
>
> Signed-off-by: orbea <or...@riseup.net>
> Signed-off-by: Sam James <s...@gentoo.org>
> ---
> eclass/ninja-utils.eclass | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/eclass/ninja-utils.eclass b/eclass/ninja-utils.eclass
> index c5f34934192f..67f7a6b5e8a7 100644
> --- a/eclass/ninja-utils.eclass
> +++ b/eclass/ninja-utils.eclass
> @@ -26,6 +26,15 @@ esac
> if [[ -z ${_NINJA_UTILS_ECLASS} ]]; then
> _NINJA_UTILS_ECLASS=1
>
> +# @ECLASS_VARIABLE: NINJA
> +# @PRE_INHERIT

How about making it @USER_VARIABLE instead? Because it's more likely to
be set in make.conf rather than in an ebuild.

Mike Gilbert

unread,
May 30, 2022, 5:00:03 PM5/30/22
to
On Mon, May 30, 2022 at 3:57 PM Anna “CyberTailor”
<cyber+...@sysrq.in> wrote:
>
> On 2022-05-08 23:07, Sam James wrote:
> > From: orbea <or...@riseup.net>
> >
> > samurai is a ninja-compatible build tool written in C which
> > works with cmake, meson and other users of ninja.
> >
> > It is feature-complete and supports most of the same options
> > as ninja.
> >
> > Signed-off-by: orbea <or...@riseup.net>
> > Signed-off-by: Sam James <s...@gentoo.org>
> > ---
> > eclass/ninja-utils.eclass | 24 +++++++++++++++++++++++-
> > 1 file changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/eclass/ninja-utils.eclass b/eclass/ninja-utils.eclass
> > index c5f34934192f..67f7a6b5e8a7 100644
> > --- a/eclass/ninja-utils.eclass
> > +++ b/eclass/ninja-utils.eclass
> > @@ -26,6 +26,15 @@ esac
> > if [[ -z ${_NINJA_UTILS_ECLASS} ]]; then
> > _NINJA_UTILS_ECLASS=1
> >
> > +# @ECLASS_VARIABLE: NINJA
> > +# @PRE_INHERIT
>
> How about making it @USER_VARIABLE instead? Because it's more likely to
> be set in make.conf rather than in an ebuild.

It's "unofficially" supported as a user variable. If users set it in
make.conf, it will break metadata invariance and the dependency cache
will need to be rebuilt.

If we truly want to support it as a user variable, we need to provide
some alternate means of varying BDEPEND.
0 new messages