From e3ac8f0f09c6ea1e994797a6f7ed4384563f2e4f Mon Sep 17 00:00:00 2001 From: Joseph-Eugene Winzer Date: Wed, 10 Feb 2021 19:15:19 +0100 Subject: Added a zig version test --- ziglings | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ziglings b/ziglings index 7c2f6a1..e941411 100755 --- a/ziglings +++ b/ziglings @@ -17,6 +17,19 @@ fmt_err=$( tput setaf 1 ) # red foreground fmt_yay=$( tput setaf 2 ) # green foreground fmt_off=$( tput sgr0 ) # reset colors/effects +zig_cmd=zig +zig_version_required=( 0 8 0 ) +zig_version=$($zig_cmd version) +zig_version=(${zig_version//./ }) + +if [[ ${zig_version[0]} -ne ${zig_version_required[0]} || ${zig_version[1]} -lt ${zig_version_required[1]} ]] +then + echo "Your current zig version is $(IFS=$'.'; echo "${zig_version[*]}")." + echo "Please update your zig compiler to a version >=$(IFS=$'.'; echo "${zig_version_required[*]}") "` + `"or change zig_cmd in ./ziglings to the appropriate path." + exit 1 +fi + exercise_num=0 function check_it { @@ -32,7 +45,7 @@ function check_it { fi # Compile/run the source and capture the result and exit value - cmd="zig run $source_file" + cmd="$zig_cmd run $source_file" echo "$ $cmd" result=$($cmd 2>&1) result_status=$? -- cgit v1.2.3-ZIG From b5ab7ea7877317813aaad6f60ab2fba3ed03826c Mon Sep 17 00:00:00 2001 From: Joseph-Eugene Winzer Date: Thu, 11 Feb 2021 16:53:43 +0100 Subject: Added zig version check for commit number --- ziglings | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ziglings b/ziglings index e941411..84822ca 100755 --- a/ziglings +++ b/ziglings @@ -18,11 +18,15 @@ fmt_yay=$( tput setaf 2 ) # green foreground fmt_off=$( tput sgr0 ) # reset colors/effects zig_cmd=zig -zig_version_required=( 0 8 0 ) +# zig compiler version ( major minor patch commits_since_last_release ) +zig_version_required=( 0 8 0 1065 ) zig_version=$($zig_cmd version) zig_version=(${zig_version//./ }) +zig_version_commit=(${zig_version[3]//+/ }) -if [[ ${zig_version[0]} -ne ${zig_version_required[0]} || ${zig_version[1]} -lt ${zig_version_required[1]} ]] +if [[ ${zig_version[0]} -ne ${zig_version_required[0]} || + ${zig_version[1]} -lt ${zig_version_required[1]} || + $zig_version_commit -lt ${zig_version_required[3]} ]] then echo "Your current zig version is $(IFS=$'.'; echo "${zig_version[*]}")." echo "Please update your zig compiler to a version >=$(IFS=$'.'; echo "${zig_version_required[*]}") "` -- cgit v1.2.3-ZIG From 7e56ccc9d9f478e160d07d6a171c7c5be0864a09 Mon Sep 17 00:00:00 2001 From: Joseph-Eugene Winzer Date: Thu, 11 Feb 2021 20:49:57 +0100 Subject: Improved zig version check --- ziglings | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ziglings b/ziglings index 84822ca..a5fa8d4 100755 --- a/ziglings +++ b/ziglings @@ -18,19 +18,31 @@ fmt_yay=$( tput setaf 2 ) # green foreground fmt_off=$( tput sgr0 ) # reset colors/effects zig_cmd=zig -# zig compiler version ( major minor patch commits_since_last_release ) -zig_version_required=( 0 8 0 1065 ) -zig_version=$($zig_cmd version) -zig_version=(${zig_version//./ }) -zig_version_commit=(${zig_version[3]//+/ }) +zig_minimum_version="0 8 0 1065" +zig_version=$($zig_cmd version 2>/dev/null) -if [[ ${zig_version[0]} -ne ${zig_version_required[0]} || - ${zig_version[1]} -lt ${zig_version_required[1]} || - $zig_version_commit -lt ${zig_version_required[3]} ]] +if [[ "$zig_version" =~ ([0-9]+)\.([0-9]+)\.([0-9]+)-dev\.([0-9]+) ]] then - echo "Your current zig version is $(IFS=$'.'; echo "${zig_version[*]}")." - echo "Please update your zig compiler to a version >=$(IFS=$'.'; echo "${zig_version_required[*]}") "` - `"or change zig_cmd in ./ziglings to the appropriate path." + match_idx=1 # regex matches start at index 1 + + for v in $zig_minimum_version + do + if [[ ${BASH_REMATCH[$match_idx]} -lt $v ]] + then + echo "Your current Zig version is $zig_version." + echo "Please update your zig compiler to a version >=$(echo "${zig_minimum_version// /.}") "` + `"or change \$zig_cmd in ./ziglings to the appropriate path." + exit 1 + fi + match_idx=$((match_idx+1)) + done +elif [[ -z $zig_version ]] +then + echo "Ziglings failed to determine your Zig version." + echo "Please check if \$zig_cmd in ./ziglings matches the zig executable in your PATH." + exit 1 +else + echo "Sorry, Zig version number '${zig_version}' is not in the expected format for a current development build." exit 1 fi -- cgit v1.2.3-ZIG