scripts/package-metadata.pl: inhibit compile deps on missing build types
authorJo-Philipp Wich <jo@mein.io>
Wed, 26 Jul 2017 22:18:12 +0000 (00:18 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 13 Dec 2017 15:23:39 +0000 (16:23 +0100)
When a package declares a PKG_BUILD_DEPENDENCY or HOST_BUILD_DEPENDENCY on
a not existing build type, the metadata script will emit a reference to an
unresolvable build target in tmp/.packagedeps, causing the make process to
fail hard in a way not catchable by the IGNORE_ERRORS mechanism.

In a situation where a package "test-a" declares a build dependency
"PKG_BUILD_DEPENDS:=test-b/host" while the Makefile of "test-b" does not
implement a HostBuild, make fails with an unrecoverable error in the form:

    make[1]: Entering directory '...'
    make[1]: *** No rule to make target 'package/test-b/host/compile',
                 needed by 'package/test-a/compile'.  Stop.
    make[1]: Leaving directory '...'
    .../toplevel.mk:200: recipe for target 'package/test-a/compile' failed
    make: *** [package/test-a/compile] Error 2

Extend the metadata generation script to catch such unresolved references
and emit a visable warning upon detection.

After this change, the script will emit a warning similar to:

    WARNING: Makefile "package/test-a/Makefile" has a build dependency on
    "test-b/host" but "package/test-b/Makefile" does not implement a
    "host" build type

Fixes a global build cluster outage which occured after the "python-cffi"
feed package removed its HostBuild which the "python-cryptography" package
build-depended on.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit bf5d32af2a675f7577b388b5eef2a11e6ce042eb)

scripts/package-metadata.pl

index 2da32c770ef3333bfcc18922ede556f9734510c7..c49d132912828531c7125787f4f53d7130323123 100755 (executable)
@@ -460,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;
@@ -499,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};
@@ -521,7 +530,17 @@ 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;
+                                       }
+                                       unless ($pkg->{src} ne $pkg_dep->{sec}.$suffix) {
+                                               warn sprintf "WARNING: Makefile '%s' has a build dependency on itself\n",
+                                                       $pkg->{makefile};
+                                               next;
+                                       }
+                                       $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
                                } elsif (defined($srcpackage{$dep})) {
                                        $idx = $subdir{$dep}.$dep;
                                }
@@ -573,7 +592,7 @@ ifndef DUMP_TARGET_DB
        ( \\
 $cmds \\
        ) > \$@
-       
+
 ifneq (\$(IMAGEOPT)\$(CONFIG_IMAGEOPT),)
   package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
 endif