Skip to content

Commit 2c33712

Browse files
author
Dylan Hardison
committed
Bug 1246528 - Use Makefile.PL and allow Bugzilla use cpanm-compatible local dependencies
r=dkl,a=dylan
1 parent a8adffb commit 2c33712

110 files changed

Lines changed: 1082 additions & 1600 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**/.htaccess
22
/lib/*
3+
/local/*
34
/template/en/custom
45
/docs/en/rst/extensions/*
56
/docs/en/rst/api/extensions/*
@@ -12,6 +13,10 @@
1213
/localconfig
1314
/cpanfile
1415
/index.html
16+
/Makefile
17+
/MYMETA.*
18+
/pm_to_blib
19+
/blib
1520

1621
/skins/contrib/Dusk/admin.css
1722
/skins/contrib/Dusk/bug.css

Bugzilla.pm

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use Bugzilla::Extension;
3434
use Bugzilla::Field;
3535
use Bugzilla::Flag;
3636
use Bugzilla::Install::Localconfig qw(read_localconfig);
37-
use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES have_vers);
3837
use Bugzilla::Install::Util qw(init_console include_languages i_am_persistent);
3938
use Bugzilla::Memcached;
4039
use Bugzilla::Template;
@@ -47,6 +46,7 @@ use File::Spec::Functions;
4746
use DateTime::TimeZone;
4847
use Date::Parse;
4948
use Safe;
49+
use List::Util qw(first);
5050

5151
#####################################################################
5252
# Constants
@@ -245,32 +245,66 @@ sub api_server {
245245
return $cache->{api_server};
246246
}
247247

248+
use constant _CAN_HAS_FEATURE => eval {
249+
require CPAN::Meta;
250+
require Module::Runtime;
251+
require CPAN::Meta::Check;
252+
Module::Runtime->import(qw(require_module));
253+
CPAN::Meta::Check->import(qw(verify_dependencies));
254+
1;
255+
};
256+
248257
sub feature {
249-
my ($class, $feature) = @_;
258+
my ($class, $feature_name) = @_;
259+
return 0 unless _CAN_HAS_FEATURE;
260+
return unless $class->has_feature($feature_name);
261+
262+
my $cache = $class->request_cache;
263+
my $feature = $cache->{feature_map}{$feature_name};
264+
# Bugzilla expects this will also load all the modules.. so we have to do that.
265+
# Later we should put a deprecation warning here, and favor calling has_feature().
266+
267+
return 1 if $cache->{feature_loaded}{$feature_name};
268+
my @modules = $feature->requirements_for('runtime', 'requires')->required_modules;
269+
require_module($_) foreach @modules;
270+
$cache->{feature_loaded}{$feature_name} = 1;
271+
return 1;
272+
}
273+
274+
sub has_feature {
275+
my ($class, $feature_name) = @_;
276+
277+
return 0 unless _CAN_HAS_FEATURE;
278+
250279
my $cache = $class->request_cache;
251-
return $cache->{feature}->{$feature}
252-
if exists $cache->{feature}->{$feature};
253-
254-
my $feature_map = $cache->{feature_map};
255-
if (!$feature_map) {
256-
foreach my $package (@{ OPTIONAL_MODULES() }) {
257-
foreach my $f (@{ $package->{feature} }) {
258-
$feature_map->{$f} ||= [];
259-
push(@{ $feature_map->{$f} }, $package);
280+
return $cache->{feature}->{$feature_name}
281+
if exists $cache->{feature}->{$feature_name};
282+
283+
my $dir = bz_locations()->{libpath};
284+
my $feature_map = $cache->{feature_map} //= do {
285+
my @meta_json = map { File::Spec->catfile($dir, $_) } qw( MYMETA.json META.json );
286+
my $file = first { -f $_ } @meta_json;
287+
my %map;
288+
if ($file) {
289+
open my $meta_fh, '<', $file or die "unable to open $file: $!";
290+
my $str = do { local $/ = undef; scalar <$meta_fh> };
291+
trick_taint($str);
292+
close $meta_fh;
293+
294+
my $meta = CPAN::Meta->load_json_string($str);
295+
296+
foreach my $feature ($meta->features) {
297+
$map{$feature->identifier} = $feature->prereqs;
260298
}
261299
}
262-
$cache->{feature_map} = $feature_map;
263-
}
264300

265-
if (!$feature_map->{$feature}) {
266-
ThrowCodeError('invalid_feature', { feature => $feature });
267-
}
301+
\%map;
302+
};
268303

269-
my $success = 1;
270-
foreach my $package (@{ $feature_map->{$feature} }) {
271-
have_vers($package) or $success = 0;
272-
}
273-
$cache->{feature}->{$feature} = $success;
304+
ThrowCodeError('invalid_feature', { feature => $feature_name }) if !$feature_map->{$feature_name};
305+
my $success = !verify_dependencies($feature_map->{$feature_name}, 'runtime', 'requires');
306+
307+
$cache->{feature}{$feature_name} = $success;
274308
return $success;
275309
}
276310

@@ -1015,8 +1049,12 @@ this Bugzilla installation.
10151049
10161050
=item C<feature>
10171051
1018-
Tells you whether or not a specific feature is enabled. For names
1019-
of features, see C<OPTIONAL_MODULES> in C<Bugzilla::Install::Requirements>.
1052+
Wrapper around C<has_feature()> that also loads all of required modules into the runtime.
1053+
1054+
=item C<has_feature>
1055+
1056+
Consults F<MYMETA.yml> for optional Bugzilla features and returns true if all the requirements
1057+
are installed.
10201058
10211059
=item C<api_server>
10221060

Bugzilla/API/1_0/Server.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use Bugzilla::Hook;
2020
use Bugzilla::Util qw(datetime_from trick_taint);
2121

2222
use File::Basename qw(basename);
23-
use File::Glob qw(:bsd_glob);
23+
use File::Glob qw(:glob);
2424
use List::MoreUtils qw(none uniq);
2525
use MIME::Base64 qw(decode_base64 encode_base64);
2626
use Moo;

Bugzilla/Constants.pm

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -516,41 +516,11 @@ use constant INSTALLATION_MODE_NON_INTERACTIVE => 1;
516516
# Data about what we require for different databases.
517517
use constant DB_MODULE => {
518518
# MySQL 5.0.15 was the first production 5.0.x release.
519-
'mysql' => {db => 'Bugzilla::DB::Mysql', db_version => '5.0.15',
520-
dbd => {
521-
package => 'DBD-mysql',
522-
module => 'DBD::mysql',
523-
# Disallow development versions
524-
blacklist => ['_'],
525-
# For UTF-8 support. 4.001 makes sure that blobs aren't
526-
# marked as UTF-8.
527-
version => '4.001',
528-
},
529-
name => 'MySQL'},
530-
'pg' => {db => 'Bugzilla::DB::Pg', db_version => '9.00.0000',
531-
dbd => {
532-
package => 'DBD-Pg',
533-
module => 'DBD::Pg',
534-
# Pg 9.2 requires 2.19.3 as spclocation no longer exists.
535-
version => '2.19.3',
536-
},
537-
name => 'PostgreSQL'},
538-
'oracle'=> {db => 'Bugzilla::DB::Oracle', db_version => '10.02.0',
539-
dbd => {
540-
package => 'DBD-Oracle',
541-
module => 'DBD::Oracle',
542-
version => '1.19',
543-
},
544-
name => 'Oracle'},
545-
# SQLite 3.6.22 fixes a WHERE clause problem that may affect us.
546-
sqlite => {db => 'Bugzilla::DB::Sqlite', db_version => '3.6.22',
547-
dbd => {
548-
package => 'DBD-SQLite',
549-
module => 'DBD::SQLite',
550-
# 1.29 is the version that contains 3.6.22.
551-
version => '1.29',
552-
},
553-
name => 'SQLite'},
519+
mysql => { db => 'Bugzilla::DB::Mysql', db_version => '5.0.15', name => 'MySQL'},
520+
pg => { db => 'Bugzilla::DB::Pg', db_version => '9.00.0000', name => 'PostgreSQL'},
521+
oracle => { db => 'Bugzilla::DB::Oracle', db_version => '10.02.0', name => 'Oracle'},
522+
# SQLite 3.6.22 fixes a WHERE clause problem that may affect us.
523+
sqlite => { db => 'Bugzilla::DB::Sqlite', db_version => '3.6.22', name => 'SQLite'},
554524
};
555525

556526
# True if we're on Win32.

Bugzilla/DB.pm

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ sub bz_check_requirements {
165165
. bz_locations()->{'localconfig'};
166166
}
167167

168-
# Check the existence and version of the DBD that we need.
169-
my $dbd = $db->{dbd};
170-
_bz_check_dbd($db, $output);
171-
172168
# We don't try to connect to the actual database if $db_check is
173169
# disabled.
174170
unless ($lc->{db_check}) {
@@ -183,27 +179,6 @@ sub bz_check_requirements {
183179
print "\n" if $output;
184180
}
185181

186-
sub _bz_check_dbd {
187-
my ($db, $output) = @_;
188-
189-
my $dbd = $db->{dbd};
190-
unless (have_vers($dbd, $output)) {
191-
my $sql_server = $db->{name};
192-
my $command = install_command($dbd);
193-
my $root = ROOT_USER;
194-
my $dbd_mod = $dbd->{module};
195-
my $dbd_ver = $dbd->{version};
196-
die <<EOT;
197-
198-
For $sql_server, Bugzilla requires that perl's $dbd_mod $dbd_ver or later be
199-
installed. To install this module, run the following command (as $root):
200-
201-
$command
202-
203-
EOT
204-
}
205-
}
206-
207182
sub bz_check_server_version {
208183
my ($self, $db, $output) = @_;
209184

0 commit comments

Comments
 (0)