summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2018-06-20 12:33:18 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2018-06-20 12:33:18 (GMT)
commit39f8ae395b158f958a415c88a31f9c500072c67f (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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
--- a/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,5 +1,6 @@
package URI::sbo;
use parent 'URI::_generic';
+use File::Spec::Unix;
sub branch {
my $self = shift;
@@ -15,6 +16,16 @@ sub path {
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__
diff --git a/slackbuilder b/slackbuilder
index c27d643..6e3ac47 100755
--- a/slackbuilder
+++ b/slackbuilder
@@ -9,9 +9,10 @@ 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
@@ -62,27 +63,16 @@ GetOptions("h" => sub {
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";

Return to:

Send suggestions and report system problems to the System administrator.