Commits

Burak Gürsoy committed 5ef8084

Automatically create Build.PL from SPEC if missing.

  • Participants
  • Parent commits e07ef65

Comments (0)

Files changed (1)

 
 END {
     my $eok = eval { require Time::Elapsed; 1; };
-    my $t = $START_TIME ? time - $START_TIME : 0;
+    my $t   = $START_TIME ? time - $START_TIME : 0;
     $@ ? _print( sprintf L('bench.error'), $t )
        : _print( sprintf L('bench.ok'), Time::Elapsed::elapsed( $t, $LANG ) );
 }
     _chdir( $path{build} );
     my ( $build_pl, $makefile_pl ) = ( 0, 0 );
 
+    if (   ! -e 'Build.PL'
+        && ! -e 'Makefile.PL'
+        &&   -e 'SPEC'
+        &&   -e catfile(qw( builder Build.pm ))
+    ) {
+        # This looks like "my" thing, but missing a builder
+        unshift @INC, catdir $path{build}, 'builder';
+        create_build_pl();
+    }
+
     if ( -e 'Build.PL' && !$O{nomb} ) {
         call("$PERL_EXE Build.PL");
         call("$PERL_EXE Build");
     return;
 }
 
+sub create_build_pl {
+    _print "[DEBUG] CREATING Build.PL from SPEC as no builder present.\n";
+    require Build::Spec;
+    my %spec  = Build::Spec::spec();
+    my $build = delete $spec{BUILDER} || croak 'SPEC does not have a BUILDER key';
+    my @opt;
+    foreach my $k ( keys %{ $build } ) {
+        push @opt, sprintf q{$mb->%s( %s );}, $k, $build->{ $k };
+    }
+    write_file( '>', 'Build.PL', sprintf <<'BUILD_PL', join "\n", @opt );
+# This file was created automatically
+use strict;
+use warnings;
+use lib qw( builder );
+use Build;
+
+my $mb = Build->new;
+%s
+$mb->create_build_script;
+
+1;
+
+BUILD_PL
+    write_file( '>>', MANIFEST => "Build.PL\tCreated automatically\n" );
+    return;
+}
+
 sub ask {
     my @modlist;
     opendir my $MODDIR, $path{source}
     while ( my $file = readdir $MODDIR ) {
         next if $file =~ m{ \A [._] }xms;
         next if !-d catdir( $path{source}, $file );
-        if (   !-e catdir( $path{source}, $file, 'Build.PL' )
-            && !-e catdir( $path{source}, $file, 'Makefile.PL' ) )
-        {
+        if (
+               ! -e catdir( $path{source}, $file, 'Build.PL' )
+            && ! -e catdir( $path{source}, $file, 'Makefile.PL' )
+            && ! -e catdir( $path{source}, $file, 'SPEC' )
+        ){
             _print tts( L('ask.nobuilder'), [ path => $file ] );
             next;
         }
         'ask.found'       => "\nFound distros:\n\n",
         'ask.ok'          => <<'MESSAGE',
 
-    OYE!
+    OH YEAH!
 
 You've selected: <%= $p{target} %> (<%= $p{modname} %>) ...