public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] kas: Improve script to generate kas yaml files
@ 2024-03-18 12:51 Uladzimir Bely
  2024-03-22  8:17 ` Uladzimir Bely
  0 siblings, 1 reply; 2+ messages in thread
From: Uladzimir Bely @ 2024-03-18 12:51 UTC (permalink / raw)
  To: isar-users

Changes:
 - Avoid duplicated code.
 - Don't update old files if there are no real changes in them.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 scripts/generate_yaml.sh | 89 +++++++++++++++++++++++++++++-----------
 1 file changed, 64 insertions(+), 25 deletions(-)

diff --git a/scripts/generate_yaml.sh b/scripts/generate_yaml.sh
index e17d6d3d..8e8651a0 100755
--- a/scripts/generate_yaml.sh
+++ b/scripts/generate_yaml.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
-# This software is a part of ISAR.
-# Copyright (c) 2023 ilbers GmbH
+# This software is a part of Isar.
+# Copyright (c) 2023-2024 ilbers GmbH
 # Authors:
 #  Uladzimir Bely <ubely@ilbers.de>
 
@@ -14,52 +14,87 @@ set -e
 cd "$(dirname "$0")/.."
 
 HEADER="\
-# This software is a part of ISAR.
-# Copyright (C) 2023 ilbers GmbH
+# This software is a part of Isar.
+# Copyright (C) $(date +%Y) ilbers GmbH
 
 header:
   version: 14"
 
-# Scan for distro configs, except "debian-common" used only for including
+update_yaml() {
+  yaml=${1}
 
-DISTROS=$(find {meta,meta-isar}/conf/distro -iname *.conf -printf "%f\n" \
-  | sed -e 's/.conf$//' | grep -v "debian-common" | sort)
+  printf "%-45s | " ${yaml}
 
-for distro in ${DISTROS}
-do
-  cat << _EOF_ > kas/distro/${distro}.yaml
+  # Use temporary file if old one not exists
+  if [ ! -f "${yaml}" ]; then
+    echo "Not existed before, saving"
+    mv ${yaml}_tmp ${yaml}
+    return
+  fi
+
+  # Compare "pure" contents, without comments (e.g., copyrights, year)
+  old=$(grep -v "^#" ${yaml})
+  new=$(grep -v "^#" ${yaml}_tmp)
+
+  if [ "${new}" = "${old}" ]; then
+    echo "No real changes, keeping  "
+    rm ${yaml}_tmp
+  else
+    echo "File changed, saving"
+    mv ${yaml}_tmp ${yaml}
+  fi
+}
+
+make_yaml() {
+  dir=${1}
+  name=${2}
+  value=${3}
+
+  yaml="kas/${dir}/${value}.yaml"
+
+  # Generate temporary file
+  cat << _EOF_ > ${yaml}_tmp
 ${HEADER}
 
-distro: ${distro}
+${name}: ${value}
 _EOF_
+
+  update_yaml ${yaml}
+}
+
+
+# Scan for distro configs, except:
+# - "debian-common" used only for including
+# - "debian-sid-ports" not used currently
+
+DISTROS=$(find {meta,meta-isar}/conf/distro -iname *.conf -printf "%f\n" \
+  | sed -e 's/.conf$//' | grep -v "debian-common\|debian-sid-ports" | sort)
+
+for distro in ${DISTROS}
+do
+  make_yaml "distro" "distro" "${distro}"
 done
 
-# Scan for image recipes
+# Scan for image recipes, except:
+# - "isar-image-installer" having more complex structure
 
 IMAGES=$(find {meta,meta-isar}/recipes-core/images -iname *.bb -printf "%f\n" \
-  | sed -e 's/.bb$//' | sort)
+  | sed -e 's/.bb$//' | grep -v "isar-image-installer"| sort)
 
 for image in ${IMAGES}
 do
-  cat << _EOF_ > kas/image/${image}.yaml
-${HEADER}
-
-target: ${image}
-_EOF_
+  make_yaml "image" "target" "${image}"
 done
 
-# Scan for machine configs, except "rpi-common" used only for including
+# Scan for machine configs, except:
+# - "rpi-common" used only for including
 
 MACHINES=$(find meta-isar/conf/machine -iname *.conf -printf "%f\n" \
   | sed -e 's/.conf$//' | grep -v "rpi-common" | sort)
 
 for machine in ${MACHINES}
 do
-  cat << _EOF_ > kas/machine/${machine}.yaml
-${HEADER}
-
-machine: ${machine}
-_EOF_
+  make_yaml "machine" "machine" "${machine}"
 done
 
 # Generate configs for fixed list of Isar packages
@@ -87,11 +122,15 @@ do
     package=${pkg}-\$\{KERNEL_NAME\}
   fi
 
-  cat << _EOF_ > kas/package/pkg_${pkg}.yaml
+  yaml="kas/package/pkg_${pkg}.yaml"
+
+  cat << _EOF_ > ${yaml}_tmp
 ${HEADER}
 
 local_conf_header:
   package-${pkg}: |
     IMAGE_INSTALL:append = " ${package}"
 _EOF_
+
+  update_yaml ${yaml}
 done
-- 
2.43.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-22  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 12:51 [PATCH] kas: Improve script to generate kas yaml files Uladzimir Bely
2024-03-22  8:17 ` Uladzimir Bely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox