From f9d02300b19db45fbc765a6b4fdf9e5c3e8ffa9a Mon Sep 17 00:00:00 2001
From: Jens Nolte <jens@nightmarestudio.de>
Date: Thu, 11 Jun 2020 04:14:06 +0200
Subject: [PATCH] Adapt build scripts for new project structure

---
 bin/set-device      | 32 +++++++++++++-------------------
 bin/set-environment |  7 +++----
 default.nix         |  2 +-
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/bin/set-device b/bin/set-device
index c036cf0..59c9ab0 100755
--- a/bin/set-device
+++ b/bin/set-device
@@ -1,44 +1,38 @@
-#!/usr/bin/env bash
+#!/usr/bin/env zsh
 
 set -e
+set -u
 
-function print_usage {
+print_usage() {
     echo "Usage: set-device [ DEVICE_NAME | DEVICE_DIR ]"
 }
 
-function list_known_devices {
+list_known_devices() {
     echo "Known devices:"
     ls -1 devices | while read f; do
-        if [[ -d "devices/$f" && -f "devices/$f/device_config.h" && -f "devices/$f/device_main.cpp" ]]; then
+        if [[ -d "devices/$f" ]]; then
             echo "$f"
         fi
     done
 }
 
-function link_device_directory {
-    if [[ "$1" == /* ]]; then
-        DIR="$1"
-    else
-        DIR="../$1"
-    fi
-    echo "Linking main/device to $DIR"
-    rm "main/device" || true
-    ln -s "$DIR" "main/device"
-    touch --no-create "main/device/device_config.h"
-    touch --no-create "main/device/device_main.cpp"
+link_device_directory() {
+    echo "Linking main to $1"
+    ln -snf "$1" "main"
+    touch --no-create main/**/*
 }
 
-if [[ -z "$1" ]]; then
+if [[ $# < 1 ]]; then
     print_usage
     list_known_devices
-elif [[ -f "$1/device_config.h" && -f "$1/device_main.cpp" ]]; then
+elif [[ -d "$1" ]]; then
     echo "Found device in directory $1"
     link_device_directory "$1"
-elif [[ -f "devices/$1/device_config.h" && -f "devices/$1/device_main.cpp" ]]; then
+elif [[ -d "devices/$1" ]]; then
     echo "Found device $1 in devices directory"
     link_device_directory "devices/$1"
 else
-    echo "Cannot find device_config.h and device_main.cpp in one of the following directories:"
+    echo "Cannot find device in one of the following directories:"
     echo "$1"
     echo "devices/$1"
 fi
diff --git a/bin/set-environment b/bin/set-environment
index 15bf6b3..5c3e29e 100755
--- a/bin/set-environment
+++ b/bin/set-environment
@@ -17,10 +17,9 @@ function link_environment {
     else
         TARGET="../$1"
     fi
-    echo "Linking main/environment.h to $TARGET"
-    rm "main/environment.h" || true
-    ln -s "$TARGET" "main/environment.h"
-    touch --no-create "main/environment.h"
+    echo "Linking qthing/environment.h to $TARGET"
+    ln -snf "$TARGET" "qthing/environment.h"
+    touch --no-create "qthing/environment.h"
 }
 
 if [[ -z "$1" ]]; then
diff --git a/default.nix b/default.nix
index fcfaa85..7e5eb07 100644
--- a/default.nix
+++ b/default.nix
@@ -52,7 +52,7 @@ in rec {
 
   shell = pkgs.stdenv.mkDerivation {
     name = "esp-idf-env";
-    buildInputs = qthingDependencies;
+    buildInputs = qthingDependencies ++ [pkgs.zsh];
     shellHook = shellSetup;
   };
 
-- 
GitLab