tools: add 'verbose' options
authorJean-Sebastien Gelinas <calestar@gmail.com>
Wed, 24 Jun 2009 06:04:57 +0000 (02:04 -0400)
committerJean Privat <jean@pryen.org>
Fri, 26 Jun 2009 19:27:17 +0000 (15:27 -0400)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

bin/gccx
src/compiling/compiling.nit
src/mmloader.nit

index 8da5452..935c77a 100755 (executable)
--- a/bin/gccx
+++ b/bin/gccx
@@ -37,6 +37,8 @@ Usage: $e [options] modulename [options for module execution]
 -o name     Call name the executable
 -d          Create temporary files in a specific directory
 -nolibgc    Do not include libgc
+-v          Verbose (show compilation steps)
+-vv         Verbose+ (show gcc calls)
 -h          This help
 END
 }
@@ -62,6 +64,8 @@ return $res
 }
 
 stop=false
+verbose=false
+vverbose=false
 while [ $stop = false ]; do
        case $1 in 
                -O) OPTS="$OPTS -O2" ext="_savo"; shift;;
@@ -71,6 +75,8 @@ while [ $stop = false ]; do
                -d) dir="$2/"; shift; shift;;
                --nolibgc) nolibgc=true; shift;;
                -x) OPTS="$OPTS $2"; shift; shift;;
+               -vv) vverbose=true; verbose=true; shift;;
+               -v) verbose=true; shift;;
                -h|"") usage; exit;;
                *) stop=true
        esac
@@ -97,7 +103,11 @@ for i in "$@"; do
                fi
        done
        if [ $found = false ]; then
-               echo "* $CC $OPTS -c $i -o $o" >&2
+               if [ $verbose = true  ] ; then
+                       if [ $vverbose = true  ] ; then
+                               echo "* $CC $OPTS -c $i -o $o" >&2
+                       fi
+               fi
                if $CC $OPTS -c $i -o $o; then
                        echo "$cksum" > "$cksumfile"
                else
@@ -107,5 +117,7 @@ for i in "$@"; do
        objs="$objs $o"
 done
 
-echo "* $CC $OPTS -lm $objs -o $out" >&2
+if [ $vverbose = true  ] ; then
+       echo "* $CC $OPTS -lm $objs -o $out" >&2
+fi
 $CC $OPTS -lm $objs -o "$out"
index a063ca5..b731b1c 100644 (file)
@@ -57,10 +57,17 @@ redef class MMSrcModule
 
                var fn = "{tc.compdir}/{name}._build.sh"
                var f = new OFStream.open(fn)
+               var verbose = ""
+
+               if tc.verbose_level > 0 then
+                       verbose = "-"
+                       for i in [1..tc.verbose_level] do verbose = verbose + "v"
+               end
+
                f.write("#!/bin/sh\n")
                f.write("# This shell script is generated by NIT to compile the program {name}.\n")
                f.write("CLIBDIR=\"{tc.clibdir}\"\n")
-               f.write("{tc.bindir}/gccx -d {tc.compdir} -I $CLIBDIR {includes.join(" ")}")
+               f.write("{tc.bindir}/gccx {verbose} -d {tc.compdir} -I $CLIBDIR {includes.join(" ")}")
                if tc.output_file != null then 
                        f.write(" -o {tc.output_file}")
                else if tc.ext_prefix.is_empty then
index 5b4a45d..0288e49 100644 (file)
@@ -49,6 +49,14 @@ special MMContext
                end
        end
 
+       # Display an info
+       meth info(s: String, level: Int)
+       do
+               if level <= verbose_level then
+                       print "{s}"
+               end
+       end
+
        # Paths where to locate modules files
        readable var _paths: Array[String] = new Array[String]
 
@@ -79,10 +87,16 @@ special MMContext
        # Option --version
        readable var _opt_version: OptionBool = new OptionBool("Show version and exit", "--version")
 
+       # Option --verbose
+       readable var _opt_verbose: OptionCount = new OptionCount("Verbose", "-v", "--verbose")
+
+       # Verbose level
+       readable var _verbose_level: Int = 0
+
        init
        do
                super
-               option_context.add_option(opt_warn, opt_path, opt_log, opt_only_parse, opt_only_metamodel, opt_help, opt_version)
+               option_context.add_option(opt_warn, opt_path, opt_log, opt_only_parse, opt_only_metamodel, opt_help, opt_version, opt_verbose)
        end
 
        # Parse and process the options given on the command line
@@ -91,6 +105,9 @@ special MMContext
                # init options
                option_context.parse(args)
 
+               # Set verbose level
+               _verbose_level = opt_verbose.value
+
                # Setup the paths value
                paths.append(opt_path.value)