Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fengzch-das
multibuild
Commits
b9a8decd
Commit
b9a8decd
authored
Jul 18, 2016
by
Matthew Brett
Browse files
Add unlex_ver and strip_ver_suffix
For getting versions from versions with suffixes.
parent
c5adb79c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
common_utils.sh
common_utils.sh
+12
-0
tests/test_common_utils.sh
tests/test_common_utils.sh
+10
-0
No files found.
common_utils.sh
View file @
b9a8decd
...
@@ -27,6 +27,18 @@ function lex_ver {
...
@@ -27,6 +27,18 @@ function lex_ver {
echo
$1
|
awk
-F
"."
'{printf "%03d%03d%03d", $1, $2, $3}'
echo
$1
|
awk
-F
"."
'{printf "%03d%03d%03d", $1, $2, $3}'
}
}
function
unlex_ver
{
# Reverses lex_ver to produce major.minor.micro
# Thus:
# 003002001 -> 3.2.1
# 003000000 -> 3.0.0
echo
"
$((
10
#${1:0:3}+0)).$((10#${1:3:3}+0)).$((10#${1:6:3}+0))"
}
function
strip_ver_suffix
{
echo
$(
unlex_ver
$(
lex_ver
$1
))
}
function
is_function
{
function
is_function
{
# Echo "true" if input argument string is a function
# Echo "true" if input argument string is a function
# Allow errors during "set -e" blocks.
# Allow errors during "set -e" blocks.
...
...
tests/test_common_utils.sh
View file @
b9a8decd
...
@@ -12,6 +12,16 @@
...
@@ -12,6 +12,16 @@
[
"
$(
lex_ver 2.1.4
)
"
==
"002001004"
]
||
ingest
"lex_ver 2.1.4"
[
"
$(
lex_ver 2.1.4
)
"
==
"002001004"
]
||
ingest
"lex_ver 2.1.4"
[
"
$(
lex_ver 2.1.4rc1
)
"
==
"002001004"
]
||
ingest
"lex_ver 2.1.4"
[
"
$(
lex_ver 2.1.4rc1
)
"
==
"002001004"
]
||
ingest
"lex_ver 2.1.4"
[
"
$(
unlex_ver 002000000
)
"
==
"2.0.0"
]
||
ingest
"unlex_ver 002000000"
[
"
$(
unlex_ver 003002012
)
"
==
"3.2.12"
]
||
ingest
"unlex_ver 003002012"
# Not octal
[
"
$(
unlex_ver 003044099
)
"
==
"3.44.99"
]
||
ingest
"unlex_ver 003044099"
[
"
$(
unlex_ver 003543012
)
"
==
"3.543.12"
]
||
ingest
"unlex_ver 003543012"
[
"
$(
unlex_ver 003543012abc
)
"
==
"3.543.12"
]
||
ingest
"unlex_ver 003543012abc"
[
"
$(
strip_ver_suffix 3.4.0rc1
)
"
==
"3.4.0"
]
||
ingest
"unlex_ver strip suff 1"
[
"
$(
strip_ver_suffix 3.24.12a4
)
"
==
"3.24.12"
]
||
ingest
"unlex_ver strip suff 2"
[
"
$(
is_function abspath
)
"
==
"true"
]
||
ingest
"is_function abspath"
[
"
$(
is_function abspath
)
"
==
"true"
]
||
ingest
"is_function abspath"
[
"
$(
is_function foo
)
"
==
""
]
||
ingest
"is_function foo"
[
"
$(
is_function foo
)
"
==
""
]
||
ingest
"is_function foo"
bar
=
baz
bar
=
baz
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment