Doit

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

)
    or error "usage: $0 [options]";

my $action = shift || 'build';
$action =~ s/-/_/g;
if (@ARGV) {
    error "No arguments allowed";
}
{
    no strict 'refs';
    &$action;
}

sub build {
    build_libs();
    manifypods();
}

sub build_libs {
    $doit->make_path('blib/lib');
    $doit->make_path('blib/arch'); # not used, but keep ExtUtils::Install quiet
    require File::Find;
    my @pm_files;
    File::Find::find(sub { no warnings 'once'; push @pm_files, $File::Find::name if /\.(pm|pod)$/ && -f $_ }, "lib");
    for my $file (@pm_files) {
	my $dest = 'blib/'.$file;
	if (!-e $dest || -M $dest > -M $file) {
	    $doit->make_path(dirname($dest));
	    $doit->copy($file, $dest);
	}
    }
}

sub manifypods {
    # Handles only Pods in .pod files (which is the case in the Doit distribution)
    require File::Find;
    require Pod::Man;
    my $mansep = $^O =~ m{^(MSWin32|cygwin)$} ? '.' : '::';
    File::Find::find
	    ({
	      wanted => sub {
		  if (-f $_ && /\.pod$/) {
		      no warnings 'once';
		      my $pod = $File::Find::name;
		      my $section = 3; # no scripts yet, so we can hardcode here
		      my %options = (section => $section);
		      (my $man = $pod) =~ s{^lib.}{};
		      $man =~ s{/+}{$mansep}g;
		      $man =~ s{\.pod$}{.$Config{"man${section}ext"}};
		      $man = "blib/man$section/$man";
		      if (!-e $man || -M $man > -M $pod || -M $man > -M "Build") {
			  $doit->make_path(dirname($man));
			  my $parser = Pod::Man->new(%options);
			  if ($doit->is_dry_run) {
			      info "$pod -> $man (dry-run)";
			  } else {
			      info "$pod -> $man";
			      $parser->parse_from_file($pod, $man)
				  or error "Could not install $man";
			  }
			  $doit->chmod(0644, $man); # XXX should this be changeable? like $PERM_RW in Makefile.PL?
		      }
		  }
	      },
	      no_chdir => 1,
	     },
	     "lib");
}

sub clean {
    $doit->remove_tree('blib');
}

sub realclean { &clean }

sub test {
    local $ENV{PERL_DL_NONLAZY} = 1;
    require File::Glob;
    require File::Spec;
    $doit->system($^X, "-MExtUtils::Command::MM", "-MTest::Harness", "-e", 'undef *Test::Harness::Switches; test_harness(0, "blib/lib", "blib/arch")', File::Glob::bsd_glob(File::Spec->catfile("t", "*.t")));
    # $doit->system(_prove_path(), '-b', 't'); # use right perl?
}

sub test_xt {
    $doit->system(_prove_path(), '-b', 'xt'); # use right perl?
}

sub test_installed {
    my $t_dir = "$FindBin::RealBin/t";
    chdir "/"
	or error "Cannot chdir to /: $!";
    $doit->system(_prove_path(), $t_dir);
}

sub test_in_docker {
    my $distro_spec = $ENV{DISTRO_SPEC}; # XXX this should be a proper option!
    if (!$distro_spec || $distro_spec !~ m{^.*:.*$}) {
	error "Please set DISTRO_SPEC environment variable to something like 'debian:jessie'";
    }
    my $more_testing = $ENV{XXX_MORE_TESTING}; # XXX this will be a proper option in future!
    Doit::Log::set_label("[$distro_spec" . ($more_testing ? " (more)" : "") . "]");
    for my $tool (qw(docker)) {
	$doit->which($tool) or error "$tool is missing";
    }
    require File::Temp;
    my $dir = File::Temp::tempdir("Doit_test_in_docker_XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
    my $dockerfile = <<"EOF";
FROM $distro_spec

EOF
    if ($ENV{XXX_INVALIDATE_CACHE}) { # XXX this will be a proper option in future!
	_add_Dockerfile_invalidate_cmd(\$dockerfile);
    }

    my $add_opts = {};
    $dockerfile .= _fix_Dockerfile_for_dist($distro_spec, $add_opts);
    _docker_add_distro_specific_files(dir => $dir, distro_spec => $distro_spec);
    if (-e "$dir/.distro_support") {
	$dockerfile .= <<'EOF';
COPY .distro_support .distro_support
RUN .distro_support/run.sh

Build.PL  view on Meta::CPAN


sub ci_precheck {
    my @ci_systems = ('github-actions', 'appveyor');

    _check_clean_git();

    for my $ci_system (@ci_systems) {
	$doit->system('git', 'push', 'origin', "+HEAD:XXX-${ci_system}");
    }

    # check-ci is available here: https://github.com/eserte/srezic-misc/blob/master/scripts/check-ci
    $doit->system('check-ci', (map { "--$_" } @ci_systems));
}

sub _prove_path {
    my @directory_candidates = ($Config{bin}, dirname(realpath $^X));
    my @basename_candidates = ('prove', "prove$Config{version}");
    my @candidates = map {
	my $basename = $_;
	map {
	    "$_/$basename";
	} @directory_candidates;
    } @basename_candidates;
    if ($^O eq 'MSWin32') {
	unshift @candidates, map { "$_.bat"} @candidates;
    }
    for my $candidate (@candidates) {
	if (-x $candidate) {
	    return $candidate;
	}
    }
    error "No 'prove' for the current perl found";
}

sub _cover_path {
    my @candidates = ("$Config{bin}/cover");
    if ($^O eq 'MSWin32') {
	unshift @candidates, map { "$_.bat"} @candidates;
    }
    for my $candidate (@candidates) {
	if (-x $candidate) {
	    return $candidate;
	}
    }
    error "No 'cover' for the current perl found";
}

sub _Build_PL_mode {
    require Data::Dumper;
    my $argv_serialized = "\n" . '$Build_PL::ARGV = ' . Data::Dumper->new([\@ARGV], [])->Indent(1)->Useqq(1)->Sortkeys(1)->Terse(1)->Dump . ";\n\n";
    {
	if (-l "Build") { # formerly this used to be a symlink
	    $doit->unlink("Build");
	}
	my $preamble = <<"EOF";
#! $Config{perlpath}
# MD5: $Build_PL_md5hex
EOF
	$preamble .= $argv_serialized;
	$doit->write_binary({quiet=>1}, 'Build', $preamble . qq{# line 1 "Build.PL"\n} . $Build_PL_file_contents);
	$doit->chmod(0755, 'Build');

	eval {
	    generate_META_json("MYMETA.json");
	    generate_META_yml("MYMETA.yml" );
	};
	warning "Failure while generating MYMETA.* files, continue without.\nError was:\n$@" if $@;
    }
    exit;
}

# Return a string for adding to Dockerfile after the FROM line. Also
# the 2nd parameter (which has to be an empty hashref) is filled with
# further instructions to amend the Dockerfile (currently only
# apt_get_update_opts).
sub _fix_Dockerfile_for_dist {
    my($distro_spec, $add_opts_ref) = @_;
    if ($distro_spec =~ m{^debian:(wheezy|jessie|stretch|7|8|9)$}) {
	my $codename = $1;
	if    ($codename eq '7') { $codename = 'wheezy' }
	elsif ($codename eq '8') { $codename = 'jessie' }
	elsif ($codename eq '9') { $codename = 'stretch' }
	# https://unix.stackexchange.com/questions/508724/failed-to-fetch-jessie-backports-repository
	$add_opts_ref->{apt_get_update_opts}  = ' -o Acquire::Check-Valid-Until=false';
	# https://askubuntu.com/questions/74345/how-do-i-bypass-ignore-the-gpg-signature-checks-of-apt
	$add_opts_ref->{apt_get_install_opts} = ' -o APT::Get::AllowUnauthenticated=true';
	<<EOF;
RUN echo 'deb [check-valid-until=no] http://archive.debian.org/debian $codename main'                   >  /etc/apt/sources.list
RUN echo 'deb [check-valid-until=no] http://archive.debian.org/debian-security/ $codename/updates main' >> /etc/apt/sources.list
EOF
    } elsif ($distro_spec =~ m{^perl:(5\.18\.\d+|.*stretch)$}) { # XXX add more perl versions based on jessie/stretch/... containers
	# docker perl images are based on debian base images; older
	# ones need patching
	$add_opts_ref->{apt_get_install_opts} = ' -o APT::Get::AllowUnauthenticated=true';
	<<'EOF';
RUN perl -i -pe \
    's{deb http://(?:http.debian.net|deb.debian.org)/debian (\S+) main}{deb [check-valid-until=no] http://archive.debian.org/debian $1 main}; \
     s{deb http://security.debian.org.* ([^/]+)/updates main}{deb [check-valid-until=no] http://archive.debian.org/debian-security/ $1/updates main}; \
     $_ = "" if m{^deb .*-updates main}; \
    ' /etc/apt/sources.list
EOF
    } else {
	$add_opts_ref->{apt_get_update_opts} = '';
	$add_opts_ref->{apt_get_install_opts} = '';
	'';
    }
}

sub _add_Dockerfile_invalidate_cmd {
    my $dockerfile_ref = shift;
    require POSIX;
    $$dockerfile_ref .= <<"EOF";
# Just a hack to make sure that the following lines
# are executed at least once a day
RUN echo @{[ POSIX::strftime("%F", localtime) ]}
EOF
}

sub _docker_add_distro_specific_files {
    my %opts = @_;
    my $dir         = delete $opts{dir}         || die 'Please specify dir';

Build.PL  view on Meta::CPAN

[extras]
name=CentOS-6.10 - Extras
baseurl=http://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
metadata_expire=never

# additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.10 - CentOSPlus
baseurl=http://vault.centos.org/6.10/centosplus/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=0
metadata_expire=never

#contrib - packages by Centos Users
[contrib]
name=CentOS-6.10 - Contrib
baseurl=http://vault.centos.org/6.10/contrib/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=0
metadata_expire=never
EOF
	$doit->write_binary("$dir/.distro_support/epel.repo", <<'EOF');
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=https://archives.fedoraproject.org/pub/archive/epel/6/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
metadata_expire=never

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=https://archives.fedoraproject.org/pub/archive/epel/6/$basearch/debug
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
metadata_expire=never

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=https://archives.fedoraproject.org/pub/archive/epel/6/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
metadata_expire=never
EOF
	$doit->write_binary("$dir/.distro_support/run.sh", <<'EOF');
#! /bin/sh
set -ex
rm -f /etc/yum.repos.d/CentOS*.repo
rm -f /etc/yum.repos.d/epel.repo
cp .distro_support/CentOS.repo /etc/yum.repos.d/
cp .distro_support/epel.repo /etc/yum.repos.d/
yum clean all
EOF
	$doit->chmod(0755, "$dir/.distro_support/run.sh");
    }
}

sub _check_clean_git {
    $doit->add_component('git');

    my $status = $doit->git_short_status;
    if ($status eq '<<') {
	error 'Working directory has uncomitted changes: ' . `git status`;
    }
    if ($status eq '*') {
	error 'Working directory has files not under git control (and not in .gitignore or .git/info/exclude): ' . `git status`;
    }
}

# REPO BEGIN
# REPO NAME y_or_n /home/eserte/src/srezic-repository 
# REPO MD5 146cfcf8f954555fe0117a55b0ddc9b1

#=head2 y_or_n
#
#Accept user input. Return true on 'y', return false on 'n', otherwise
#ask again.
#
#A default may be supplied as an optional argument:
#
#    y_or_n 'y';
#    y_or_n 'n';
#
#=cut

sub y_or_n (;$) {
    my $default = shift;
    while () {
        chomp(my $yn = <STDIN>);
	if ($yn eq '' && defined $default) {
	    $yn = $default;
	}
        if (lc $yn eq 'y') {
            return 1;
        } elsif (lc $yn eq 'n') {
	    return 0;
        } else {
            print STDERR "Please answer y or n: ";
        }
    }
}
# REPO END

__END__



( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )