Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Output alignment in build.sh



On Tue, 24 Aug 2010, Christos Zoulas wrote:

On Aug 24,  5:51pm, kre%munnari.OZ.AU@localhost (Robert Elz) wrote:
-- Subject: Re: Output alignment in build.sh

| You could use "case "${#msg}" and 16|17|18|19|[2-9]*) (etc) as the patterns,
| but the way I wrote it works on even the oldest Bourne style shell
| (${#var} is a later addition) and to me anyway, is just more obvious
| (some shells might not like the "local" declaration, but that can just be
| removed if needed).

I guess build.sh is "special" because it needs to be written in
the least common denominator shell, so kre's ?? code is probably
the way to go here.

Yeah the first attempt at the was definitely a "C programmer writing shell code"! :)

The attached patch uses this approach and also cleans up some remnants of a much older version.

Any more comments? Any reason why this should not, in one form or another, be committed?


-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------
Index: src/build.sh
===================================================================
RCS file: /cvsroot/src/build.sh,v
retrieving revision 1.237
diff -u -p -r1.237 build.sh
--- src/build.sh        17 Jun 2010 08:19:02 -0000      1.237
+++ src/build.sh        24 Aug 2010 12:56:28 -0000
@@ -63,6 +63,27 @@ statusmsg()
        ${runcmd} echo "===> $@" | tee -a "${results}"
 }
 
+statusmsg2()
+{
+       msg="${1}"
+       shift
+       case ${msg} in
+       ????????????????*)      ;;
+       ??????????*)            msg="${msg}      ";;
+       ?????*)                 msg="${msg}           ";;
+       *)                      msg="${msg}                ";;
+       esac
+       case ${msg} in
+       ?????????????????????*) ;;
+       ????????????????????)   msg="${msg} ";;
+       ???????????????????)    msg="${msg}  ";;
+       ??????????????????)     msg="${msg}   ";;
+       ?????????????????)      msg="${msg}    ";;
+       ????????????????)       msg="${msg}     ";;
+       esac
+       statusmsg "${msg}$@"
+}
+
 warning()
 {
        statusmsg "Warning: $@"
@@ -1219,7 +1240,7 @@ validatemakeparams()
                fi
                eval ${var}=\"\${newval}\"
                eval export ${var}
-               statusmsg "${var} path:     ${newval}"
+               statusmsg2 "${var} path:" "${newval}"
        done
 
        # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
@@ -1386,8 +1407,7 @@ exec "\${TOOLDIR}/bin/${toolprefix}make"
 EOF
        [ "${runcmd}" = "echo" ] && echo EOF
        ${runcmd} chmod +x "${makewrapper}"
-       statusmsg "makewrapper:      ${makewrapper}"
-       statusmsg "Updated ${makewrapper}"
+       statusmsg2 "Updated makewrapper:" "${makewrapper}"
 }
 
 make_in_dir()
@@ -1456,8 +1476,8 @@ buildkernel()
                buildkernelwarned=true
        fi
        getkernelconf $1
-       statusmsg "Building kernel:  ${kernelconf}"
-       statusmsg "Build directory:  ${kernelbuildpath}"
+       statusmsg2 "Building kernel:" "${kernelconf}"
+       statusmsg2 "Build directory:" "${kernelbuildpath}"
        ${runcmd} mkdir -p "${kernelbuildpath}" ||
            bomb "Cannot mkdir: ${kernelbuildpath}"
        if [ "${MKUPDATE}" = "no" ]; then
@@ -1491,7 +1511,7 @@ releasekernel()
                builtkern="${kernelbuildpath}/${kern}"
                [ -f "${builtkern}" ] || continue
                releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
-               statusmsg "Kernel copy:      ${releasekern}"
+               statusmsg2 "Kernel copy:" "${releasekern}"
                if [ "${runcmd}" = "echo" ]; then
                        echo "gzip -c -9 < ${builtkern} > ${releasekern}"
                else
@@ -1635,13 +1655,13 @@ main()
        sanitycheck
 
        build_start=$(date)
-       statusmsg "${progname} command: $0 $@"
-       statusmsg "${progname} started: ${build_start}"
-       statusmsg "NetBSD version:   ${DISTRIBVER}"
-       statusmsg "MACHINE:          ${MACHINE}"
-       statusmsg "MACHINE_ARCH:     ${MACHINE_ARCH}"
-       statusmsg "Build platform:   ${uname_s} ${uname_r} ${uname_m}"
-       statusmsg "HOST_SH:          ${HOST_SH}"
+       statusmsg2 "${progname} command:" "$0 $@"
+       statusmsg2 "${progname} started:" "${build_start}"
+       statusmsg2 "NetBSD version:"   "${DISTRIBVER}"
+       statusmsg2 "MACHINE:"          "${MACHINE}"
+       statusmsg2 "MACHINE_ARCH:"     "${MACHINE_ARCH}"
+       statusmsg2 "Build platform:"   "${uname_s} ${uname_r} ${uname_m}"
+       statusmsg2 "HOST_SH:"          "${HOST_SH}"
 
        rebuildmake
        validatemakeparams
@@ -1716,7 +1736,7 @@ main()
                esac
        done
 
-       statusmsg "${progname} ended:   $(date)"
+       statusmsg2 "${progname} ended:" "$(date)"
        if [ -s "${results}" ]; then
                echo "===> Summary of results:"
                sed -e 's/^===>//;s/^/  /' "${results}"


Home | Main Index | Thread Index | Old Index