summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-06-20 14:33:18 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2018-06-20 14:33:18 +0200
commit39f8ae395b158f958a415c88a31f9c500072c67f (patch)
treea51065db5df01cc85887a8a650e8013acdb0ab8d
parent5091d2c21569478bab5eeac0ad1cf6c4e459ab87 (diff)
downloadslackbuilder-39f8ae395b158f958a415c88a31f9c500072c67f.tar.gz
slackbuilder-39f8ae395b158f958a415c88a31f9c500072c67f.tar.bz2
Support the sbo:// URLs on input
* lib/SlackBuild/Request/Auto.pm: New module * lib/URI/sbo.pm (request,component): New methods * slackbuilder: Use SlackBuild::Request::Auto to parse the request argument.
-rw-r--r--lib/SlackBuild/Request/Auto.pm102
-rw-r--r--lib/URI/sbo.pm11
-rwxr-xr-xslackbuilder30
3 files changed, 123 insertions, 20 deletions
diff --git a/lib/SlackBuild/Request/Auto.pm b/lib/SlackBuild/Request/Auto.pm
new file mode 100644
index 0000000..08832d6
--- /dev/null
+++ b/lib/SlackBuild/Request/Auto.pm
@@ -0,0 +1,102 @@
+package SlackBuild::Request::Auto;
+use strict;
+use warnings;
+use parent 'SlackBuild::Request';
+use File::Basename;
+use File::Spec;
+use Net::SBo;
+use JSON;
+use Carp;
+
+sub req {
+ my ($class, $reqname) = @_;
+ my $req;
+
+ if (-f $reqname) {
+ local $/ = undef;
+ open(my $fd, $reqname) or croak "can't open file $reqname: $!";
+ my $string = <$fd>;
+ close $fd;
+ return decode_json($string);
+ }
+
+ if (-d $reqname) {
+ if (my $file =
+ (glob File::Spec->catfile($reqname, '*.SlackBuild'))[0]) {
+ my ($package,$path,$suffix) = fileparse($file, '.SlackBuild');
+ return { package => $package, slackbuild_uri => $path };
+ }
+ }
+
+ if ($reqname =~ m{^\w+://}) {
+ my $uri = new URI($reqname);
+ if ($uri->scheme =~ m{^(?:http|ftp)s?}
+ && $uri->path =~ m{.*/(.+?)\.tar(?:\.(?:[xgl]z|bz2))?}x) {
+ return { package => $1, slackbuild_uri => $reqname };
+ }
+ if ($uri->scheme eq 'sbo') {
+ return { package => $uri->package, slackbuild_uri => $reqname }
+ }
+ }
+
+ if (my ($dir,$commit) = Net::SBo->new->find($reqname)) {
+ return { package => $reqname, slackbuild_uri => "sbo://$commit/$dir"};
+ }
+
+ croak "unrecognized request type";
+}
+
+sub new {
+ my ($class, $arg) = @_;
+ return $class->SUPER::new(__PACKAGE__->req($arg));
+}
+
+1;
+__END__
+
+=head1 NAME
+
+SlackBuild::Request::Auto - automatic request convertor for SlackBuilder
+
+=head1 SYNOPSIS
+
+ $req = new SlackBuild::Request::Auto($arg)
+
+=head1 DESCRIPTION
+
+Attempts to recognize the format of I<$arg> and convert it to the SlackBuilder
+build request.
+
+Argument can be any of:
+
+=over 4
+
+=item Name of an existing file
+
+The file is read and parsed as a JSON request file.
+
+=item Name of an existing directory
+
+If it contains a file B<*.SlackBuild>, a request referring to files
+in this directory is returned.
+
+=item A http, https, ftp, or ftps URL to a tar file
+
+The file component of the URL must end with B<.tar>, followed with a
+compression suffix (B<.gz>, B<.xz>, or B<.bz2>). The archive must contain
+at least the B<*.SlackBuild> file.
+
+Example:
+
+ https://slackbuilds.org/slackbuilds/14.2/system/mailutils.tar.gz
+
+=item An SBo URL
+
+Example:
+
+ sbo://HEAD/system/mailutils
+
+=back
+
+=cut
+
diff --git a/lib/URI/sbo.pm b/lib/URI/sbo.pm
index 883d659..6594c99 100644
--- a/lib/URI/sbo.pm
+++ b/lib/URI/sbo.pm
@@ -1,8 +1,9 @@
package URI::sbo;
use parent 'URI::_generic';
+use File::Spec::Unix;
sub branch {
my $self = shift;
return $self->authority || 'HEAD';
}
@@ -12,12 +13,22 @@ sub path {
my $self = shift;
my $ret = $self->SUPER::path(@_);
$ret =~ s{^/}{};
return $ret;
}
+sub _pathcomp {
+ my ($self, $n) = @_;
+ # The array layout is:
+ # ($category, $package, @path)
+ return (File::Spec::Unix->splitdir($self->path))[$n];
+}
+
+sub category { shift->_pathcomp(0) }
+sub package { shift->_pathcomp(1) }
+
1;
__END__
=head1 NAME
URI::sbo - slackbuilds URI
diff --git a/slackbuilder b/slackbuilder
index c27d643..6e3ac47 100755
--- a/slackbuilder
+++ b/slackbuilder
@@ -6,15 +6,16 @@ use Pod::Usage;
use Pod::Man;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
use File::Basename;
use File::Spec;
use Unix::Sysexits;
use SlackBuilder;
-use SlackBuild::Request;
+use SlackBuild::Request::Auto;
use Net::SBo;
use JSON;
+use Try::Tiny;
use constant {
EX_FAIL => 1
};
my $progname = basename($0);
@@ -59,33 +60,22 @@ GetOptions("h" => sub {
"image|i=s" => \$sbargs{image},
"rootdir|C=s" => \$sbargs{image}
) or exit(EX_USAGE);
abend(EX_USAGE, "bad number of arguments") unless @ARGV == 1;
my $reqname = shift @ARGV;
-my $req;
-
-if (-f $reqname) {
- $req = readfile($reqname);
-} elsif (-d $reqname) {
- if (my $file = (glob File::Spec->catfile($reqname, '*.SlackBuild'))[0]) {
- my ($package,$path,$suffix) = fileparse($file, '.SlackBuild');
- $req = { package => $package, slackbuild_uri => $path };
- }
-} elsif ($reqname =~ m{^(?:http|ftp)s?://.*/
- (.+?) \.tar(?:\.(?:[xgl]z|bz2))?}x) {
- $req = { package => $1, slackbuild_uri => $reqname };
-} elsif (my ($dir,$commit) = Net::SBo->new->find($reqname)) {
- $req = { package => $reqname, slackbuild_uri => "sbo://$commit/$dir"};
-}
-
-abend(EX_NOINPUT, "request file $reqname does not exist")
- unless $req;
+my $req = try {
+ new SlackBuild::Request::Auto($reqname)
+} catch {
+ my $err = (split /\n/)[0];
+ $err =~ s{\s+at .* line \d+\.$}{};
+ abend(EX_NOINPUT, "$reqname: $err")
+};
my $builder = new SlackBuilder(%sbargs);
-$builder->run(new SlackBuild::Request($req));
+$builder->run($req);
if ($builder->is_success) {
if ($builder->output_files == 0) {
print STDERR "Build exited successfully, but no output files were generated\n";
exit EX_FAIL;
}
print "OK. File list:\n";

Return to:

Send suggestions and report system problems to the System administrator.