Skip to content

Commit

Permalink
Make install --deployment update all modules
Browse files Browse the repository at this point in the history
This is a fix for perl-carton#149

It can probably be done a lot saner, this is more a PoC.
  • Loading branch information
JRaspass committed May 10, 2016
1 parent 192b219 commit 82f8941
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 9 deletions.
36 changes: 27 additions & 9 deletions lib/Carton/CLI.pm
Expand Up @@ -7,6 +7,7 @@ use Path::Tiny;
use Try::Tiny;
use Module::CoreList;
use Scalar::Util qw(blessed);
use File::Temp;

use Carton;
use Carton::Builder;
Expand Down Expand Up @@ -197,13 +198,6 @@ sub cmd_install {

# TODO: --without with no .lock won't fetch the groups, resulting in insufficient requirements

if ($deployment) {
$self->print("Installing modules using @{[$env->cpanfile]} (deployment mode)\n");
$builder->cascade(0);
} else {
$self->print("Installing modules using @{[$env->cpanfile]}\n");
}

# TODO merge CPANfile git to mirror even if lock doesn't exist
if ($env->snapshot->loaded) {
my $index_file = $env->install_path->child("cache/modules/02packages.details.txt");
Expand All @@ -217,9 +211,33 @@ sub cmd_install {
$builder->mirror(Carton::Mirror->new($env->vendor_cache));
}

$builder->install($env->install_path);
if ($deployment) {
$self->print("Installing modules using @{[$env->cpanfile]} (deployment mode)\n");

my $cpanfile = File::Temp->new;
for ( $env->snapshot->distributions ) {
while ( my ($pkg, $ver) = each %{ $_->provides } ) {
print $cpanfile "requires '$pkg', '== $ver->{version}';\n"
if $ver->{version} ne 'undef';
}
}
$cpanfile->close;

$builder->run_cpanm(
"-L", $env->install_path,
(map { ("--mirror", $_->url) } $builder->effective_mirrors),
"--mirror-index", $builder->index,
( $builder->custom_mirror ? "--mirror-only" : () ),
"--save-dists", $env->install_path . '/cache',
"--cpanfile", $cpanfile->filename,
"--installdeps", $env->cpanfile->dirname,
) or die "Installing modules failed\n";
}
else {
$self->print("Installing modules using @{[$env->cpanfile]}\n");

$builder->install($env->install_path);

unless ($deployment) {
$env->cpanfile->load;
$env->snapshot->find_installs($env->install_path, $env->cpanfile->requirements);
$env->snapshot->save;
Expand Down
89 changes: 89 additions & 0 deletions xt/cli/bug-149.t
@@ -0,0 +1,89 @@
use strict;
use Test::More;
use xt::CLI;

{
my $app = cli();
$app->write_cpanfile(<<'EOF');
requires 'Type::Tiny', '== 1.000005';
EOF

$app->write_file( 'cpanfile.snapshot' => my $snapshot = <<'EOF' );
# carton snapshot format: version 1.0
DISTRIBUTIONS
Exporter-Tiny-0.040
pathname: T/TO/TOBYINK/Exporter-Tiny-0.040.tar.gz
provides:
Exporter::Shiny 0.040
Exporter::Tiny 0.040
requirements:
ExtUtils::MakeMaker 6.17
perl 5.006001
Type-Tiny-1.000005
pathname: T/TO/TOBYINK/Type-Tiny-1.000005.tar.gz
provides:
Devel::TypeTiny::Perl56Compat 1.000005
Devel::TypeTiny::Perl58Compat 1.000005
Error::TypeTiny 1.000005
Error::TypeTiny::Assertion 1.000005
Error::TypeTiny::Compilation 1.000005
Error::TypeTiny::WrongNumberOfParameters 1.000005
Eval::TypeTiny 1.000005
Reply::Plugin::TypeTiny 1.000005
Test::TypeTiny 1.000005
Type::Coercion 1.000005
Type::Coercion::FromMoose 1.000005
Type::Coercion::Union 1.000005
Type::Library 1.000005
Type::Params 1.000005
Type::Parser 1.000005
Type::Registry 1.000005
Type::Tiny 1.000005
Type::Tiny::Class 1.000005
Type::Tiny::Duck 1.000005
Type::Tiny::Enum 1.000005
Type::Tiny::Intersection 1.000005
Type::Tiny::Role 1.000005
Type::Tiny::Union 1.000005
Type::Utils 1.000005
Types::Common::Numeric 1.000005
Types::Common::String 1.000005
Types::Standard 1.000005
Types::Standard::ArrayRef 1.000005
Types::Standard::Dict 1.000005
Types::Standard::HashRef 1.000005
Types::Standard::Map 1.000005
Types::Standard::ScalarRef 1.000005
Types::Standard::Tuple 1.000005
Types::TypeTiny 1.000005
requirements:
Exporter::Tiny 0.026
ExtUtils::MakeMaker 6.17
perl 5.006001
EOF

$app->run(qw/install --deployment/);

like $app->stdout, qr/
\QSuccessfully installed Exporter-Tiny-0.040\E\n
\QSuccessfully installed Type-Tiny-1.000005\E\n
/x, 'First deployment installs both';

$app->run(qw/install --deployment/);

unlike $app->stdout, qr/Successfully installed/,
'Second install with an unchanged snapshot is a no-op';

$snapshot =~ s/0.040/0.042/g; # Upgrade Exporter::Tiny

$app->write_file( 'cpanfile.snapshot' => $snapshot );

$app->run(qw/install --deployment/);

like $app->stdout, qr/
\QSuccessfully installed Exporter-Tiny-0.042 (upgraded from 0.040)\E\n
\Q1 distribution installed\E\n
/x, 'Third install with a changed snapshot install the correct dist';
}

done_testing;

0 comments on commit 82f8941

Please sign in to comment.