public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH] kas: Improve script to generate kas yaml files
Date: Mon, 18 Mar 2024 15:51:53 +0300	[thread overview]
Message-ID: <20240318125206.31874-1-ubely@ilbers.de> (raw)

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


             reply	other threads:[~2024-03-18 12:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 12:51 Uladzimir Bely [this message]
2024-03-22  8:17 ` Uladzimir Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240318125206.31874-1-ubely@ilbers.de \
    --to=ubely@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox