File Coverage

alienfile
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1 1     1   268679 use alienfile;
  1         2  
  1         6  
2 1     1   139 use Config;
  1         2  
  1         993  
3              
4             configure { requires 'Alien::Build' => '2.37' };
5              
6             my $test_program = <<'EOF';
7             #include <stdio.h>
8             #include <libxml/xmlversion.h>
9             #include <libxml/parser.h>
10             #include <libxml/tree.h>
11              
12             int
13             main(int argc, char *argv[])
14             {
15             xmlDoc *doc = NULL;
16             /*
17             * xmlRead should fail, but having this call ensures
18             * that the we have access to the symbols in -lxml2
19             * (LIBXML_DOTTED_VERSION below is in the header file)
20             */
21             doc = xmlReadFile("foo.xml", NULL, 0);
22             printf("xml version = '%s'\n", LIBXML_DOTTED_VERSION);
23             }
24             EOF
25              
26             my @try_flags = (
27             { cflags => '', libs => '-lxml2' },
28             { cflags => '-I/usr/include/libxml2', libs => '-lxml2' },
29             { cflags => '-I/usr/local/include/libxml2', libs => '-lxml2' },
30             );
31              
32             plugin 'Probe::Vcpkg' => 'libxml2';
33              
34             probe [
35             ['xml2-config', '--version' => \'%{.install.my_version}'],
36             ['xml2-config', '--cflags' => \'%{.install.my_cflags}'],
37             ['xml2-config', '--libs' => \'%{.install.my_libs}'],
38             ];
39              
40             plugin 'PkgConfig' => 'libxml-2.0';
41              
42             plugin 'Probe::CBuilder' => (
43             cflags => $_->{cflags},
44             libs => $_->{libs},
45             program => $test_program,
46             version => qr{xml version = '(.*?)'},
47             ) for @try_flags;
48             plugin 'PkgConfig::MakeStatic' => ();
49              
50             my %bad_versions = map { $_ => 1 } (
51             # known bad versions
52             # may have some extras, and may be incomplete.
53             # but probably sufficient.
54             # computed using maint/tags-to-versions.pl and the git repository
55             # for libxml2.
56             '2.0.0',
57             '2.1.0','2.1.1',
58             '2.2.0','2.2.1','2.2.2','2.2.3','2.2.4','2.2.5','2.2.6','2.2.7','2.2.8',
59             '2.3.0','2.3.1','2.3.2','2.3.3','2.3.4','2.3.5','2.3.6','2.3.7','2.3.8','2.3.9','2.3.10','2.3.11','2.3.12','2.3.13','2.3.14',
60             '2.4.0','2.4.1','2.4.2','2.4.3','2.4.4','2.4.5','2.4.6','2.4.7','2.4.8','2.4.9','2.4.10','2.4.11','2.4.12','2.4.13','2.4.14','2.4.15','2.4.16','2.4.17','2.4.18','2.4.19','2.4.20','2.4.21','2.4.22','2.4.23','2.4.24','2.4.25','2.4.26','2.4.27','2.4.28','2.4.29','2.4.30',
61             '2.5.0','2.5.1','2.5.2','2.5.3','2.5.4','2.5.5','2.5.6','2.5.7','2.5.8','2.5.9','2.5.10','2.5.11',
62             '2.6.0','2.6.1','2.6.2','2.6.3','2.6.4','2.6.5','2.6.6','2.6.7','2.6.8','2.6.9','2.6.10','2.6.11','2.6.12','2.6.13','2.6.14','2.6.15','2.6.19','2.6.20','2.6.25',
63             '2.7.0','2.7.1',
64             '2.9.4',
65             # The next set have reported CVEs
66             (map {'2.11.' . $_} (0 .. 9)),
67             (map {'2.12.' . $_} (0 .. 9)),
68             (map {'2.13.' . $_} (0 .. 6)),
69             );
70              
71             meta->around_hook(
72             probe => sub {
73             my $orig = shift;
74             my $build = shift;
75             my $install_type = $orig->($build, @_);
76             # if the system type is install, make sure the version isn't on the
77             # blacklist.
78             # Honor $ENV{FORCE} used in the Makefile.PL for XML-LibXML to allow
79             # versions on the blacklist.
80             if($install_type eq 'system' && !$ENV{FORCE})
81             {
82             # the first is provided by Probe::CBuilder, or pkg-config plugins for AB >= 1.61
83             # the second is generated by the Probe::CBuilder plugin since forever (or thereabouts)
84             # the thirds is from this alienfile, (see above with the xml2-config probe).
85             my $version = $build->hook_prop->{version} ||
86             $build->install_prop->{plugin_probe_cbuilder_gather}->{version} ||
87             $build->install_prop->{my_version};
88              
89             $version =~ s/-.*$//g;
90              
91             unless(defined $version)
92             {
93             print STDERR "Unfortunately, Alien::Libxml2 requires the version from the system libxml2 in\n",
94             "order to determine if it is acceptible for use, but Alien::Build prior to 1.61\n",
95             "did not provide this information in the probe step. Alien::Libxml2 can still\n",
96             "find the system libxml2 on systems with xml2-config in the PATH, or if libxml2\n",
97             "is available from one of the commonly known locations. If you want to detect\n",
98             "the system libxml2 with a .pc file via pkg-config, then please upgrade\n",
99             "Alien::Build to 1.61 or better\n";
100             return 'share';
101             }
102              
103             if($bad_versions{$version})
104             {
105             print STDERR "Alien::Libxml2 is designed to work with XML::LibXML.\n\n".
106             "The installed system version of libxml2 $version is not compatible with XML::LibXML (and probably buggy)!\n\n".
107             " - don't expect XML::LibXML to build or work correctly with this version of libxml2!\n" .
108             " - don't report errors with this version of libxml2!\n" .
109             " - don't send patches for this version of libxml2!\n\n";
110             if($version eq '2.9.4')
111             {
112             print STDERR "XML::LibXML typically attempts to install with this version anyway, so will we.\n";
113             }
114             else
115             {
116             print STDERR "XML::LibXML typcially refuses to install with this version unless forced, so we will\n";
117             print STDERR "attempt to download a newer version from the internet. If you prefer you can force\n";
118             print STDERR "Alien::Libxml2 to install with this possibly buggy version using:\n";
119             print STDERR "env FORCE=1 perl Makefile.PL\n";
120             print STDERR "or\n";
121             print STDERR "env FORCE=1 cpanm Alien::Libxml2\n";
122             return 'share';
123             }
124             }
125             }
126             $install_type;
127             },
128             );
129              
130             plugin 'Prefer::BadVersion' => [ keys %bad_versions ];
131              
132             share {
133              
134             # out of source build is borked on Windows, so we turn it
135             # off there. Turn it on elsewhere as it saves a copy.
136             meta->prop->{out_of_source} = $^O eq 'MSWin32' ? 0 : 1;
137              
138             plugin 'Download::GitLab' => (
139             gitlab_host => 'https://gitlab.gnome.org',
140             gitlab_user => 'GNOME',
141             gitlab_project => 'libxml2',
142             type => 'link',
143             format => 'tar.xz',
144             version_from => 'tag_name',
145             convert_version => sub {
146             my $version = shift;
147             $version =~ s/^v//;
148             $version;
149             },
150             );
151              
152             if($^O eq 'MSWin32' && $Config{ccname} eq 'cl')
153             {
154             build [
155             sub { shift->install_prop->{prefix} =~ s/\//\\/g;},
156             'cd win32',
157             'cscript configure.js prefix=%{.install.prefix} iconv=no compiler=msvc static=yes',
158             'nmake -f Makefile.msvc',
159             'nmake -f Makefile.msvc install',
160             ];
161              
162             plugin 'Gather::IsolateDynamic';
163              
164             gather sub {
165             my($build) = @_;
166             my $prefix = $build->runtime_prop->{prefix};
167             $build->runtime_prop->{cflags} = "-I$prefix/include/libxml2";
168             $build->runtime_prop->{libs} = "-L$prefix/lib libxml2_a.lib";
169             };
170             }
171             else
172             {
173             plugin 'Build::Autoconf' => ();
174              
175             build [
176             '%{configure} --prefix=%{.install.autoconf_prefix} --without-python --disable-shared --enable-static',
177             '%{make}',
178             '%{make} install',
179             ];
180              
181             plugin 'PkgConfig::MakeStatic' => ();
182             }
183              
184             };
185              
186             sys {
187              
188             meta->after_hook(
189             gather_system => sub {
190             my($build) = @_;
191             return if defined $build->runtime_prop->{libs};
192             if($build->install_prop->{my_libs})
193             {
194             $build->runtime_prop->{$_} = $build->install_prop->{"my_$_"} for qw( version cflags libs );
195             }
196             },
197             );
198              
199             };