1#!/usr/bin/env bash 2 3# Get absolute path of Renode directory. 4# 5# To make it run from any place in the system (possibly different git repository) 6# we have to get full path of the script and then find the git repository that 7# contains it (it will be the Renode repository). 8RENODE_DIR="$(cd $(dirname $(realpath $0)); git rev-parse --show-toplevel)" 9 10# Read dts2repl commit cached in the Renode repository 11# 12# NOTE: The output of the 'git submodule status' command is: 13# " a53f2f01039a462bdd7322d1fb315edd95033b6d tools/dts2repl (heads/main)" 14# We are looking for the commit SHA-1 (40 hexadecimal digits) followed 15# by the "tools/dts2repl" string. 16# It could be done in a single grep command: 17# grep -oP "[a-f0-9]{40}(?=\s+tools/dts2repl)") 18# however, the -P option isn't available on all supported platforms, so 19# it has to be split into two separate commands. 20DTS2REPL_VERSION=$( \ 21 cd $RENODE_DIR; \ 22 git submodule status --cached tools/dts2repl | \ 23 grep -Eo "[a-f0-9]{40}\s+tools/dts2repl" | \ 24 grep -Eo "[a-f0-9]{40}" \ 25) 26 27if [ $? -ne 0 ] ; then 28 echo "Failed to determine dts2repl version." 29 exit 1 30fi 31 32# In packages the DTS2REPL_VERSION variable will be set to specific dts2repl version. 33# The bottom part of this script will be copied directly to the package, but the 34# upper part will contain a single line: 35# DTS2REPL_VERSION=<commit-sha> 36# 37# To make it easy to cut the head of this script we leave the marker here: 38# END OF VERSION CHECK 39 40case $1 in 41 "--commit"|"") 42 echo "$DTS2REPL_VERSION" 43 ;; 44 45 "--url") 46 echo "https://github.com/antmicro/dts2repl/tree/$DTS2REPL_VERSION" 47 ;; 48 49 "--pip"|"--pipx") 50 echo "git+https://github.com/antmicro/dts2repl@$DTS2REPL_VERSION" 51 ;; 52 53 "--help"|"-h") 54 echo "usage: $(basename $0) [-h] [--commit] [--pip] [--pipx] [--url]" 55 echo "" 56 echo "Display version of dts2repl supported by this version of Renode in specified format." 57 echo "" 58 echo "options:" 59 echo " --commit git commit SHA (default)" 60 echo " --pip url that can be passed to pip to install dts2repl" 61 echo " --pipx url that can be passed to pipx to install dts2repl" 62 echo " --url url to the specific commit on GitHub" 63 echo " -h, --help show this help message and exit" 64 ;; 65 66 *) 67 >&2 echo "Unrecognized argument '$1'" 68 exit 1 69 ;; 70esac 71