diff mbox series

meson: skip gitweb build when Perl is disabled

Message ID 20241220-b4-pks-meson-fix-gitweb-wo-perl-v1-1-41039ad8d8d4@pks.im (mailing list archive)
State Superseded
Headers show
Series meson: skip gitweb build when Perl is disabled | expand

Commit Message

Patrick Steinhardt Dec. 20, 2024, 7:26 a.m. UTC
It is possible to configure a Git build without Perl when disabling both
our test suite and all Perl-based features. In Meson, this can be
achieved with `meson setup -Dperl=disabled -Dtests=false`.

It was reported by a user that this breaks the Meson build because
gitweb gets built even if Perl was not discovered in such a build:

    $ meson setup .. -Dtests=false -Dperl=disabled
    ...
    ../gitweb/meson.build:2:43: ERROR: Unable to get the path of a not-found external program

Fix this issue by introducing a new feature-option that allows the user
to configure whether or not to build Gitweb. The feature is set to
'auto' by default and will be disabled automatically in case Perl was
not found on the system.

Reported-by: Daniel Engberg <daniel.engberg.lists@pyret.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Hi,

I received an off-list mail from a user interested in the new Meson
build system who has done a bit of testing of it on FreeBSD. They found
an issue when configuring the build without Perl enabled, which can be
achieved by both disabling tests and Perl-based features. This patch
here fixes the issue.

Thanks!

Patrick
---
 meson.build       | 13 +++++++++++--
 meson_options.txt |  2 ++
 2 files changed, 13 insertions(+), 2 deletions(-)


---
base-commit: d882f382b3d939d90cfa58d17b17802338f05d66
change-id: 20241218-b4-pks-meson-fix-gitweb-wo-perl-93379dd0ceed

Comments

Junio C Hamano Dec. 20, 2024, 3:03 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> It is possible to configure a Git build without Perl when disabling both
> our test suite and all Perl-based features. In Meson, this can be
> achieved with `meson setup -Dperl=disabled -Dtests=false`.
>
> It was reported by a user that this breaks the Meson build because
> gitweb gets built even if Perl was not discovered in such a build:
>
>     $ meson setup .. -Dtests=false -Dperl=disabled
>     ...
>     ../gitweb/meson.build:2:43: ERROR: Unable to get the path of a not-found external program
>
> Fix this issue by introducing a new feature-option that allows the user
> to configure whether or not to build Gitweb. The feature is set to
> 'auto' by default and will be disabled automatically in case Perl was
> not found on the system.
>
> Reported-by: Daniel Engberg <daniel.engberg.lists@pyret.net>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> Hi,
>
> I received an off-list mail from a user interested in the new Meson
> build system who has done a bit of testing of it on FreeBSD. They found
> an issue when configuring the build without Perl enabled, which can be
> achieved by both disabling tests and Perl-based features. This patch
> here fixes the issue.
>
> Thanks!

Thanks, Patrick and Daniel.

> -if get_option('tests')
> +if get_option('tests') or get_option('gitweb').enabled()
>    perl_required = true
>  endif

OK, so we use "perl_required" to keep track of the fact that
something else wants Perl to be usable.

> +# Gitweb requires Perl, so we disable the auto-feature if Perl was not found.
> +# We make sure further up that Perl is required in case the gitweb option is
> +# enabled.
> +gitweb_option = get_option('gitweb').disable_auto_if(not perl.found())

Hopefully before we reach this point, we would have figured out if
perl is avialable, to allow us do this.

There seem to be too many "perl" related variables, interaction
among which smells way too complex for their worth.  For example,

    perl = find_program('perl', ..., required: perl_required);
    perl_features_enabled = perl.found() and get_option('perl').allowed()

and only when the latter is true, we'd do further configuration to
make perl usable.  Does that mean the condition you wrote above to
automatically disable gitweb somewhat incorrect?  Even if we may
have found perl, the builder may deliberately have disallowed use of
it, in which case we just know perl is there without figuring out
what other things (like where the localedir is) that are needed to
use it correctly.

> +if gitweb_option.enabled()
> +  subdir('gitweb')
> +endif
> +
>  subdir('templates')

OK, we used to do the subdir() thing unconditionally, but now, if we
decide that we shouldn't or cannot do gitweb, we do not do
that,which sounds good.

> +option('gitweb', type: 'feature', value: 'auto',
> +  description: 'Build Git web interface. Required Perl.')

I do not know the convention in the meson world, but to me, this
would sound more natural with "Required" -> "Requires".

>  option('iconv', type: 'feature', value: 'auto',
>    description: 'Support reencoding strings with different encodings.')
>  option('pcre2', type: 'feature', value: 'enabled',
>
> ---
> base-commit: d882f382b3d939d90cfa58d17b17802338f05d66
> change-id: 20241218-b4-pks-meson-fix-gitweb-wo-perl-93379dd0ceed
Patrick Steinhardt Dec. 20, 2024, 3:18 p.m. UTC | #2
On Fri, Dec 20, 2024 at 07:03:23AM -0800, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > -if get_option('tests')
> > +if get_option('tests') or get_option('gitweb').enabled()
> >    perl_required = true
> >  endif
> 
> OK, so we use "perl_required" to keep track of the fact that
> something else wants Perl to be usable.
> 
> > +# Gitweb requires Perl, so we disable the auto-feature if Perl was not found.
> > +# We make sure further up that Perl is required in case the gitweb option is
> > +# enabled.
> > +gitweb_option = get_option('gitweb').disable_auto_if(not perl.found())
> 
> Hopefully before we reach this point, we would have figured out if
> perl is avialable, to allow us do this.

Yup.

> There seem to be too many "perl" related variables, interaction
> among which smells way too complex for their worth.  For example,
> 
>     perl = find_program('perl', ..., required: perl_required);
>     perl_features_enabled = perl.found() and get_option('perl').allowed()
> 
> and only when the latter is true, we'd do further configuration to
> make perl usable.  Does that mean the condition you wrote above to
> automatically disable gitweb somewhat incorrect?  Even if we may
> have found perl, the builder may deliberately have disallowed use of
> it, in which case we just know perl is there without figuring out
> what other things (like where the localedir is) that are needed to
> use it correctly.

I don't think it's incorrect. The Perl features are those that the Git
distribution itself uses, including all the Perl modules in "perl/". The
gitweb subsystem, as far as I can see, uses none of those functions and
thus the data we configure in case `perl_features_enabled` is true is
irrelevant for gitweb.

Now I don't disagree with your statement that there are too many
Perl-related variables, but it simply reflects the fact that Git uses it
for multiple different things: testing, git-instaweb, the Perl library,
several Perl-based commands and gitweb. And I think it's not entirely
unreasonable to let users configure these independently of one another,
and that brings some complexity with it.

That being said I'd also be okay to not introduce the separate "gitweb"
option and instead just use the existing "perl" option for it. I don't
mind it all that much.

> > +option('gitweb', type: 'feature', value: 'auto',
> > +  description: 'Build Git web interface. Required Perl.')
> 
> I do not know the convention in the meson world, but to me, this
> would sound more natural with "Required" -> "Requires".

Oh, yes, indeed. I'll wait a bit for your opinion on the above before
sending a simple typo fix for this.

Patrick
Junio C Hamano Dec. 20, 2024, 3:50 p.m. UTC | #3
Patrick Steinhardt <ps@pks.im> writes:

> I don't think it's incorrect. The Perl features are those that the Git
> distribution itself uses, including all the Perl modules in "perl/". The
> gitweb subsystem, as far as I can see, uses none of those functions and
> thus the data we configure in case `perl_features_enabled` is true is
> irrelevant for gitweb.

Ah, now that makes sense to me why these things are laid out that
way.  Thanks.
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 0dccebcdf16b07650d943e53643f0e09e2975cc9..8e34a895dca80da77d6809a6fe90fe7661f142a1 100644
--- a/meson.build
+++ b/meson.build
@@ -740,7 +740,7 @@  endif
 # features. It is optional if you want to neither execute tests nor use any of
 # these optional features.
 perl_required = get_option('perl')
-if get_option('tests')
+if get_option('tests') or get_option('gitweb').enabled()
   perl_required = true
 endif
 
@@ -1874,7 +1874,15 @@  if intl.found()
   subdir('po')
 endif
 subdir('contrib')
-subdir('gitweb')
+
+# Gitweb requires Perl, so we disable the auto-feature if Perl was not found.
+# We make sure further up that Perl is required in case the gitweb option is
+# enabled.
+gitweb_option = get_option('gitweb').disable_auto_if(not perl.found())
+if gitweb_option.enabled()
+  subdir('gitweb')
+endif
+
 subdir('templates')
 
 # Everything but the bin-wrappers need to come before this target such that we
@@ -1893,6 +1901,7 @@  summary({
   'curl': curl.found(),
   'expat': expat.found(),
   'gettext': intl.found(),
+  'gitweb': gitweb_option.enabled(),
   'https': https_backend,
   'iconv': iconv.found(),
   'pcre2': pcre2.found(),
diff --git a/meson_options.txt b/meson_options.txt
index 32a72139bae870745d9131cc9086a4594826be91..1b38d9b716ee2d06ac1484a744529547f7ed4acd 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -23,6 +23,8 @@  option('expat', type: 'feature', value: 'enabled',
   description: 'Build helpers used to push to remotes with the HTTP transport.')
 option('gettext', type: 'feature', value: 'auto',
   description: 'Build translation files.')
+option('gitweb', type: 'feature', value: 'auto',
+  description: 'Build Git web interface. Required Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
 option('pcre2', type: 'feature', value: 'enabled',