metadata: compile dependencies only when the package is selected build-deps
authorYousong Zhou <yszhou4tech@gmail.com>
Wed, 28 Feb 2018 03:27:42 +0000 (11:27 +0800)
committerYousong Zhou <yszhou4tech@gmail.com>
Fri, 2 Mar 2018 09:43:03 +0000 (17:43 +0800)
This is intended to reduce build time for situations like the following
where python and python-six and their dependencies could still be built
as long as any subpackage within the srcpackage was selected regardless
of the selection state of openvswitch-python

    define Package/openvswitch-python
      ...
      DEPENDS:=+python +python-six
    endef

Previously we work around this by specifying the dependency as
+PACKAGE_openvswitch-python:python, which is unintuitive

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
scripts/package-metadata.pl

index 53bb45a62c83d628e62dc3857eb8d9d48d3b9ba3..b82715441b20556ac1e330f72ee38ae2d93d9d11 100755 (executable)
@@ -382,6 +382,7 @@ sub gen_package_mk() {
                my %deplines = ('' => {});
 
                foreach my $pkg (@{$src->{packages}}) {
+                       my @pkgdeplines;
                        foreach my $dep (@{$pkg->{depends}}) {
                                next if ($dep =~ /@/);
 
@@ -410,10 +411,17 @@ sub gen_package_mk() {
                                        }
                                        my $depline = get_conditional_dep($condition, $depstr);
                                        if ($depline) {
-                                               $deplines{''}{$depline}++;
+                                               push @pkgdeplines, $depline;
                                        }
                                }
                        }
+                       if (@pkgdeplines) {
+                               my $depstr = join(' ', @pkgdeplines);
+                               if ($depstr) {
+                                       my $depline = get_conditional_dep('PACKAGE_'.$pkg->{name}, $depstr);
+                                       $deplines{''}{$depline}++;
+                               }
+                       }
 
                        my $config = '';
                        $config = sprintf '$(CONFIG_PACKAGE_%s)', $pkg->{name} unless $pkg->{buildonly};
@@ -486,8 +494,7 @@ sub gen_package_mk() {
                }
 
                foreach my $suffix (sort keys %deplines) {
-                       my $depline = join(" ", sort keys %{$deplines{$suffix}});
-                       if ($depline) {
+                       for my $depline (sort keys %{$deplines{$suffix}}) {
                                $line .= sprintf "\$(curdir)/%s/compile += %s\n", $src->{path}.$suffix, $depline;
                        }
                }