metadata: interate over source packages when generating Makefile
authorMatthias Schiffer <mschiffer@universe-factory.net>
Sat, 6 Jan 2018 16:12:03 +0000 (17:12 +0100)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Sat, 13 Jan 2018 18:54:44 +0000 (19:54 +0100)
All build dependencies are between source packages. Interating over source
rather than binary packages simplifies parts of the code and prepares
further improvement.

As a side effect, this changes the implicit default variant of a few
packages (the first defined is used now instead of the lexicographically
first).

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
scripts/metadata.pm
scripts/package-metadata.pl

index 8cc7530a1d25b251c33a504028cda14241f527d1..9d6f3216d151a038f634d8d110b47057f3aadb16 100644 (file)
@@ -213,6 +213,7 @@ sub parse_package_metadata($) {
                        $subdir =~ s/^package\///;
                        $subdir{$src} = $subdir;
                        $srcpackage{$src} = {
+                               makefile => $makefile,
                                packages => [],
                                buildtypes => [],
                                builddepends => [],
index 97b57c65eb8d5f7a556c3dc48ef7a685bb5d4d76..1031e11460e4050a0bf4d049b1efb7bf77ffba38 100755 (executable)
@@ -414,36 +414,45 @@ sub get_conditional_dep($$) {
 sub gen_package_mk() {
        my %conf;
        my %dep;
-       my %done;
        my $line;
 
        parse_package_metadata($ARGV[0]) or exit 1;
-       foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
-               my $config;
-               my $pkg = $package{$name};
-               my $src = $srcpackage{$pkg->{src}};
+       foreach my $srcname (sort {uc($a) cmp uc($b)} keys %srcpackage) {
+               my $src = $srcpackage{$srcname};
+               my $path = $subdir{$srcname}.$srcname;
+               my $variant_default;
                my @srcdeps;
 
-               next if defined $pkg->{vdepends};
+               foreach my $pkg (@{$src->{packages}}) {
+                       next if defined $pkg->{vdepends};
+
+                       my $config = '';
+                       $config = "\$(CONFIG_PACKAGE_$pkg->{name})" unless $pkg->{buildonly};
+
+                       $pkg->{prereq} and print "prereq-$config += $path\n";
+
+                       next if $pkg->{buildonly};
+
+                       print "package-$config += $path\n";
 
-               $config = "\$(CONFIG_PACKAGE_$name)";
-               if ($config) {
-                       $pkg->{buildonly} and $config = "";
-                       print "package-$config += $pkg->{subdir}$pkg->{src}\n";
                        if ($pkg->{variant}) {
-                               if (!defined($done{$pkg->{src}}) or $pkg->{variant_default}) {
-                                       print "\$(curdir)/$pkg->{subdir}$pkg->{src}/default-variant := $pkg->{variant}\n";
+                               if (!defined($variant_default) or $pkg->{variant_default}) {
+                                       $variant_default = $pkg->{variant};
                                }
-                               print "\$(curdir)/$pkg->{subdir}$pkg->{src}/variants += \$(if $config,$pkg->{variant})\n"
+                               print "\$(curdir)/$path/variants += \$(if $config,$pkg->{variant})\n";
                        }
-                       $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
                }
 
-               next if $done{$pkg->{src}};
-               $done{$pkg->{src}} = 1;
+               if (defined($variant_default)) {
+                       print "\$(curdir)/$path/default-variant := $variant_default\n";
+               }
+
+               unless (grep {!$_->{buildonly}} @{$src->{packages}}) {
+                       print "package- += $path\n";
+               }
 
                if (@{$src->{buildtypes}} > 0) {
-                       print "buildtypes-$pkg->{subdir}$pkg->{src} = ".join(' ', @{$src->{buildtypes}})."\n";
+                       print "buildtypes-$path = ".join(' ', @{$src->{buildtypes}})."\n";
                }
 
                foreach my $dep (@{$src->{builddepends}}, map { @{$_->{depends}} } @{$src->{packages}}) {
@@ -477,7 +486,7 @@ sub gen_package_mk() {
                                if (defined($pkg_dep) && defined($pkg_dep->{src})) {
                                        unless (!$deptype || grep { $_ eq $deptype } @{$srcpackage{$pkg_dep->{src}}{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;
+                                                       $src->{makefile}, $type, $pkg_dep->{src}, $deptype, $pkg_dep->{makefile}, $deptype;
                                                next;
                                        }
                                        $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
@@ -494,7 +503,7 @@ sub gen_package_mk() {
                        }
                        my $depline = join(" ", sort keys %deplines);
                        if ($depline) {
-                               $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/$type/compile += $depline\n";
+                               $line .= "\$(curdir)/$path/$type/compile += $depline\n";
                        }
                }
 
@@ -531,7 +540,7 @@ sub gen_package_mk() {
                                if (defined $pkg_dep->{src}) {
                                        unless (!$deptype || grep { $_ eq $deptype } @{$srcpackage{$pkg_dep->{src}}{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;
+                                                       $src->{makefile}, $pkg_dep->{src}, $deptype, $pkg_dep->{makefile}, $deptype;
                                                next;
                                        }
                                        $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
@@ -543,17 +552,17 @@ sub gen_package_mk() {
                                        $idx .= $suffix;
 
                                        my $depline;
-                                       next if $pkg->{src} eq $pkg_dep->{src}.$suffix;
-                                       next if $dep{$condition.":".$pkg->{src}."->".$idx};
-                                       next if $dep{$pkg->{src}."->($dep)".$idx} and $pkg_dep->{vdepends};
+                                       next if $srcname eq $pkg_dep->{src}.$suffix;
+                                       next if $dep{$condition.":".$srcname."->".$idx};
+                                       next if $dep{$srcname."->($dep)".$idx} and $pkg_dep->{vdepends};
                                        my $depstr;
 
                                        if ($pkg_dep->{vdepends}) {
                                                $depstr = "\$(if \$(CONFIG_PACKAGE_$dep),\$(curdir)/$idx/compile)";
-                                               $dep{$pkg->{src}."->($dep)".$idx} = 1;
+                                               $dep{$srcname."->($dep)".$idx} = 1;
                                        } else {
                                                $depstr = "\$(curdir)/$idx/compile";
-                                               $dep{$pkg->{src}."->".$idx} = 1;
+                                               $dep{$srcname."->".$idx} = 1;
                                        }
                                        $depline = get_conditional_dep($condition, $depstr);
                                        if ($depline) {
@@ -564,7 +573,7 @@ sub gen_package_mk() {
                }
                my $depline = join(" ", sort keys %deplines);
                if ($depline) {
-                       $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
+                       $line .= "\$(curdir)/$path/compile += $depline\n";
                }
        }