@@ -618,67 +618,6 @@ sub indent_array (@) {
618618 return " $first \n $rest " ;
619619}
620620
621- sub parse_quoted_words ($) {
622- my ($value ) = @_ ;
623-
624- $value // return q{ } ;
625- $value = strip_space($value );
626-
627- if ($value =~ / ^\( (.+)\)\z /s ) {
628- $value = $1 ;
629- return [grep { defined && $_ ne q{ } } quotewords(qr {\s +|(?-s:#.*)} , 0, $value )];
630- }
631-
632- $value =~ s / ["']\s *#.*// ;
633- $value !~ / ["']/ && $value =~ s /\s *#.*// ;
634- $value =~ s / ^['"]// ;
635- $value =~ s / ['"]$// ;
636- return $value =~ / \S / ? $value : ();
637- }
638-
639- sub parse_pkgbuild ($) {
640- ref $_ [0] eq ' HASH' or return ;
641-
642- -f -r -s ' PKGBUILD' or do { warn " [!] Invalid PKGBUILD: $! " ; return };
643-
644- my $pkgbuild = do { local (@ARGV , $/ ) = ' PKGBUILD' ; <> };
645-
646- $pkgbuild =~ s / ^\s *#.*// gm ;
647-
648- while (
649- $pkgbuild =~ m {
650- ^\h * # at the beginning of line
651- (\w +) # capturing word key (e.g.: pkgname)
652- \h *=\h * # optional horizontal space around the '='
653- ( # capturing value
654- \( .*?\) # multi line values // e.g.: key=('value1' \n 'value2')
655- (?= # start of look-ahead
656- \s * # there may be some space //
657- (?:\# (?-s:.*))? # and an optional comment // e.g.: key=('test'); # comm
658- (?:\R |;|\z ) # and a newline or end of the string //
659- ) # end of look-ahead
660- | # OR
661- (?-s:.*) # a single value (e.g.: 'value')
662- ) # end of capture
663- } smgx
664- ) {
665- my $key = $1 ;
666- chomp (my $value = $2 );
667-
668- next if exists $_ [0]-> {pkgbuild }{$key };
669- $key = strip_space($key );
670-
671- if ($value =~ s ~\$\{ ?(\w +)\} ?~ $_ [0]->{pkgbuild}{$1 } // "\$ $1 "~ gse ) {
672- say " Replaced VALUE: $value " if $lconfig {debug };
673- }
674-
675- $value =~ s /\s *;+\s *\z // ;
676- $_ [0]-> {pkgbuild }{$key } = parse_quoted_words($value );
677- }
678-
679- return 1;
680- }
681-
682621sub get_tgz_package ($$) {
683622 my ($url , $output ) = @_ ;
684623 if ($lconfig {overwrite } or not -e $output or -z _) {
@@ -699,6 +638,7 @@ sub get_package_tarball ($$) {
699638 return ;
700639 }
701640
641+ $info -> {resultcount } > 0 or return ;
702642 $info = {results => $info -> {results }[0]};
703643
704644 my $tgz_file = catfile($path , basename($info -> {results }{URLPath }));
@@ -767,31 +707,33 @@ sub absolute_deps ($) {
767707}
768708
769709sub show_info ($) {
770- my ($info ) = @_ ;
710+ my ($data ) = @_ ;
711+
712+ ref ($data -> {results }) eq ' HASH' or return ;
771713
772- return if ref $info -> {results } ne ' HASH ' ;
714+ my $info = $data -> {results };
773715
774716 say map { sprintf $c {bold } . $_ -> [0], $c {reset } . $_ -> [1] }
775- [" Name : %s \n " , " $c {bold}$info ->{results}{ Name}$c {reset}" ],
776- [" Version : %s \n " , $info -> {results }{ Version } // ' Unknown' ],
777- [" Maintainer : %s \n " , $info -> {results }{ Maintainer } // " $c {bred}None$c {reset}" ],
778- [" URL : %s \n " , indent_array(array_ref_or_string( $info -> {pkgbuild }{ url })) ],
779- [" AUR URL : %s \n " , sprintf ($lconfig {aur_package_id_url }, $info -> {results }{ ID })],
780- [" Licenses : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ license }))],
781- [" Votes : %s \n " , $info -> {results }{ NumVotes }],
782- [" Popularity : %s \n " , $info -> {results }{ Popularity }],
783- [" Installed : %s \n " , package_is_installed($info -> {results }{ Name }) ? ' Yes' : ' No' ],
784- [" Out Of Date : %s \n " , $info -> {results }{ OutOfDate } ? " $c {bred}Yes$c {reset}" : ' No' ],
785- [" Groups : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ groups }))],
786- [" Depends On : %s \n " , indent_array(map { absolute_deps($_ ) } array_ref_or_string($info -> {pkgbuild }{ depends }))],
787- [" Make Deps : %s \n " , indent_array(map { absolute_deps($_ ) } array_ref_or_string($info -> {pkgbuild }{ makedepends }))],
788- [" Optional Deps : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ optdepends }))],
789- [" Provides : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ provides }))],
790- [" Conflicts With : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ conflicts }))],
791- [" Replaces : %s \n " , indent_array(array_ref_or_string($info -> {pkgbuild }{ replaces }))],
792- [" Architecture : %s \n " , indent_array(array_ref_or_string( $info -> {pkgbuild }{ arch })) ],
793- [" Last Update : %s \n " , scalar localtime ($info -> {results }{ LastModified } || $info -> { results } {FirstSubmitted })],
794- [" Description : %s \n " , array_ref_or_string( $info -> {pkgbuild }{ pkgdesc }) ];
717+ [" Name : %s \n " , " $c {bold}$info ->{Name}$c {reset}" ],
718+ [" Version : %s \n " , $info -> {Version } // ' Unknown' ],
719+ [" Maintainer : %s \n " , $info -> {Maintainer } // " $c {bred}None$c {reset}" ],
720+ [" URL : %s \n " , $info -> {URL } ],
721+ [" AUR URL : %s \n " , sprintf ($lconfig {aur_package_id_url }, $info -> {ID })],
722+ [" License : %s \n " , indent_array(array_ref_or_string($info -> {License }))],
723+ [" Votes : %s \n " , $info -> {NumVotes }],
724+ [" Popularity : %s \n " , $info -> {Popularity }],
725+ [" Installed : %s \n " , package_is_installed($info -> {Name }) ? ' Yes' : ' No' ],
726+ [" Out Of Date : %s \n " , $info -> {OutOfDate } ? " $c {bred}Yes$c {reset}" : ' No' ],
727+ [" Depends On : %s \n " , indent_array(map { absolute_deps( $_ ) } array_ref_or_string($info -> {Depends }))],
728+ [" Make Deps : %s \n " , indent_array(map { absolute_deps($_ ) } array_ref_or_string($info -> {MakeDepends }))],
729+ [" Check Deps : %s \n " , indent_array(map { absolute_deps($_ ) } array_ref_or_string($info -> {CheckDepends }))],
730+ [" Optional Deps : %s \n " , indent_array(array_ref_or_string($info -> {OptDepends }))],
731+ [" Provides : %s \n " , indent_array(array_ref_or_string($info -> {Provides }))],
732+ [" Conflicts With : %s \n " , indent_array(array_ref_or_string($info -> {Conflicts }))],
733+ [" Replaces : %s \n " , indent_array(array_ref_or_string($info -> {Replaces }))],
734+ [" Package Base : %s \n " , $info -> {PackageBase } ],
735+ [" Last Update : %s \n " , scalar localtime ($info -> {LastModified } || $info -> {FirstSubmitted })],
736+ [" Description : %s \n " , $info -> {Description } ];
795737
796738 return 1;
797739}
@@ -895,7 +837,10 @@ sub output_file_content ($) {
895837 return 1;
896838}
897839
898- sub edit_text_files () {
840+ sub edit_text_files ($) {
841+ my ($info ) = @_ ;
842+
843+ my $edited = 0;
899844 foreach my $file (sort grep { -f and not -z _ } glob (' *' )) {
900845
901846 next if substr ($file , -1) eq q{ ~} ; # ignore backup (~) files
@@ -911,6 +856,7 @@ sub edit_text_files () {
911856 if ($term -> ask_yn(prompt => " =>> Do you want to edit ${file} ?" , default => ' n' )) {
912857 my $abs_file = rel2abs($file );
913858 system $ENV {EDITOR }, $abs_file ;
859+ $edited ||= 1;
914860
915861 if ($? ) {
916862 warn " [!] $ENV {EDITOR} exited with code: $? \n " ;
@@ -919,6 +865,42 @@ sub edit_text_files () {
919865 }
920866 }
921867
868+ # When PKGBUILD is updated, we have to recompute the dependencies
869+ if ($edited ) {
870+ system ' mksrcinfo' ;
871+
872+ if ($? ) {
873+ warn " [!] mksrcinfo exited with code: $? \n " ;
874+ return ;
875+ }
876+
877+ open (my $fh , ' <:utf8' , ' .SRCINFO' ) or do {
878+ warn " [!] Can't open " . rel2abs(" .SRCINFO" ) . " for reading: $! " ;
879+ return ;
880+ };
881+
882+ my %data ;
883+ while (defined (my $line = <$fh >)) {
884+ if ($line =~ / ^\s *(\w +)\s *=\s *(.*\S )/ ) {
885+ push @{$data {$1 }}, $2 ;
886+ }
887+ }
888+
889+ my %pairs = (
890+ Depends => ' depends' ,
891+ License => ' license' ,
892+ MakeDepends => ' makedepends' ,
893+ OptDepends => ' optdepends' ,
894+ Provides => ' provides' ,
895+ Conflicts => ' conflicts' ,
896+ CheckDepends => ' checkdepends' ,
897+ );
898+
899+ while (my ($key1 , $key2 ) = each %pairs ) {
900+ $info -> {results }{$key1 } = $data {$key2 };
901+ }
902+ }
903+
922904 return 1;
923905}
924906
@@ -1024,8 +1006,7 @@ sub install_package ($) {
10241006 }
10251007 }
10261008
1027- edit_text_files() if not $lconfig {noedit }; # edit PKGBUILD and other -T files
1028- parse_pkgbuild($info ) or return ;
1009+ edit_text_files($info ) if not $lconfig {noedit }; # edit PKGBUILD and other -T files
10291010
10301011 print " \n " ;
10311012 show_info($info ) or return ;
@@ -1036,14 +1017,10 @@ sub install_package ($) {
10361017 map { absolute_deps($_ ) }
10371018
10381019 # Makedepends
1039- ref $info -> {pkgbuild }{makedepends } eq ' ARRAY'
1040- ? @{$info -> {pkgbuild }{makedepends }}
1041- : $info -> {pkgbuild }{makedepends },
1020+ (exists ($info -> {results }{MakeDepends }) ? @{$info -> {results }{MakeDepends }} : ()),
10421021
10431022 # Depends
1044- ref $info -> {pkgbuild }{depends } eq ' ARRAY'
1045- ? @{$info -> {pkgbuild }{depends }}
1046- : $info -> {pkgbuild }{depends }
1023+ (exists ($info -> {results }{Depends }) ? @{$info -> {results }{Depends }} : ()),
10471024 ) {
10481025
10491026 if (exists $ignored_packages {$dep }) { # next if $dep exists in %ignored_packages
@@ -1346,7 +1323,6 @@ if ($lconfig{S}) { # -S
13461323 !$lconfig {aur } && is_available_in_pacman_repo($pkgname )
13471324 ? execute_pacman_command(0, qw( -Si) , $pkgname )
13481325 : (my $info = get_package_tarball($pkgname , $lconfig {cache_dir }));
1349- parse_pkgbuild($info ) or next ;
13501326 show_info($info );
13511327 }
13521328 }
0 commit comments