scripts/package-metadata.pl: remove broken detection of self-dependencies
[openwrt/openwrt.git] / scripts / package-metadata.pl
index 92c989d3a292416e548cd3e306471ecb29f3da5e..fbd458bf2a1e8c965eeb627b57dfd8efb2494fe1 100755 (executable)
@@ -176,12 +176,25 @@ sub mconf_depends {
                next if $package{$depend} and $package{$depend}->{buildonly};
                if ($flags =~ /\+/) {
                        if ($vdep = $package{$depend}->{vdepends}) {
-                               my @vdeps = @$vdep;
-                               $depend = shift @vdeps;
+                               my @vdeps;
+                               $depend = undef;
+
+                               foreach my $v (@$vdep) {
+                                       if ($package{$v} && $package{$v}->{variant_default}) {
+                                               $depend = $v;
+                                       } else {
+                                               push @vdeps, $v;
+                                       }
+                               }
+
+                               if (!$depend) {
+                                       $depend = shift @vdeps;
+                               }
+
                                if (@vdeps > 1) {
-                                       $condition = '!('.join("||", map { "PACKAGE_".$_ } @vdeps).')';
+                                       $condition = ($condition ? "$condition && " : '') . '!('.join("||", map { "PACKAGE_".$_ } @vdeps).')';
                                } elsif (@vdeps > 0) {
-                                       $condition = '!PACKAGE_'.$vdeps[0];
+                                       $condition = ($condition ? "$condition && " : '') . '!PACKAGE_'.$vdeps[0];
                                }
                        }
 
@@ -193,17 +206,22 @@ sub mconf_depends {
 
                        $m = "select";
                        next if $only_dep;
+
+                       $flags =~ /@/ or $depend = "PACKAGE_$depend";
                } else {
                        if ($vdep = $package{$depend}->{vdepends}) {
                                $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
+                       } else {
+                               $flags =~ /@/ or $depend = "PACKAGE_$depend";
                        }
                }
-               $flags =~ /@/ or $depend = "PACKAGE_$depend";
+
                if ($condition) {
                        if ($m =~ /select/) {
                                next if $depend eq $condition;
                                $depend = "$depend if $condition";
                        } else {
+                               next if $dep->{"$depend if $condition"};
                                $depend = "!($condition) || $depend" unless $dep->{$condition} eq 'select';
                        }
                }
@@ -272,6 +290,7 @@ sub print_package_config_category($) {
                        print "menu \"$menu\"\n";
                }
                foreach my $pkg (@pkgs) {
+                       next if $pkg->{ignore};
                        my $title = $pkg->{name};
                        my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
                        if ($c > 0) {
@@ -347,7 +366,7 @@ sub print_package_overrides() {
        keys %overrides > 0 or return;
        print "\tconfig OVERRIDE_PKGS\n";
        print "\t\tstring\n";
-       print "\t\tdefault \"".join(" ", keys %overrides)."\"\n\n";
+       print "\t\tdefault \"".join(" ", sort keys %overrides)."\"\n\n";
 }
 
 sub gen_package_config() {
@@ -441,20 +460,27 @@ sub gen_package_mk() {
                        next unless $pkg->{"builddepends/$type"};
                        foreach my $dep (@{$pkg->{"builddepends/$type"}}) {
                                my $suffix = "";
+                               my $deptype = "";
                                my $condition;
 
                                if ($dep =~ /^(.+):(.+)/) {
                                        $condition = $1;
                                        $dep = $2;
                                }
-                               if ($dep =~ /^(.+)(\/.+)/) {
+                               if ($dep =~ /^(.+)\/(.+)/) {
                                        $dep = $1;
-                                       $suffix = $2;
+                                       $deptype = $2;
+                                       $suffix = "/$2";
                                }
 
                                my $idx = "";
                                my $pkg_dep = $package{$dep};
                                if (defined($pkg_dep) && defined($pkg_dep->{src})) {
+                                       unless (!$deptype || grep { $_ eq $deptype } @{$pkg_dep->{buildtypes}}) {
+                                               warn sprintf "WARNING: Makefile '%s' has a %s build dependency on '%s/%s' but '%s' does not implement a '%s' build type\n",
+                                                       $pkg->{makefile}, $type, $pkg_dep->{src}, $deptype, $pkg_dep->{makefile}, $deptype;
+                                               next;
+                                       }
                                        $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
                                } elsif (defined($srcpackage{$dep})) {
                                        $idx = $subdir{$dep}.$dep;
@@ -480,14 +506,16 @@ sub gen_package_mk() {
                        my $condition;
                        my $prefix = "";
                        my $suffix = "";
+                       my $deptype = "";
 
                        if ($deps =~ /^(.+):(.+)/) {
                                $condition = $1;
                                $deps = $2;
                        }
-                       if ($deps =~ /^(.+)(\/.+)/) {
+                       if ($deps =~ /^(.+)\/(.+)/) {
                                $deps = $1;
-                               $suffix = $2;
+                               $deptype = $2;
+                               $suffix = "/$2";
                        }
 
                        my $pkg_dep = $package{$deps};
@@ -502,7 +530,12 @@ sub gen_package_mk() {
                        foreach my $dep (@deps) {
                                $pkg_dep = $package{$deps};
                                if (defined $pkg_dep->{src}) {
-                                       ($pkg->{src} ne $pkg_dep->{src}.$suffix) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
+                                       unless (!$deptype || grep { $_ eq $deptype } @{$pkg_dep->{buildtypes}}) {
+                                               warn sprintf "WARNING: Makefile '%s' has a build dependency on '%s/%s' but '%s' does not implement a '%s' build type\n",
+                                                       $pkg->{makefile}, $pkg_dep->{src}, $deptype, $pkg_dep->{makefile}, $deptype;
+                                               next;
+                                       }
+                                       $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
                                } elsif (defined($srcpackage{$dep})) {
                                        $idx = $subdir{$dep}.$dep;
                                }
@@ -554,7 +587,7 @@ ifndef DUMP_TARGET_DB
        ( \\
 $cmds \\
        ) > \$@
-       
+
 ifneq (\$(IMAGEOPT)\$(CONFIG_IMAGEOPT),)
   package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
 endif
@@ -613,6 +646,16 @@ sub gen_version_filtered_list() {
        }
 }
 
+sub gen_usergroup_list() {
+       parse_package_metadata($ARGV[0]) or exit 1;
+       for my $name (keys %usernames) {
+               print "user $name $usernames{$name}{id} $usernames{$name}{makefile}\n";
+       }
+       for my $name (keys %groupnames) {
+               print "group $name $groupnames{$name}{id} $groupnames{$name}{makefile}\n";
+       }
+}
+
 sub parse_command() {
        GetOptions("ignore=s", \@ignore);
        my $cmd = shift @ARGV;
@@ -624,6 +667,7 @@ sub parse_command() {
                /^subdirs$/ and return gen_package_subdirs();
                /^license$/ and return gen_package_license(0);
                /^licensefull$/ and return gen_package_license(1);
+               /^usergroup$/ and return gen_usergroup_list();
                /^version_filter$/ and return gen_version_filtered_list();
        }
        die <<EOF
@@ -635,6 +679,7 @@ Available Commands:
        $0 subdirs [file]                       Package subdir information in makefile format
        $0 license [file]                       Package license information
        $0 licensefull [file]                   Package license information (full list)
+       $0 usergroup [file]                     Package usergroup allocation list
        $0 version_filter [patchver] [list...]  Filter list of version tagged strings
 
 Options: