split LOG_* and UPDATE_* from lib/update.args into lib/update.*; fixup check_link and do_link for relative targets
authorTero Marttila <terom@paivola.fi>
Thu, 18 Sep 2014 21:13:23 +0300
changeset 624 889ecd6dcb4e
parent 623 44c32fd60997
child 625 57e4f48a7140
split LOG_* and UPDATE_* from lib/update.args into lib/update.*; fixup check_link and do_link for relative targets
bin/update
lib/update.args
lib/update.log
lib/update.updates
--- a/bin/update	Sat Apr 26 23:55:18 2014 +0300
+++ b/bin/update	Thu Sep 18 21:13:23 2014 +0300
@@ -102,6 +102,8 @@
 
 ## Main entry point
 function main {
+    log_init
+
     parse_args "$@"
 
     ## Input dirs
--- a/lib/update.args	Sat Apr 26 23:55:18 2014 +0300
+++ b/lib/update.args	Thu Sep 18 21:13:23 2014 +0300
@@ -3,25 +3,7 @@
 #
 # Command-line options
 
-# use color output?
-IS_TTY=
-
-
 ## Options
-LOG_ERROR=y
-LOG_WARN=y
-LOG=y
-LOG_FORCE=y
-LOG_UPDATE=y
-LOG_NOOP=y
-LOG_SKIP=
-LOG_DEBUG=
-LOG_CMD=
-LOG_DIFF=y
-
-UPDATE_FORCE=
-UPDATE_NOOP=
-UPDATE_DIFF=
 
 SERIAL_NOOP=
 SERIAL_FORCE=
@@ -70,9 +52,6 @@
 
 ## Parse any command-line arguments, setting the global options vars.
 function parse_args {
-    # test tty
-    [ -t 1 ] && IS_TTY=y
- 
     OPTIND=1
 
     while getopts 'hd:qvDVpFSsnCcm:Rr' opt "$@"; do
--- a/lib/update.log	Sat Apr 26 23:55:18 2014 +0300
+++ b/lib/update.log	Thu Sep 18 21:13:23 2014 +0300
@@ -3,6 +3,24 @@
 #
 # Logging output
 
+# use color output?
+IS_TTY=
+
+LOG_ERROR=y
+LOG_WARN=y
+LOG=y
+LOG_FORCE=y
+LOG_UPDATE=y
+LOG_NOOP=y
+LOG_SKIP=
+LOG_DEBUG=
+LOG_CMD=
+LOG_DIFF=y
+
+function log_init {
+    [ -t 1 ] && IS_TTY=y
+}
+
 # Output message to stderr.
 function log_msg {
     echo "$*" >&2
--- a/lib/update.updates	Sat Apr 26 23:55:18 2014 +0300
+++ b/lib/update.updates	Thu Sep 18 21:13:23 2014 +0300
@@ -3,6 +3,10 @@
 #
 # Dependency-based updates + utils
 
+UPDATE_FORCE=
+UPDATE_NOOP=
+UPDATE_DIFF=
+
 ## Compare the given output file with all given source files:
 #
 #   check_update $out ${deps[@]} && do_update $out ... || ...
@@ -95,12 +99,16 @@
 # Tests if the symlink exists, and the target matches.
 # Fails if the target does not exist.
 function check_link {
-    local lnk="$1"
+    local out="$1"
     local tgt="$2"
 
-    [ ! -e "$tgt" ] && fail "$tgt: target does not exist"
-    
-    [ ! -e "$lnk" ] || [ $(readlink "$lnk") != "$tgt" ]
+    [ -e "$out" ] || return 1
+
+    [ -L "$out" ] || fail "$out: is not a link"
+
+    [ "$(readlink "$out")" == "$tgt" ] || return 1
+
+    return 0
 }
 
 ## Update symlink to point to target:
@@ -108,10 +116,12 @@
 #   do_link $lnk $tgt
 #
 function do_link {
-    local lnk="$1"
+    local out="$1"
     local tgt="$2"
 
-    cmd ln -sf "$tgt" "$lnk"
+    cmd ln -sf "$tgt" "$out"
+
+    [ -e "$out" ] || fail "$out: given target does not exist: $tgt"
 }
 
 ## Read include paths from file