Module buildsys. Needs improvement.
This commit is contained in:
1 parent
ae778cc267
commit
3a70f30f2b
1 file changed
+124
Executable
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env perl
|
||||
# Auto IRC Bot. An advanced, lightweight and powerful IRC bot.
|
||||
# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS)
|
||||
# This program is free software; rights to this code are stated in doc/LICENSE.
|
||||
use 5.010_000;
|
||||
use strict;
|
||||
use warnings;
|
||||
use English qw(-no_match_vars);
|
||||
use FindBin qw($Bin);
|
||||
our $Bin = $Bin;
|
||||
|
||||
our $VERSION = 1.00;
|
||||
|
||||
# Get module parameter.
|
||||
if (!defined $ARGV[0]) {
|
||||
say 'Not enough parameters. Usage: buildmod <module>';
|
||||
exit;
|
||||
}
|
||||
my $module = $ARGV[0];
|
||||
|
||||
# Set full path.
|
||||
my $type = 0;
|
||||
my $modulep;
|
||||
if (-e "$Bin/../modules/$module.pm") {
|
||||
$modulep = "$Bin/../modules/$module.pm";
|
||||
$type = 1;
|
||||
}
|
||||
else {
|
||||
if (-e "$Bin/../modules/$module/Buildfile") {
|
||||
$modulep = "$Bin/../modules/$module/Buildfile";
|
||||
$type = 2;
|
||||
}
|
||||
else {
|
||||
say 'No such module '.$module;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
my $data;
|
||||
if ($type == 1) {
|
||||
open my $FHM, '<', $modulep;
|
||||
my @BUF = <$FHM>;
|
||||
close $FHM;
|
||||
|
||||
foreach my $line (@BUF) {
|
||||
$line =~ s/(\r|\n)//g;
|
||||
|
||||
if ($line =~ m/^# build: /sm) {
|
||||
$data = substr $line, 9;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined $data) {
|
||||
say 'No build line found in '.$module.'.pm. Aborting.';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
elsif ($type == 2) {
|
||||
open my $FHM, '<', $modulep;
|
||||
my @BUF = <$FHM>;
|
||||
close $FHM;
|
||||
|
||||
foreach my $line (@BUF) {
|
||||
$line =~ s/(\r|\n)//g;
|
||||
|
||||
$data .= $line;
|
||||
}
|
||||
|
||||
if (!defined $data) {
|
||||
say 'No build datafound in '.$module.'/Buildfile. Aborting.';
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
$data = substr $data, 1;
|
||||
}
|
||||
}
|
||||
|
||||
# Start build.
|
||||
my @pars = split ' ', $data;
|
||||
my $die = 0;
|
||||
|
||||
say 'Building '.$module.'.....';
|
||||
|
||||
foreach (@pars) {
|
||||
my ($opt, $val) = split m/[=]/;
|
||||
|
||||
given ($opt) {
|
||||
when ('cpan') {
|
||||
say 'Checking for required CPAN modules.....'; print $RS;
|
||||
my @vals = split ',', $val;
|
||||
my $res = 0;
|
||||
foreach my $cpanmod (@vals) {
|
||||
$res = eval('require '.$cpanmod.'; 1;');
|
||||
say ' '.$cpanmod.': '.(($res) ? 'Found' : 'Not Found');
|
||||
if (!$res) { $die = 1; }
|
||||
}
|
||||
print $RS;
|
||||
|
||||
if ($die) { say 'Failed to build '.$module.'.'; exit; }
|
||||
}
|
||||
when ('perl') {
|
||||
print 'Checking Perl version..... '.$PERL_VERSION.' - ';
|
||||
if ($] < $val) { $die = 1; }
|
||||
say (($die) ? 'Not OK' : 'OK');
|
||||
print $RS;
|
||||
if ($die) { say 'Failed to build '.$module.'.'; exit; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open my $FHBM, '<', $modulep;
|
||||
|
||||
my $db = '# buildmod.built: YES '.time."\n";
|
||||
foreach my $line (<$FHBM>) {
|
||||
$line =~ s/(\r|\n)//g;
|
||||
$db .= $line."\n";
|
||||
}
|
||||
close $FHBM;
|
||||
|
||||
open $FHBM, '>', $modulep;
|
||||
print {$FHBM} $db;
|
||||
close $FHBM;
|
||||
|
||||
say 'Done.';
|
||||
Reference in new issue
Block a user