From 8edb1689a3de314a6034cca2e0dea01b342955bf Mon Sep 17 00:00:00 2001
From: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Date: Wed, 2 Oct 2019 17:42:35 +0200
Subject: [PATCH] buildscript: Remove target binaries from build dir before
 building
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

So far, if build fails, but images from last successful build are
present in OpenWrt build directory (build/bin/targets/...), those
are copied even after unsuccessful build.

This results in the old images being copied to the bin folder and
being labelled with the new firmware revision. (!)
As our error check also only looks at whether images are there,
the image copying process will look like a success.

This patch deletes old images of the target/subtarget to be built,
so that the copy-firmware step will find nothing if the build
stop to early.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Fabian Bläse <fabian@blaese.de>
---
 buildscript | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/buildscript b/buildscript
index c2de5759..81974a97 100755
--- a/buildscript
+++ b/buildscript
@@ -212,6 +212,8 @@ prebuild() {
 build() {
     prebuild
 
+    rm_firmware
+
     opath=$(pwd)
     cd "$target"
     cpus=$(grep -c processor /proc/cpuinfo)
@@ -269,6 +271,12 @@ config() {
     cd "$opath"
 }
 
+rm_firmware() {
+    [ -n "$subtarget" ] || subtarget="generic"
+
+    rm -rf $target/bin/targets/${chipset}/${subtarget}
+}
+
 cp_firmware() {
     [ -n "$subtarget" ] || subtarget="generic"
 
-- 
GitLab