]>
Dogcows Code - chaz/graphql-client/blob - maint/fatpack.pl
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
32 'JSON::Path::Evaluator', # requires perl 5.16
35 'Proc::Find::Parents', # used by Term::Detect::Software on some platforms
42 'dist=s' => \
$distdir,
43 ) or die "Invalid options.\n";
44 $distdir && -d
$distdir or die "Use --dist to specify path to a distribution directory.\n";
46 my $mcpan = MetaCPAN
::API-
>new;
48 run
($distdir, $clean);
52 my $path = path
(shift);
54 run_command
('cpanm', '-n', "-L$path", @modules);
58 my $distdir = path
(shift);
61 my $builddir = path
('.build');
62 my $fatlibdir = path
('fatlib');
65 print STDERR
"Cleaning...\n";
66 $builddir->remove_tree({safe
=> 0});
67 $fatlibdir->remove_tree({safe
=> 0});
72 my @modules = required_modules
($distdir, $builddir->child('deps.txt'));
73 install_modules
($builddir->child('local'), @modules);
74 pack_modules
($builddir->child('local'), @modules);
76 clean_fatlib
($fatlibdir);
78 # consolidate all modules into a new directory for packing
79 my $moduledir = $builddir->child('modules');
80 $moduledir->remove_tree({safe
=> 0});
82 system(qw{cp -r}, $fatlibdir, $distdir->child('lib'), "$moduledir/");
84 $moduledir->child('fatlib/Test')->remove_tree({safe
=> 0}); # don't need Test:: modules
87 my $cd_builddir = pushd
($moduledir);
89 system('perlstrip', '--cache', '-v', find_modules
('.'));
93 generate_script
($distdir->child('bin/graphql'), $fatpack, 'graphql');
96 sub required_modules
{
97 my $path = path
(shift);
98 my $cache_filepath = shift;
100 print STDERR
"Determining required modules...\n";
102 my $cachefile = $cache_filepath && path
($cache_filepath);
103 if (my $contents = eval { $cachefile->slurp_utf8 }) {
105 return split(/\n/, $contents);
108 my $meta = CPAN
::Meta-
>load_file($path->child('META.json'));
110 my $requires = CPAN
::Meta
::Requirements-
>new;
112 for my $type (qw{requires recommends suggests}) {
113 my $reqs = $meta->effective_prereqs->requirements_for('runtime', $type);
114 for my $module ($reqs->required_modules) {
115 next if $blacklist_modules{$module};
117 my $core = $Module::CoreList
::version
{$core_version}{$module};
118 print STDERR
"skipping core: $module $core\n" if $core;
119 next if $core && $reqs->accepts_module($module, $core);
121 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
122 dependencies_for_module
($requires, $module);
125 $requires->clear_requirement($_) for qw(Module::CoreList ExtUtils::MakeMaker Carp);
126 my @deps = $requires->required_modules;
128 push @deps, @extra_modules;
130 $cachefile->spew_utf8([map { "$_\n" } @deps]) if $cachefile;
135 sub dependencies_for_dist
{
136 my $requires = shift;
140 return if $dists{$name}++;
141 print STDERR
"Finding dependencies for dist $name\n";
143 my $dist = $mcpan->release(distribution
=> $name);
145 my $reqs = CPAN
::Meta
::Requirements-
>new;
147 foreach my $dep (@{$dist->{dependency
}}) {
148 next if $dep->{phase
} ne 'runtime';
149 next if $dep->{relationship
} ne 'requires'; # && $dep->{relationship} ne 'recommends';
151 my $module = $dep->{module
};
152 next if $blacklist_modules{$module};
154 $reqs->add_minimum($dep->{module
} => $dep->{version
});
155 my $core = $Module::CoreList
::version
{$core_version}{$module};
156 print STDERR
"skipping core: $module $core\n" if $core;
157 next if $core && $reqs->accepts_module($module, $core);
159 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
160 dependencies_for_module
($requires, $dep->{module
});
164 sub dependencies_for_module
{
165 my $requires = shift;
169 return if $modules{$name}++;
170 print STDERR
"Finding dependencies for module $name\n";
172 my $module = $mcpan->module($name);
173 dependencies_for_dist
($requires, $module->{distribution
});
177 my $path = path
(shift);
178 $path->child($Config{archname
})->remove_tree({safe
=> 0});
179 $path->child('POD2')->remove_tree({safe
=> 0});
182 if (/\.p(od|l)$/ || /\.sample$/) {
190 my $path = path
(shift);
194 push @pm_filepaths, $_ if /\.pm$/;
196 return @pm_filepaths;
200 my ($path, @modules) = @_;
202 my @filepaths = map { my $s = $_; $s =~ s!::!/!g; "$s.pm" } @modules;
204 my $stdout = capture_stdout
{
205 local $ENV{PERL5LIB
} = $path->child('lib/perl5')->absolute;
206 system('fatpack', 'packlists-for', @filepaths);
209 my @packlists = split(/\n/, $stdout);
210 for my $packlist (@packlists) {
211 warn "Packing $packlist\n";
214 system('fatpack', 'tree', map { path
($_)->absolute } @packlists);
217 sub generate_script
{
218 my ($input_filepath, $fatpack, $output_filepath) = @_;
220 open(my $in, '<', $input_filepath) or die "open failed: $!";
221 open(my $out, '>', "$output_filepath.tmp") or die "open failed: $!";
224 s
|^#!\h*perl|#!/usr/bin/env perl|;
225 s
|^# FATPACK.*|$fatpack|;
229 unlink($output_filepath);
230 rename("$output_filepath.tmp", $output_filepath);
232 path
($output_filepath)->chmod(0755);
234 print STDERR
"Wrote fatpacked script: $output_filepath\n";
238 local $ENV{PLENV_VERSION
} = $plenv_version;
239 system('plenv', 'exec', @_);
This page took 0.051433 seconds and 4 git commands to generate.