metadata: remove redundant fields from package hash
[openwrt/openwrt.git] / scripts / feeds
index 045835c0cc3a09436c4684e403041e0dcf5ff59d..4595c824a4b7c4836fdb1b67472dc476101e3d45 100755 (executable)
@@ -9,7 +9,8 @@ use strict;
 use Cwd 'abs_path';
 
 chdir "$FindBin::Bin/..";
-$ENV{TOPDIR}=getcwd();
+$ENV{TOPDIR} //= getcwd();
+chdir $ENV{TOPDIR};
 $ENV{GIT_CONFIG_PARAMETERS}="'core.autocrlf=false'";
 $ENV{GREP_OPTIONS}="";
 
@@ -129,20 +130,22 @@ my %update_method = (
                'init_branch'   => "git clone --depth 1 --branch '%s' '%s' '%s'",
                'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
                'update'        => "git pull --ff",
+               'update_force'  => "git pull --ff || (git reset --hard HEAD; git pull --ff; exit 1)",
                'controldir'    => ".git",
-               'revision'      => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
+               'revision'      => "git rev-parse --short HEAD | tr -d '\n'"},
        'src-git-full' => {
                'init'          => "git clone '%s' '%s'",
                'init_branch'   => "git clone --branch '%s' '%s' '%s'",
                'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
                'update'        => "git pull --ff",
+               'update_force'  => "git pull --ff || (git reset --hard HEAD; git pull --ff; exit 1)",
                'controldir'    => ".git",
-               'revision'      => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
+               'revision'      => "git rev-parse --short HEAD | tr -d '\n'"},
        'src-gitsvn' => {
                'init'  => "git svn clone -r HEAD '%s' '%s'",
                'update'        => "git svn rebase",
                'controldir'    => ".git",
-               'revision'      => "git show --abbrev-commit HEAD | head -n 1 | cut -d ' ' -f 2 | tr -d '\n'"},
+               'revision'      => "git rev-parse --short HEAD | tr -d '\n'"},
        'src-bzr' => {
                'init'          => "bzr checkout --lightweight '%s' '%s'",
                'update'        => "bzr update",
@@ -160,11 +163,12 @@ my %update_method = (
 # src-git: pull broken
 # src-cpy: broken if `basename $src` != $name
 
-sub update_feed_via($$$$) {
+sub update_feed_via($$$$$) {
        my $type = shift;
        my $name = shift;
        my $src = shift;
        my $relocate = shift;
+       my $force = shift;
 
        my $m = $update_method{$type};
        my $localpath = "./feeds/$name";
@@ -185,7 +189,11 @@ sub update_feed_via($$$$) {
        } elsif ($m->{'init_commit'} and $commit) {
                # in case git hash has been provided don't update the feed
        } else {
-               system("cd '$safepath'; $m->{'update'}") == 0 or return 1;
+               my $update_cmd = $m->{'update'};
+               if ($force && exists $m->{'update_force'}) {
+                       $update_cmd = $m->{'update_force'};
+               }
+               system("cd '$safepath'; $update_cmd") == 0 or return 1;
        }
 
        return 0;
@@ -333,7 +341,7 @@ sub list {
                        my $localpath = "./feeds/$feed->[1]";
                        my $m = $update_method{$feed->[0]};
                        my $revision;
-                       if( !$m->{'revision'} ) {
+                       if (!-d "$localpath" || !$m->{'revision'}) {
                                $revision = "X";
                        }
                        elsif( $m->{'controldir'} && -d "$localpath/$m->{'controldir'}" ) {
@@ -354,7 +362,7 @@ sub list {
                                printf "%s %s %s\n", $feed->[0], $feed->[1], $uri;
                        }
                        else {
-                               printf "\%-8s \%-8s \%-8s \%s\n", $feed->[1], $feed->[0], $revision, join(", ", @{$feed->[2]});
+                               printf "\%-10s \%-8s \%-8s \%s\n", $feed->[1], $feed->[0], $revision, join(", ", @{$feed->[2]});
                        }
                }
                return 0;
@@ -365,10 +373,14 @@ sub list {
        return 0;
 }
 
+# TODO: do_install_package etc. should deal with source packages rather
+# than binary packages
 sub do_install_package($$) {
        my $feed = shift;
        my $pkg = shift;
-       my $path = $pkg->{makefile};
+
+       my $path;
+       $pkg->{src} and $path = $pkg->{src}{makefile};
 
        if($path) {
                $path =~ s/\/Makefile$//;
@@ -486,7 +498,7 @@ sub install_package {
                warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
                return 0;
        };
-       my $src = $pkg->{src};
+       my $src = $pkg->{src}{name};
        my $type = $feed->[0];
        $src or $src = $name;
 
@@ -517,15 +529,17 @@ sub install_package {
        };
 
        # install all dependencies referenced from the source package
-       foreach my $vpkg (@{$feed_src->{$src}}) {
-               foreach my $dep (@{$vpkg->{depends}}, @{$vpkg->{builddepends}}, @{$vpkg->{"builddepends/host"}}) {
-                       next if $dep =~ /@/;
-                       $dep =~ s/^\+//;
-                       $dep =~ s/^.+://;
-                       $dep =~ s/\/.+$//;
-                       next unless $dep;
-                       install_package($feed, $dep, 0) == 0 or $ret = 1;
-               }
+       foreach my $dep (
+               @{$feed_src->{$src}{builddepends}},
+               @{$feed_src->{$src}{"builddepends/host"}},
+               map { @{$_->{depends}} } @{$feed_src->{$src}{packages}}
+       ) {
+               next if $dep =~ /@/;
+               $dep =~ s/^\+//;
+               $dep =~ s/^.+://;
+               $dep =~ s/\/.+$//;
+               next unless $dep;
+               install_package($feed, $dep, 0) == 0 or $ret = 1;
        }
 
        return $ret;
@@ -653,7 +667,7 @@ sub uninstall {
                                warn "WARNING: $name not installed\n";
                                next;
                        };
-                       $pkg->{src} and $name = $pkg->{src};
+                       $pkg->{src} and $name = $pkg->{src}{name};
                        warn "Uninstalling package '$name'\n";
                        system("rm -f ./package/feeds/*/$name");
                        $uninstall = 1;
@@ -663,13 +677,15 @@ sub uninstall {
        return 0;
 }
 
-sub update_feed($$$$)
+sub update_feed($$$$$)
 {
        my $type=shift;
        my $name=shift;
        my $src=shift;
        my $perform_update=shift;
+       my $force_update=shift;
        my $force_relocate=update_location( $name, "@$src" );
+       my $rv=0;
 
        if( $force_relocate ) {
                warn "Source of feed $name has changed, replacing copy\n";
@@ -682,9 +698,16 @@ sub update_feed($$$$)
                my $failed = 1;
                foreach my $feedsrc (@$src) {
                        warn "Updating feed '$name' from '$feedsrc' ...\n";
-                       next unless update_feed_via($type, $name, $feedsrc, $force_relocate) == 0;
+                       if (update_feed_via($type, $name, $feedsrc, $force_relocate, $force_update) != 0) {
+                               if ($force_update) {
+                                       $rv=1;
+                                       $failed=0;
+                                       warn "failed, ignore.\n";
+                                       next;
+                               }
+                               last;
+                       }
                        $failed = 0;
-                       last;
                }
                $failed and do {
                        warn "failed.\n";
@@ -696,7 +719,7 @@ sub update_feed($$$$)
                warn "failed.\n";
                return 1;
        };
-       return 0;
+       return $rv;
 }
 
 sub update {
@@ -708,7 +731,7 @@ sub update {
        $ENV{SCAN_COOKIE} = $$;
        $ENV{OPENWRT_VERBOSE} = 's';
 
-       getopts('ahi', \%opts);
+       getopts('ahif', \%opts);
 
        if ($opts{h}) {
                usage();
@@ -728,7 +751,7 @@ sub update {
        if ( ($#ARGV == -1) or $opts{a}) {
                foreach my $feed (@feeds) {
                        my ($type, $name, $src) = @$feed;
-                       update_feed($type, $name, $src, $perform_update) == 0 or $failed=1;
+                       update_feed($type, $name, $src, $perform_update, $opts{f}) == 0 or $failed=1;
                }
        } else {
                while ($feed_name = shift @ARGV) {
@@ -737,7 +760,7 @@ sub update {
                                if($feed_name ne $name) {
                                        next;
                                }
-                               update_feed($type, $name, $src, $perform_update) == 0 or $failed=1;
+                               update_feed($type, $name, $src, $perform_update, $opts{f}) == 0 or $failed=1;
                        }
                }
        }
@@ -795,6 +818,7 @@ Commands:
        Options:
            -a :           Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
            -i :           Recreate the index only. No feed update from repository is performed.
+           -f :           Force updating feeds even if there are changed, uncommitted files.
 
        clean:             Remove downloaded/generated files.