]>
Dogcows Code - chaz/graphql-client/blob - maint/fatpack.pl
2748081e4905a02987c5be77ca3da53be0a0851e
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/");
84 my $cd_builddir = pushd
($moduledir);
86 system('perlstrip', '--cache', '-v', find_modules
('.'));
90 generate_script
($distdir->child('bin/graphql'), $fatpack, 'graphql');
93 sub required_modules
{
94 my $path = path
(shift);
95 my $cache_filepath = shift;
97 print STDERR
"Determining required modules...\n";
99 my $cachefile = $cache_filepath && path
($cache_filepath);
100 if (my $contents = eval { $cachefile->slurp_utf8 }) {
102 return split(/\n/, $contents);
105 my $meta = CPAN
::Meta-
>load_file($path->child('META.json'));
107 my $requires = CPAN
::Meta
::Requirements-
>new;
109 for my $type (qw{requires recommends suggests}) {
110 my $reqs = $meta->effective_prereqs->requirements_for('runtime', $type);
111 for my $module ($reqs->required_modules) {
112 next if $blacklist_modules{$module};
114 my $core = $Module::CoreList
::version
{$core_version}{$module};
115 print STDERR
"skipping core: $module $core\n" if $core;
116 next if $core && $reqs->accepts_module($module, $core);
118 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
119 dependencies_for_module
($requires, $module);
122 $requires->clear_requirement($_) for qw(Module::CoreList ExtUtils::MakeMaker Carp);
123 my @deps = $requires->required_modules;
125 push @deps, @extra_modules;
127 $cachefile->spew_utf8([map { "$_\n" } @deps]) if $cachefile;
132 sub dependencies_for_dist
{
133 my $requires = shift;
137 return if $dists{$name}++;
138 print STDERR
"Finding dependencies for dist $name\n";
140 my $dist = $mcpan->release(distribution
=> $name);
142 my $reqs = CPAN
::Meta
::Requirements-
>new;
144 foreach my $dep (@{$dist->{dependency
}}) {
145 next if $dep->{phase
} ne 'runtime';
146 next if $dep->{relationship
} ne 'requires'; # && $dep->{relationship} ne 'recommends';
148 my $module = $dep->{module
};
149 next if $blacklist_modules{$module};
151 $reqs->add_minimum($dep->{module
} => $dep->{version
});
152 my $core = $Module::CoreList
::version
{$core_version}{$module};
153 print STDERR
"skipping core: $module $core\n" if $core;
154 next if $core && $reqs->accepts_module($module, $core);
156 $requires->add_string_requirement($module => $reqs->requirements_for_module($module));
157 dependencies_for_module
($requires, $dep->{module
});
161 sub dependencies_for_module
{
162 my $requires = shift;
166 return if $modules{$name}++;
167 print STDERR
"Finding dependencies for module $name\n";
169 my $module = $mcpan->module($name);
170 dependencies_for_dist
($requires, $module->{distribution
});
174 my $path = path
(shift);
175 $path->child($Config{archname
})->remove_tree({safe
=> 0});
176 $path->child('POD2')->remove_tree({safe
=> 0});
179 if (/\.p(od|l)$/ || /\.sample$/) {
187 my $path = path
(shift);
191 push @pm_filepaths, $_ if /\.pm$/;
193 return @pm_filepaths;
197 my ($path, @modules) = @_;
199 my @filepaths = map { my $s = $_; $s =~ s!::!/!g; "$s.pm" } @modules;
201 my $stdout = capture_stdout
{
202 local $ENV{PERL5LIB
} = $path->child('lib/perl5')->absolute;
203 system('fatpack', 'packlists-for', @filepaths);
206 my @packlists = split(/\n/, $stdout);
207 for my $packlist (@packlists) {
208 warn "Packing $packlist\n";
211 system('fatpack', 'tree', map { path
($_)->absolute } @packlists);
214 sub generate_script
{
215 my ($input_filepath, $fatpack, $output_filepath) = @_;
217 open(my $in, '<', $input_filepath) or die "open failed: $!";
218 open(my $out, '>', "$output_filepath.tmp") or die "open failed: $!";
221 s
|^#!\h*perl|#!/usr/bin/env perl|;
222 s
|^# FATPACK.*|$fatpack|;
226 unlink($output_filepath);
227 rename("$output_filepath.tmp", $output_filepath);
229 path
($output_filepath)->chmod(0755);
231 print STDERR
"Wrote fatpacked script: $output_filepath\n";
235 local $ENV{PLENV_VERSION
} = $plenv_version;
236 system('plenv', 'exec', @_);
This page took 0.043098 seconds and 3 git commands to generate.