aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-22 23:23:28 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-03-22 23:23:28 +0100
commit01a1ed449f72740d81cda58357936639ce8b79cd (patch)
tree9b9e4dbdc3c5a43b65a72c7882b3a697061ed8bc /lib
parentefebfd58938fc512e300cbdafd25e01e61bd4157 (diff)
Include duration of installation process
Diffstat (limited to 'lib')
-rw-r--r--lib/actions/install.bash8
-rw-r--r--lib/util.bash22
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/actions/install.bash b/lib/actions/install.bash
index b2faefd..8f6993b 100644
--- a/lib/actions/install.bash
+++ b/lib/actions/install.bash
@@ -16,6 +16,8 @@ action() {
local OPTIND
local prefix_absolute
local modules
+ local init
+ local duration
while getopts ":b:p:" opt
do
@@ -33,6 +35,7 @@ action() {
prefix_absolute="$(CDPATH="" cd -- "$RSTAR_PREFIX" && pwd -P)"
info "Installing Raku in $prefix_absolute"
+ init="$(date +%s)"
# Compile all core components
for component in moarvm nqp rakudo
@@ -73,9 +76,12 @@ action() {
done
fi
+ duration="$(pp_duration "$init")"
+
# Friendly message
- # TODO: Add information on the time it took"
info "Rakudo Star has been installed into $prefix_absolute!"
+ info "The installation took $duration."
+ info ""
info "You may need to add the following paths to your \$PATH:"
info " $prefix_absolute/bin"
info " $prefix_absolute/share/perl6/site/bin"
diff --git a/lib/util.bash b/lib/util.bash
index 8ca1a5e..7ab0bc1 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -74,6 +74,28 @@ fetch() {
return $exit_code
}
+# Pretty print a duration between a starting point (in seconds) and an end
+# point (in seconds). If no end point is given, the current time will be used.
+# A good way to get a current timestamp in seconds is through date's "%s"
+# format.
+pp_duration() {
+ local start=$1
+ local end=$2
+ local diff
+
+ if [[ -z "$end" ]]
+ then
+ end="$(date +%s)"
+ fi
+
+ diff=$((end - start))
+
+ printf "%dh %02dm %02ds\n" \
+ "$((diff / 60 / 60))" \
+ "$((diff / 60))" \
+ "$((diff % 60))"
+}
+
# Create a temporary directory. Similar to tempfile, but you'll get a directory
# instead.
tmpdir() {