Quellcode durchsuchen

Check mkit.ini version

This is the last version where we tolerate incompatible changes in
mkit.ini and from now on, all mkit.ini files must have the version line
(in first 3 or last 3 lines).

As per my interpretation of SemVer, if major version is 0, we may
introduce incompatible changes within minor, in that case we check that
as well.  Otherwise, we just check the major.
Alois Mahdal vor 8 Jahren
Ursprung
Commit
d0c2f08815
1 geänderte Dateien mit 47 neuen und 0 gelöschten Zeilen
  1. 47
    0
      src/include/mkit.sh

+ 47
- 0
src/include/mkit.sh Datei anzeigen

@@ -58,6 +58,52 @@ die() {
58 58
     exit 4
59 59
 }
60 60
 
61
+_compver() {
62
+    #
63
+    # True if version $1 matches our version
64
+    #
65
+    # If our x is 0, check first two fragments, otherwise check just
66
+    # the x.  Fragments must equal.
67
+    #
68
+    local their_ver our_x our_y their_x their_y
69
+    their_ver="$1"
70
+    their_x=${their_ver%%.*}
71
+    their_y=${their_ver##$their_x.}
72
+    their_y=${their_y%%.*}
73
+    our_x=${MKIT_VERSION%%.*}
74
+    our_y=${MKIT_VERSION##$our_x.}
75
+    our_y=${our_y%%.*}
76
+    debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
77
+    test "$their_x" -eq "$our_x" || return 1
78
+    test "$our_x" -eq 0 && {
79
+        test "$their_y" = "$our_y"
80
+        return $?
81
+    }
82
+    return 0
83
+}
84
+
85
+_chkiniversion() {
86
+    #
87
+    # Check if ini version is supported
88
+    #
89
+    # Look for "#mkit version=0.0.0" or similar in first or last
90
+    # 3 lines of the file; then check if the version is supported.
91
+    #
92
+    local ver_line
93
+    local their_ver
94
+    ver_line=$(
95
+        {
96
+            head -3 "$MKIT_INI"
97
+            tac "$MKIT_INI" | tail -3
98
+        } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
99
+    )
100
+    test -n "$ver_line" \
101
+     || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
102
+    their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
103
+    _compver "$their_ver" \
104
+     || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
105
+}
106
+
61 107
 mkit_init() {
62 108
     #
63 109
     # Do basic initialization
@@ -67,6 +113,7 @@ mkit_init() {
67 113
     $MKIT_DRY && MKIT_DEBUG=true
68 114
     MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
69 115
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
116
+    _chkiniversion
70 117
     test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
71 118
      || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
72 119
 }