From 3d1860e092a6e5bae855b30bcc1fedbf4b6b2690 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Fri, 27 Jan 2017 01:30:47 +0100
Subject: [PATCH] build: allow using DEVICES variable for
 sysupgrade_image/factory_image images

Setting DEVICES will also suppress cleaning the package directory,
improving incremental build speed.
---
 scripts/clean_output.sh        |  2 +-
 scripts/common.inc.sh          | 30 +++++++++++++-----------------
 scripts/copy_output.sh         |  2 +-
 scripts/target_config_check.sh | 10 ++++++++++
 4 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/scripts/clean_output.sh b/scripts/clean_output.sh
index d9b6e903a..f6c967c52 100755
--- a/scripts/clean_output.sh
+++ b/scripts/clean_output.sh
@@ -17,4 +17,4 @@ fi
 rm -f "lede/bin/targets/${LEDE_BINDIR}"/* 2>/dev/null || true
 
 # Full builds will output the "packages" directory, so clean up first
-[ "$has_devices" ] || rm -rf "lede/bin/targets/${LEDE_BINDIR}/packages"
+[ "$DEVICES" ] || rm -rf "lede/bin/targets/${LEDE_BINDIR}/packages"
diff --git a/scripts/common.inc.sh b/scripts/common.inc.sh
index 59bb8ad3e..ac879ada4 100644
--- a/scripts/common.inc.sh
+++ b/scripts/common.inc.sh
@@ -31,36 +31,32 @@ sysupgrade() {
 }
 
 
-if [ "$DEVICES" ]; then
-	has_devices=1
-else
-	has_devices=
-fi
+unknown_devices="$DEVICES"
 
 want_device() {
-	[ "$has_devices" ] || return 0
+	[ "$DEVICES" ] || return 0
 
 	local new_devices=''
-	local ret=1
 
-	for device in $DEVICES; do
-		if [ "$device" = "$1" ]; then
-			ret=0
-		else
+	for device in $unknown_devices; do
+		if [ "$device" != "$1" ]; then
 			new_devices="${new_devices:+${new_devices} }$device"
 		fi
 	done
+	unknown_devices=$new_devices
 
-	DEVICES=$new_devices
+	for device in $DEVICES; do
+		if [ "$device" = "$1" ]; then
+			return 0
+		fi
+	done
 
-	return $ret
+	return 1
 }
 
 check_devices() {
-	[ "$has_devices" ] || return 0
-
-	if [ "$DEVICES" ]; then
-		echo "Error: unknown devices given: $DEVICES" >&2
+	if [ "$unknown_devices" ]; then
+		echo "Error: unknown devices given: ${unknown_devices}" >&2
 		exit 1
 	fi
 }
diff --git a/scripts/copy_output.sh b/scripts/copy_output.sh
index 9f19a80cb..94fa55fa4 100755
--- a/scripts/copy_output.sh
+++ b/scripts/copy_output.sh
@@ -149,7 +149,7 @@ sysupgrade() {
 . targets/"$1"; copy
 
 # Copy opkg repo
-if [ -z "$has_devices" ]; then
+if [ -z "$DEVICES" ]; then
 	rm -f "$GLUON_PACKAGEDIR"/*/"$LEDE_BINDIR"/*
 	rmdir -p "$GLUON_PACKAGEDIR"/*/"$LEDE_BINDIR" 2>/dev/null || true
 	mkdir -p "${GLUON_PACKAGEDIR}/${PACKAGE_PREFIX}/${LEDE_BINDIR}"
diff --git a/scripts/target_config_check.sh b/scripts/target_config_check.sh
index 030ba62e5..5a6c80353 100755
--- a/scripts/target_config_check.sh
+++ b/scripts/target_config_check.sh
@@ -67,6 +67,16 @@ device() {
 	done
 }
 
+factory_image() {
+	output="$1"
+	want_device "${output}" || return 0
+}
+
+sysupgrade_image() {
+	output="$1"
+	want_device "${output}" || return 0
+}
+
 packages() {
 	if [ "${output}" ]; then
 		want_device "${output}" || return 0
-- 
GitLab