From c6bc09ed10bf13186e6a6f743d8be3db975b3415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= Date: Fri, 15 Nov 2024 16:23:30 +0100 Subject: [PATCH] script/query: don't restrict `./script.sh get-latest` to a single tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `./script.sh get-latest ` gets the full list of tags, filters it, sorts it then returns a single result. On the Python side, it gets the first one. If that works, it uses it, else it tries the second one, etc. That is a weird implementation: modify get-latest to return all tags so that Python code only has to spawn a single subprocess. Also, rename it from `get-latest` to `get-latest-tags`. This makes things more explicit (what latest?) and also explicits that more than one tag is required. Also, argument 1 is supposed to be an offset. No custom implementation of get_latest() did implement that. Signed-off-by: Théo Lebrun --- README.adoc | 4 ++-- elixir/query.py | 16 +++++++--------- projects/amazon-freertos.sh | 4 ++-- projects/bluez.sh | 4 ++-- projects/llvm.sh | 4 ++-- projects/mesa.sh | 4 ++-- projects/op-tee.sh | 4 ++-- projects/zephyr.sh | 4 ++-- samples/projects/linuxtest.sh | 2 +- script.sh | 8 ++++---- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/README.adoc b/README.adoc index d9c11f7..2bf4612 100644 --- a/README.adoc +++ b/README.adoc @@ -444,9 +444,9 @@ to customize the `list_tags_h` function. You should also make sure that Elixir properly identifies the most recent versions: - ./script.sh get-latest + ./script.sh get-latest-tags | head -If needed, customize the `get_latest()` function. +If needed, customize the `get_latest_tags()` function. If you want to enable support for `compatible` properties in Devicetree files, add `dts_comp_support=1` at the beginning of `projects/.sh`. diff --git a/elixir/query.py b/elixir/query.py index f4e9845..2e24448 100755 --- a/elixir/query.py +++ b/elixir/query.py @@ -110,18 +110,16 @@ class Query: elif cmd == 'latest': - previous = None - index = 0 + # Returns the latest tag that is included in the database. + # This excludes release candidates. + sorted_tags = self.scriptLines('get-latest-tags') - while True: - tag = decode(self.script('get-latest', str(index))).rstrip('\n') - - # tag == previous implies oldest tag, we return it anyway - if self.db.vers.exists(tag) or tag == previous: + for tag in sorted_tags: + if self.db.vers.exists(tag): return tag - previous = tag - index += 1 + # return the oldest tag, even if it does not exist in the database + return sorted_tags[-1] elif cmd == 'type': diff --git a/projects/amazon-freertos.sh b/projects/amazon-freertos.sh index 582a563..284a2cc 100644 --- a/projects/amazon-freertos.sh +++ b/projects/amazon-freertos.sh @@ -14,7 +14,7 @@ list_tags_h() sed -r 's/^(v[0-9]*)\.([0-9]*)(.*)$/\1 \1.\2 \1.\2\3/' } -get_latest() +get_latest_tags() { - git tag | grep '^20' | sort -V | tail -n 1 + git tag | grep '^20' | sort -Vr } diff --git a/projects/bluez.sh b/projects/bluez.sh index a7f5049..3613a70 100644 --- a/projects/bluez.sh +++ b/projects/bluez.sh @@ -13,7 +13,7 @@ list_tags_h() sed -E 's/^([0-9]*)\.([0-9]*)$/v\1 v\1.\2 \1.\2/' } -get_latest() +get_latest_tags() { - git tag | grep '^[0-9]\.' | sort -V | tail -n 1 + git tag | grep '^[0-9]\.' | sort -Vr } diff --git a/projects/llvm.sh b/projects/llvm.sh index 1fcaaef..a6c7616 100644 --- a/projects/llvm.sh +++ b/projects/llvm.sh @@ -16,7 +16,7 @@ list_tags_h() sed -r 's/^llvmorg-([0-9]*)\.([0-9]*)(.*)$/v\1 v\1.\2 llvmorg-\1.\2\3/' } -get_latest() +get_latest_tags() { - git tag | grep 'llvmorg' | grep -v init | sort -V | tail -n 1 + git tag | grep 'llvmorg' | grep -v init | sort -Vr } diff --git a/projects/mesa.sh b/projects/mesa.sh index 230331e..52cee0b 100644 --- a/projects/mesa.sh +++ b/projects/mesa.sh @@ -15,7 +15,7 @@ list_tags_h() sed -r 's/^mesa-([0-9]*)(\.[0-9]*)(.*)$/v\1 v\1\2 mesa-\1\2\3/' } -get_latest() +get_latest_tags() { - git tag | version_dir | grep ^mesa-[0-9]*[\.][0-9]* | grep -v '\-rc' | sort -V | tail -n 1 + git tag | version_dir | grep ^mesa-[0-9]*[\.][0-9]* | grep -v '\-rc' | sort -Vr } diff --git a/projects/op-tee.sh b/projects/op-tee.sh index d7c543d..8937cd6 100644 --- a/projects/op-tee.sh +++ b/projects/op-tee.sh @@ -14,7 +14,7 @@ list_tags() grep '^[0-9]\.' } -get_latest() +get_latest_tags() { - git tag | grep '^[0-9]\.' | grep -v '\-rc' | sort -V | tail -n 1 + git tag | grep '^[0-9]\.' | grep -v '\-rc' | sort -Vr } diff --git a/projects/zephyr.sh b/projects/zephyr.sh index b3c45fa..149b385 100644 --- a/projects/zephyr.sh +++ b/projects/zephyr.sh @@ -17,7 +17,7 @@ list_tags_h() sed -r 's/^(v[0-9]*)\.([0-9]*)(.*)$/\1 \1.\2 \1.\2\3/' } -get_latest() +get_latest_tags() { - git tag | grep -v '^zephyr-v' | version_dir | grep -v '\-rc' | sort -V | tail -n 1 + git tag | grep -v '^zephyr-v' | version_dir | grep -v '\-rc' | sort -Vr } diff --git a/samples/projects/linuxtest.sh b/samples/projects/linuxtest.sh index bc875ba..7c1c5c0 100644 --- a/samples/projects/linuxtest.sh +++ b/samples/projects/linuxtest.sh @@ -11,7 +11,7 @@ list_tags_h() echo "v5 v5.6 v5.6.1" } -get_latest() +get_latest_tags() { echo "v5.6.1" } diff --git a/script.sh b/script.sh index 011e095..1446777 100755 --- a/script.sh +++ b/script.sh @@ -63,9 +63,9 @@ list_tags_h() sed -r 's/^(v[0-9]*)\.([0-9]*)(.*)$/\1 \1.\2 \1.\2\3/' } -get_latest() +get_latest_tags() { - git tag | version_dir | grep -v '\-rc' | sort -V | tail -n $(($opt1 + 1)) | head -1 + git tag | version_dir | grep -v '\-rc' | sort -Vr } get_type() @@ -247,8 +247,8 @@ case $cmd in fi ;; - get-latest) - get_latest + get-latest-tags) + get_latest_tags ;; get-type)