summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2016-03-30 17:11:37 -0700
committerSean Whitton <spwhitton@spwhitton.name>2016-03-30 17:11:37 -0700
commitff061b80b84495adfac8028cb78982ddebe76df5 (patch)
tree175442ec1fa00c84c9d2c1325158bedab44fc701
parent911ad3e5434703a4c18d91f99f79c20d1c8bcd15 (diff)
melpa_files function
-rwxr-xr-xdh-make-elpa52
1 files changed, 51 insertions, 1 deletions
diff --git a/dh-make-elpa b/dh-make-elpa
index 888b4f5..cf2826b 100755
--- a/dh-make-elpa
+++ b/dh-make-elpa
@@ -7,7 +7,8 @@ our $VERSION = '0.1.0';
use DhMakePerl;
use Array::Utils qw{array_minus};
-use File::Grep qw( fgrep );
+use File::Grep qw{fgrep};
+use LWP::Simple qw{get};
sub initial_sanity_check {
my @files = glob("*.el");
@@ -16,6 +17,55 @@ sub initial_sanity_check {
}
}
+# Return the list of files for a package according to MELPA
+sub melpa_files {
+ my ($package) = @_;
+ print "Querying MELPA to find out which *.el files belong to the package $package...\n";
+ print "Note that this will give the wrong result if upstream has re-organised their repo since the release you're packaging.\n";
+ my $recipe = get("https://raw.githubusercontent.com/melpa/melpa/master/recipes/" . $package)
+ or die "Could not download recipe from MELPA!";
+
+ # insert MELPA's default globs if necessary (edited slightly)
+ my $defaults = <<EOT;
+"*.el"
+ (:exclude ".dir-locals.el" "test.el" "tests.el" "*-test.el" "*-tests.el")
+EOT
+ $recipe =~ s/:defaults/$defaults/;
+
+ # now see if there is a files array at all
+ if ($recipe =~ m/:files\s\((.*)\)/s)
+ {
+ # parse out the lisp list into perl arrays
+ my $lisp_files_list = $1;
+ $lisp_files_list =~ s/\s+/ /g;
+ my $includes, my $excludes;
+ # is there an :exclude list?
+ if ($lisp_files_list =~ m/(.*)\(:exclude\s(.*)\)(.*)/) {
+ $includes = $1 . $3;
+ $excludes = $2;
+ }
+ # no exclude list: include all
+ else {
+ $includes = $lisp_files_list;
+ $excludes = "";
+ }
+ # trim and split them up
+ $includes =~ s/^\s*\"(.*)\"[\s)]*$/$1/;
+ $excludes =~ s/^\s*\"(.*)\"[\s)]*$/$1/;
+ my @includes = split /\" \"/, $includes;
+ my @excludes = split /\" \"/, $excludes;
+
+ # perform the globs and return
+ @includes = map { glob($_) } @includes;
+ @excludes = map { glob($_) } @excludes;
+ return array_minus( @includes, @excludes );
+ }
+ # no files array: we can assume that all the *.el files belong to this package
+ else {
+ return glob("*.el");
+ }
+}
+
initial_sanity_check();
# check for command line arg