Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add "bundle" target that will create a tarball for uploading
It builds and tests the project in cwd to reveal its dependencies,
tries to get its hands on the distribution name and description,
and proposes a META.info file with this just collected information.

Sadly the used prompt() segfaults on moar and besides that we need
to autodiscover the types it is going to provide, similar to the
dependency check.
  • Loading branch information
FROGGS committed Mar 9, 2014
1 parent 38664d7 commit 17b6624
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 9 deletions.
20 changes: 11 additions & 9 deletions META.info
Expand Up @@ -5,14 +5,16 @@
"depends" : [ "File::Find", "Shell::Command", "JSON::Tiny" ],
"source-url" : "git://github.com/tadzik/panda.git",
"provides" : {
"Panda" : "lib/Panda.pm",
"Panda::App" : "lib/Panda/App.pm",
"Panda::Builder" : "lib/Panda/Builder.pm",
"Panda::Common" : "lib/Panda/Common.pm",
"Panda::Ecosystem" : "lib/Panda/Ecosystem.pm",
"Panda::Fetcher" : "lib/Panda/Fetcher.pm",
"Panda::Installer" : "lib/Panda/Installer.pm",
"Panda::Project" : "lib/Panda/Project.pm",
"Panda::Tester" : "lib/Panda/Tester.pm"
"Panda" : "lib/Panda.pm",
"Panda::App" : "lib/Panda/App.pm",
"Panda::Builder" : "lib/Panda/Builder.pm",
"Panda::Bundler" : "lib/Panda/Bundler.pm",
"Panda::Common" : "lib/Panda/Common.pm",
"Panda::DepTracker" : "lib/Panda/DepTracker.pm",
"Panda::Ecosystem" : "lib/Panda/Ecosystem.pm",
"Panda::Fetcher" : "lib/Panda/Fetcher.pm",
"Panda::Installer" : "lib/Panda/Installer.pm",
"Panda::Project" : "lib/Panda/Project.pm",
"Panda::Tester" : "lib/Panda/Tester.pm"
}
}
5 changes: 5 additions & 0 deletions bin/panda
Expand Up @@ -66,6 +66,11 @@ multi MAIN ('search', $pattern) {
search-projects($panda, $pattern);
}

#= Bundle the project in the current directory for uploading to PAUSE.
multi MAIN ('bundle', Bool :$notests, Str :$name, Str :$auth, Str :$desc) {
$panda.bundler.bundle($panda);
}

END {
rm_rf '.work' if '.work'.IO.e;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Panda.pm
Expand Up @@ -4,6 +4,7 @@ use Panda::Fetcher;
use Panda::Builder;
use Panda::Tester;
use Panda::Installer;
use Panda::Bundler;
use Shell::Command;
use JSON::Tiny;

Expand All @@ -18,6 +19,7 @@ class Panda {
has $.builder = Panda::Builder.new;
has $.tester = Panda::Tester.new;
has $.installer = Panda::Installer.new;
has $.bundler = Panda::Bundler.new;

multi method announce(Str $what) {
say "==> $what"
Expand Down
94 changes: 94 additions & 0 deletions lib/Panda/Bundler.pm
@@ -0,0 +1,94 @@
class Panda::Bundler;
use Panda::Common;
use Panda::Project;

sub guess-project($where) {
my $name;
my $description;
my $source-url;

indir $where, {
if 'META.info'.IO.e {
try my $json = from-json 'META.info'.IO.slurp;
if $json {
$name = $json<name> if $json<name>;
$description = $json<description> if $json<description>;
$source-url = $json<source-url> if $json<source-url>;
}
}
unless $name {
$name = $where.parts<basename>.subst(/:i ^'p' 'erl'? '6-'/, '').split(/<[\-_]>+/, :g)>>.tc.join('::');
}
unless $description {
$description = '.git/description'.IO.slurp if '.git/description'.IO.e
}
unless $source-url {
try my $git = qx{git remote show origin}.lines.first(/\.git$/);
if $git && $git ~~ /$<url>=\S+$/ {
$source-url = $<url>;
if $source-url ~~ m/'git@' $<host>=[.+] ':' $<repo>=[<-[:]>+] $/ {
$source-url = "git://$<host>/$<repo>"
}
}
}
};

Panda::Project.new( :$name, :metainfo( :$description, :$source-url ) )
}

method bundle($panda, :$notests) {
my $dir = cwd.absolute;
my $bone = guess-project($dir);

temp $*EXECUTABLE_NAME = "$*EXECUTABLE_NAME -MPanda::DepTracker";
%*ENV<PANDA_DEPTRACKER_FILE> = "$dir/deptracker-$*PID";

$panda.announce('building', $bone);
unless $_ = $panda.builder.build($dir) {
die X::Panda.new($bone.name, 'build', $_)
}
if %*ENV<PANDA_DEPTRACKER_FILE>.IO.e {
my $test = EVAL %*ENV<PANDA_DEPTRACKER_FILE>.IO.slurp;
for $test.list -> $m {
$bone.metainfo<build-depends>.push: $m<module_name> # XXX :auth/:ver/:from/...
}
%*ENV<PANDA_DEPTRACKER_FILE>.IO.spurt: ''
}

unless $notests {
temp $*EXECUTABLE_NAME = "\"$*EXECUTABLE_NAME -MPanda::DepTracker\"";
$panda.announce('testing', $bone);
unless $_ = $panda.tester.test($dir) {
die X::Panda.new($bone.name, 'test', $_)
}
if %*ENV<PANDA_DEPTRACKER_FILE>.IO.e {
my $test = EVAL %*ENV<PANDA_DEPTRACKER_FILE>.IO.slurp;
for $test.list -> $m {
$bone.metainfo<test-depends>.push: $m<module_name> # XXX :auth/:ver/:from/...
}
%*ENV<PANDA_DEPTRACKER_FILE>.IO.spurt: ''
}
}

$bone.metainfo<depends> = [($bone.metainfo<test-depends> (&) $bone.metainfo<build-depends>).list.flat];

$bone.metainfo<version> = prompt "Please enter version number (example: v1.2.3): ";

$panda.announce('Creating META.info.proposed');
'META.info.proposed'.IO.spurt: to-json {
name => $bone.name,
description => $bone.metainfo<description>,
version => $bone.metainfo<version>,
build-depends => $bone.metainfo<build-depends>,
test-depends => $bone.metainfo<test-depends>,
depends => $bone.metainfo<depends>,
# XXX provides section
source-url => $bone.metainfo<source-url>,
};

try unlink %*ENV<PANDA_DEPTRACKER_FILE> if %*ENV<PANDA_DEPTRACKER_FILE>.IO.e;

return True;
}

# vim: ft=perl6
9 changes: 9 additions & 0 deletions lib/Panda/DepTracker.pm
@@ -0,0 +1,9 @@
class DepTracker is CompUnitRepo {
method load_module($module_name, %opts, *@GLOBALish is rw, :$line, :$file) {
if %*ENV<PANDA_DEPTRACKER_FILE> && $module_name ne 'Panda::DepTracker' {
%*ENV<PANDA_DEPTRACKER_FILE>.IO.spurt: { :$module_name, :%opts }.perl ~ ",\n", :append;
}
nextsame;
}
}
nqp::bindhllsym('perl6', 'ModuleLoader', DepTracker);

0 comments on commit 17b6624

Please sign in to comment.