From 9a507bbe294beab4fd3122b5524e34ab474ef798 Mon Sep 17 00:00:00 2001
From: Lorenzo Pagliai <lorenzo.pagliai@seco.com>
Date: Fri, 24 May 2024 17:10:37 +0200
Subject: [PATCH] [BITBAKE] Handle custom Edgehog distros

In order to handle the scenarios where bitbake needs to compile an
image different from the standard ones we introduce the possibility to
have a custom DISTRO variable value. However, the variable shall follow
the following convention:

* The first part of the string shall indicate the standard Edgehog OS
  distro, i.e. 'things' or 'embedded' as of now
* The second part of the string shall be the custom Edgehog OS image
  distro with at maximum a '-' as a separator, e.g. 'custom-image'
* The two parts of the string shall be separated by a '-'

An example could be 'embedded-custom-image'.
---
 build-pipeline-yocto.yml.jinja2 | 21 +++++++++++++++++----
 docs/manifest-pipeline.md       | 14 +++++++++++++-
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/build-pipeline-yocto.yml.jinja2 b/build-pipeline-yocto.yml.jinja2
index 6bf7c4e..c785188 100644
--- a/build-pipeline-yocto.yml.jinja2
+++ b/build-pipeline-yocto.yml.jinja2
@@ -249,6 +249,11 @@ release:
       {% if distro == 'things' %}
         {% set recipe = "seco-image-edgehog" %}
         {% set image = "edgehog-things-image" %}
+      {% elif 'things-' in distro %}
+        {% set parts = distro.split('-') %}
+        {% set recipe = parts[1:]|join('-') %}
+        {% set image = parts[1:]|join('-') %}
+
 #----------------------------------------------------
 # Edgehog-build-{{ machine }}-{{ distro }}
 #----------------------------------------------------
@@ -302,12 +307,20 @@ test-{{ machine }}-{{ distro }}:
         {% set recipe = "seco-image-edgehog-full" %}
         {% set image = "edgehog-embedded-full-image" %}
         {% set testing = true %}
+      {% else %}
+        {% set parts = distro.split('-') %}
+        {% if 'embedded' in distro %}
+          {% set DEFCONFIG = DEFCONFIG + "_" + parts[0] + "_" %}
+          {% set BUILD_DIR = BUILD_DIR + "_" + parts[0] + "_" %}
+        {% endif %}
+        {% set recipe = parts[1:]|join('-') %}
+        {% set image = parts[1:]|join('-') %}
       {% endif %}
-      {% if distro != 'things' %}
+      {% if 'things' not in distro %}
         {% for backend in GRAPHIC_BACKEND.split(' ')%}
-         {% set DEFCONFIG = DEFCONFIG + backend %}
-         {% set BUILD_DIR = BUILD_DIR + backend %}
-         {% set distro = distro + "-" + backend %}
+          {% set DEFCONFIG = DEFCONFIG + backend %}
+          {% set BUILD_DIR = BUILD_DIR + backend %}
+          {% set distro = distro + "-" + backend %}
 #----------------------------------------------------
 # Edgehog-build-{{ machine }}-{{ distro }}
 #----------------------------------------------------
diff --git a/docs/manifest-pipeline.md b/docs/manifest-pipeline.md
index 24c7227..52f474b 100644
--- a/docs/manifest-pipeline.md
+++ b/docs/manifest-pipeline.md
@@ -31,7 +31,19 @@ the pipeline with all the jobs for each machine, based on its input variables
   Space separated list of machines to build for, e.g. "c12 c20"
 
 * `DISTRO`  
-  Space separated list of Edgehog OS distros to build for, e.g. "things embedded-base embedded-full"
+  Space separated list of Edgehog OS distros to build for, e.g. "things embedded-base embedded-full".  
+  In order to handle the scenarios where bitbake needs to compile an
+  image different from the standard ones it is also handled the possibility to
+  have a custom DISTRO variable value. However, the variable shall follow
+  the following convention:
+  
+  * The first part of the string shall indicate the standard Edgehog OS
+    distro, i.e. 'things' or 'embedded' as of now.
+  * The second part of the string shall be the custom Edgehog OS image
+    distro with at maximum a '-' as a separator, e.g. 'custom-image'.
+  * The two parts of the string shall be separated by a '-'.
+    
+  An example could be 'embedded-custom-image'.
 
 * `GRAPHIC_BACKEND`  
   Space separated list of graphical backends to build for, e.g. "wayland x11"
-- 
GitLab