]>
Dogcows Code - chaz/graphql-client/blob - maint/fatpack.pl
66497fa281971e51603c81d596f0c462e538e8fa
5 maint/fatpack.pl - Generate a fatpack version of graphql
9 maint/fatpack.pl --dist-dir DIRPATH [--clean]
18 use Capture
::Tiny
qw(capture_stdout);
26 my $core_version = '5.010001';
27 my $plenv_version = '5.10.1';
28 my %blacklist_modules = map { $_ => 1 } (
30 'Text::Table::ASV', # brought in by Text::Table::Any but not actually required
31 'Unicode::GCString', # optional XS module
34 'Proc::Find::Parents', # used by Term::Detect::Software on some platforms
41 'dist=s' => \
$distdir,
42 ) or die "Invalid options.\n";
43 $distdir && -d
$distdir or die "Use --dist to specify path to a distribution directory.\n";
45 my $mcpan = MetaCPAN
::API-
>new;
47 run
($distdir, $clean);
51 my $path = path
(shift);
53 run_command
('cpanm', '-n', "-L$path", @modules);
57 my $distdir = path
(shift);
60 my $builddir = path
('.build');
61 my $fatlibdir = path
('fatlib');
64 print STDERR
"Cleaning...\n";
65 $builddir->remove_tree({safe
=> 0});
66 $fatlibdir->remove_tree({safe
=> 0});
71 my @modules = required_modules
($distdir, $builddir->child('deps.txt'));
72 install_modules
($builddir->child('local'), @modules);
73 pack_modules
($builddir->child('local'), @modules);
75 clean_fatlib
($fatlibdir);
77 # consolidate all modules into a new directory for packing
78 my $moduledir = $builddir->child('modules');
79 $moduledir->remove_tree({safe
=> 0});
81 system(qw{cp -r}, $fatlibdir, $distdir->child('lib'), "$moduledir/");
83 $moduledir->child('fatlib/Test')->remove_tree({safe
=> 0}); # don't need Test:: modules
86 my $cd_builddir = pushd
($moduledir);
88 system('perlstrip', '--cache', '-v', find_modules
('.'));
92 generate_script
($distdir->child('bin/graphql'), $fatpack, 'graphql');
95 sub required_modules
{
96 my $path = path
(shift);
97 my $cache_filepath = shift;
99 print STDERR
"Determining required modules...\n";
101 my $cachefile = $cache_filepath && path
($cache_filepath);
102 if (my $contents = eval { $cachefile->slurp_utf8 }) {
104 return split(/\n/, $contents);
107 my $meta = CPAN
::Meta-
>load_file($path->child('META.json'));
109 my $requires = CPAN
::Meta
::Requirements-
>new;
111 for my $type (qw{requires recommends suggests}) {
112 my $reqs = $meta->effective_prereqs->requirements_for('runtime', $type);
113 for my $module ($reqs->required_modules) {
114 next if $blacklist_modules{$module};
116 my $core = $Module::CoreList
::version
{$core_version}{$module};
117 print STDERR
"skipping core: $module $core\n" if $core;
118 next if $core && $reqs->accepts_module($module, $core);
120 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
121 dependencies_for_module
($requires, $module);
124 $requires->clear_requirement($_) for qw(Module::CoreList ExtUtils::MakeMaker Carp);
125 my @deps = $requires->required_modules;
127 push @deps, @extra_modules;
129 $cachefile->spew_utf8([map { "$_\n" } @deps]) if $cachefile;
134 sub dependencies_for_dist
{
135 my $requires = shift;
139 return if $dists{$name}++;
140 print STDERR
"Finding dependencies for dist $name\n";
142 my $dist = $mcpan->release(distribution
=> $name);
144 my $reqs = CPAN
::Meta
::Requirements-
>new;
146 foreach my $dep (@{$dist->{dependency
}}) {
147 next if $dep->{phase
} ne 'runtime';
148 next if $dep->{relationship
} ne 'requires'; # && $dep->{relationship} ne 'recommends';
150 my $module = $dep->{module
};
151 next if $blacklist_modules{$module};
153 $reqs->add_minimum($dep->{module
} => $dep->{version
});
154 my $core = $Module::CoreList
::version
{$core_version}{$module};
155 print STDERR
"skipping core: $module $core\n" if $core;
156 next if $core && $reqs->accepts_module($module, $core);
158 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
159 dependencies_for_module
($requires, $dep->{module
});
163 sub dependencies_for_module
{
164 my $requires = shift;
168 return if $modules{$name}++;
169 print STDERR
"Finding dependencies for module $name\n";
171 my $module = $mcpan->module($name);
172 dependencies_for_dist
($requires, $module->{distribution
});
176 my $path = path
(shift);
177 $path->child($Config{archname
})->remove_tree({safe
=> 0});
178 $path->child('POD2')->remove_tree({safe
=> 0});
181 if (/\.p(od|l)$/ || /\.sample$/) {
189 my $path = path
(shift);
193 push @pm_filepaths, $_ if /\.pm$/;
195 return @pm_filepaths;
199 my ($path, @modules) = @_;
201 my @filepaths = map { my $s = $_; $s =~ s!::!/!g; "$s.pm" } @modules;
203 my $stdout = capture_stdout
{
204 local $ENV{PERL5LIB
} = $path->child('lib/perl5')->absolute;
205 system('fatpack', 'packlists-for', @filepaths);
208 my @packlists = split(/\n/, $stdout);
209 for my $packlist (@packlists) {
210 warn "Packing $packlist\n";
213 system('fatpack', 'tree', map { path
($_)->absolute } @packlists);
216 sub generate_script
{
217 my ($input_filepath, $fatpack, $output_filepath) = @_;
219 open(my $in, '<', $input_filepath) or die "open failed: $!";
220 open(my $out, '>', "$output_filepath.tmp") or die "open failed: $!";
223 s
|^#!\h*perl|#!/usr/bin/env perl|;
224 s
|^# FATPACK.*|$fatpack|;
228 unlink($output_filepath);
229 rename("$output_filepath.tmp", $output_filepath);
231 path
($output_filepath)->chmod(0755);
233 print STDERR
"Wrote fatpacked script: $output_filepath\n";
237 local $ENV{PLENV_VERSION
} = $plenv_version;
238 system('plenv', 'exec', @_);
This page took 0.049579 seconds and 3 git commands to generate.