Skip to content

Commit 1aca69c

Browse files
avargitster
authored andcommitted
perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS
Before my 20d2a30 ("Makefile: replace perl/Makefile.PL with simple make rules", 2017-12-10) on an OS package that removed the private-Error.pm copy we carried around manually removing the OS's Error.pm would yield: $ git add -p Can't locate Error.pm in @inc (you may need to install the Error module) [...] Now, before this change we'll instead emit this more cryptic error: $ git add -p BUG: '/usr/share/perl5/Git/FromCPAN' should be a directory! at /usr/share/perl5/Git/Error.pm line 36. This is a confusing error. Now if the new NO_PERL_CPAN_FALLBACKS option is specified and we can't find the module we'll instead emit: $ /tmp/git/bin/git add -p BUG: The 'Error' module is not here, but NO_PERL_CPAN_FALLBACKS was set! [...] Where [...] is the lengthy explanation seen in the change below, which explains what the potential breakage is, and how to fix it. The reason for checking @@NO_PERL_CPAN_FALLBACKS@@] against the empty string in Perl is as opposed to checking for a boolean value is that that's (as far as I can tell) make's idea of a string that's set, and e.g. NO_PERL_CPAN_FALLBACKS=0 is enough to set NO_PERL_CPAN_FALLBACKS. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 075321c commit 1aca69c

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

INSTALL

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ Issues of note:
8888
export GIT_EXEC_PATH PATH GITPERLLIB
8989

9090
- By default (unless NO_PERL is provided) Git will ship various perl
91-
scripts & libraries it needs. However, for simplicity it doesn't
92-
use the ExtUtils::MakeMaker toolchain to decide where to place the
93-
perl libraries. Depending on the system this can result in the perl
91+
scripts. However, for simplicity it doesn't use the
92+
ExtUtils::MakeMaker toolchain to decide where to place the perl
93+
libraries. Depending on the system this can result in the perl
9494
libraries not being where you'd like them if they're expected to be
9595
used by things other than Git itself.
9696

@@ -102,6 +102,11 @@ Issues of note:
102102
Will result in e.g. perllibdir=/usr/share/perl/5.26.1 on Debian,
103103
perllibdir=/usr/share/perl5 (which we'd use by default) on CentOS.
104104

105+
- Unless NO_PERL is provided Git will ship various perl libraries it
106+
needs. Distributors of Git will usually want to set
107+
NO_PERL_CPAN_FALLBACKS if NO_PERL is not provided to use their own
108+
copies of the CPAN modules Git needs.
109+
105110
- Git is reasonably self-sufficient, but does depend on a few external
106111
programs and libraries. Git can be used without most of them by adding
107112
the approriate "NO_<LIBRARY>=YesPlease" to the make command line or

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,11 +2314,14 @@ all:: $(LIB_PERL_GEN)
23142314
ifndef NO_PERL_CPAN_FALLBACKS
23152315
all:: $(LIB_CPAN_GEN)
23162316
endif
2317+
NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS))
23172318
endif
23182319

23192320
perl/build/lib/%.pm: perl/%.pm
23202321
$(QUIET_GEN)mkdir -p $(dir $@) && \
2321-
sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@
2322+
sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
2323+
-e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
2324+
< $< > $@
23222325

23232326
perl/build/man/man3/Git.3pm: perl/Git.pm
23242327
$(QUIET_GEN)mkdir -p $(dir $@) && \

perl/Git/LoadCPAN.pm

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ attempt to load C<Module::Name> from the OS, and if that doesn't work
1919
will fall back on C<FromCPAN::Module::Name> shipped with Git itself.
2020
2121
Usually distributors will not ship with Git's Git::FromCPAN tree at
22-
all, preferring to use their own packaging of CPAN modules instead.
22+
all via the C<NO_PERL_CPAN_FALLBACKS> option, preferring to use their
23+
own packaging of CPAN modules instead.
2324
2425
This module is only intended to be used for code shipping in the
2526
C<git.git> repository. Use it for anything else at your peril!
2627
2728
=cut
2829

30+
# NO_PERL_CPAN_FALLBACKS_STR evades the sed search-replace from the
31+
# Makefile, and allows for detecting whether the module is loaded from
32+
# perl/Git as opposed to perl/build/Git, which is useful for one-off
33+
# testing without having Error.pm et al installed.
34+
use constant NO_PERL_CPAN_FALLBACKS_STR => '@@' . 'NO_PERL_CPAN_FALLBACKS' . '@@';
35+
use constant NO_PERL_CPAN_FALLBACKS => (
36+
q[@@NO_PERL_CPAN_FALLBACKS@@] ne ''
37+
and
38+
q[@@NO_PERL_CPAN_FALLBACKS@@] ne NO_PERL_CPAN_FALLBACKS_STR
39+
);
40+
2941
sub import {
3042
shift;
3143
my $caller = caller;
@@ -45,6 +57,25 @@ sub import {
4557
} or do {
4658
my $error = $@ || "Zombie Error";
4759

60+
if (NO_PERL_CPAN_FALLBACKS) {
61+
chomp(my $error = sprintf <<'THEY_PROMISED', $module);
62+
BUG: The '%s' module is not here, but NO_PERL_CPAN_FALLBACKS was set!
63+
64+
Git needs this Perl module from the CPAN, and will by default ship
65+
with a copy of it. This Git was built with NO_PERL_CPAN_FALLBACKS,
66+
meaning that whoever built it promised to provide this module.
67+
68+
You're seeing this error because they broke that promise, and we can't
69+
load our fallback version, since we were asked not to install it.
70+
71+
If you're seeing this error and didn't package Git yourself the
72+
package you're using is broken, or your system is broken. This error
73+
won't appear if Git is built without NO_PERL_CPAN_FALLBACKS (instead
74+
we'll use our fallback version of the module).
75+
THEY_PROMISED
76+
die $error;
77+
}
78+
4879
my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
4980

5081
require File::Basename;

0 commit comments

Comments
 (0)