[m-rev.] For review: New option for mmake to capture make process

Eric Taucher gluon at earthlink.net
Tue Jul 31 06:26:33 AEST 2007


A new option to capture all of the makefiles and output created by mmake. 

 

scripts/mmake.in:

   Each make file created by mmake is captured to a separate file and the
output of each make file is capture to a separate file.

   The captured files are date time stamped in the name for uniqueness, and
have the make target in the name.

   This will also capture the makefiles created in the temporary workspaces
before the workspace is deleted.

   By creating unique files for each makefile, the make database and make
debug output can be stored with it's corresponding makefile output for
easier debugging.

   Listed in each output file, is the name of the primary files used to make
the make file. Currently specific include files are not listed.

   While some of the information in the captured files duplicates existing
output messages, no deletion of existing output messages was done.

 

   Example of files created for command "make library."

 

 
make.2007-07-30-15-48-33.mercury-compiler-rotd-2007-07-24.library.Makefile

   make.2007-07-30-15-48-33.mercury-compiler-rotd-2007-07-24.library.txt

 
make.2007-07-30-15-48-35.mercury-compiler-rotd-2007-07-24-scripts.default_ta
rget.Makefile

 
make.2007-07-30-15-48-35.mercury-compiler-rotd-2007-07-24-scripts.default_ta
rget.txt

 
make.2007-07-30-15-48-36.mercury-compiler-rotd-2007-07-24-boehm_gc.default_t
arget.Makefile

 
make.2007-07-30-15-48-36.mercury-compiler-rotd-2007-07-24-boehm_gc.default_t
arget.txt

 
make.2007-07-30-15-48-37.mercury-compiler-rotd-2007-07-24-runtime.default_ta
rget.Makefile

 
make.2007-07-30-15-48-37.mercury-compiler-rotd-2007-07-24-runtime.default_ta
rget.txt

 
make.2007-07-30-15-48-40.mercury-compiler-rotd-2007-07-24-util.default_targe
t.Makefile

 
make.2007-07-30-15-48-40.mercury-compiler-rotd-2007-07-24-util.default_targe
t.txt

 
make.2007-07-30-15-48-41.mercury-compiler-rotd-2007-07-24-library.default_ta
rget.Makefile

 
make.2007-07-30-15-48-41.mercury-compiler-rotd-2007-07-24-library.default_ta
rget.txt

 

   Example of header for captured output showing files used to make
makefile.

 

 
----------------------------------------------------------------------------
-----

 

   PWD: /cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24/library

   Mercury make command that started process:  ../scripts/mmake

   Standard make command to be executed:       make
--warn-undefined-variables -f /tmp/mmake.ft4024 -r

 

   Note: Standard makefile /tmp/mmake.ft4024 saved as
'/cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24/make.2007-07-30-15-53-
18.mercury-compiler-rotd-2007-07-24-library.default_target.Makefile'

   Files combined into standard makefile:

            Vars:             ../scripts/Mmake.vars

            dv:               array.dv mer_std.dv

            Mercury makefile:
/cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24/library/Mmakefile

            d:                array.d array2d.d assoc_list.d <deleted for
example> version_store.d version_types.d

            Dependencies:     array.dep mer_std.dep

            Rules:            ../scripts/Mmake.rules

 

   Include files such as Mmake.common, VERSION, Mmake.workspace,
Merucry.options, Mmake.parms may also be used, but are not list here do to
the complexity.

 

 
----------------------------------------------------------------------------
-----

 

 

Index: mmake.in

===================================================================

RCS file: /home/mercury/mercury1/repository/mercury/scripts/mmake.in,v

retrieving revision 1.49

diff -u -r1.49 mmake.in

--- mmake.in      30 Nov 2005 16:23:51 -0000        1.49

+++ mmake.in   30 Jul 2007 18:17:27 -0000

@@ -47,6 +47,26 @@

                        Save the generated makefile to \`Mmake.makefile'.

                        This is useful for tracking down syntax errors in

                        your Mmake file.

+          --capture-makeprocess <base directory> <output directory>:

+                      For each generated/executed makefile capture the
makefile

+                      to a file and it's console output to a separate file.

+                      Notes:

+                      1. Since the make process has multiple makefiles in
different

+                      directories, the the directory name is part of the
capture

+                      name. To keep the capture name shorter, 

+                      the base directory name is removed from the directory
name.

+                      .i.e. If the current directory is

+
\`/cygdrive/d/Mercury/mercury-compiler-0.13.1/runtime' and 

+                      the base directory is \`/cygdrive/d/Mercury/' 

+                      then part of the capture name will be

+                      \`mercury-compiler-0.13.1-runtime'.

+                      2. In order to save the temp makefiles and put all
captured

+                      files in one place, an output directory is required. 

+                      3. When this option is combined with make options -p 

+                      and/or --debug=basic, it becomes extremely useful.

+                      4. Typical use --capture-makeprocess .. .
--debug=basic -p

+                      5. .. . Only work with cygwin environment, 

+                      other environments must use full directory name.

            -f <filename>, --file <filename>:

                        Use the specified file as the Mmake file.

            -v, --verbose:

@@ -84,9 +104,11 @@

 @SET_MACOSX_DEPLOYMENT_TARGET@

 

 MMAKE=$0

+MMAKE_OPTIONS=

 include_makefile=

 verbose=false

 save_makefile=false

+capture_makeprocess=false

 if [ -d Mercury ]; then

            use_subdirs=${MMAKE_USE_SUBDIRS=yes}

 else

@@ -104,18 +126,22 @@

                                    ;;

                        --use-subdirs)

                                    use_subdirs=yes

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        --no-use-subdirs)

                                    use_subdirs=no

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        --use-mmc-make)

                                    use_mmc_make=yes

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        --no-mmc-make)

                                    use_mmc_make=no

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        --target)

@@ -131,45 +157,92 @@

 
"\`--target' option" 1>&2

                                                            exit 1 ;;

                                    esac

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1 $2"

                                    shift; shift

                                    ;;

                        -s|--save-makefile)

                                    save_makefile=true

                                    MMAKE="$MMAKE $1"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        -s-|--no-save-makefile)

                                    save_makefile=false

                                    MMAKE="$MMAKE $1"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

+                                  shift

+                                  ;;

+                      --capture-makeprocess)

+                                  # Can't use a directory if it doesn't
exist

+                                  if [ ! -d "$2" ]; then

+                                              echo Directory $2 does not
exist.

+                                              exit 1

+                                  fi

+                                  if [ ! -d "$3" ]; then

+                                              echo Directory $3 does not
exist.

+                                              exit 1

+                                  fi

+                                  capture_makeprocess=true

+                                  # pass parameters to other mmake
processes using

+                                  # exported variables

+                                  

+                                  # Use cygpath -a to convert . or .. to
absolute path

+                                  CAPTURE_BASE_DIR=$(cygpath -a "$2")

+                                  if [ "$?" = "0" ]; then

+                                              CAPTURE_OUTPUT_DIR=$(cygpath
-a "$3")

+                                  else

+                                              # XXX convert . or .. on non
cygwin systems

+                                              CAPTURE_BASE_DIR=$2

+                                              CAPTURE_OUTPUT_DIR=$3

+                                  fi

+

+                                  # if a trailing / is in directory name
then remove it

+                                  CAPTURE_BASE_DIR=${CAPTURE_BASE_DIR%/}

+
CAPTURE_OUTPUT_DIR=${CAPTURE_OUTPUT_DIR%/}

+                                  

+                                  INDEX_POS=$(expr index '$PWD'
'$CAPTURE_BASE_DIR')

+                                  if [ "$INDEX_POS" != "1" ]; then

+                                              echo "base directory:
'$CAPTURE_BASE_DIR' is not a parent of present directory: '$PWD'"

+                                  fi

+

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2'
'$3'"

+                                  shift

+                                  shift

                                    shift

                                    ;;

                        -f|--file)

                                    mmake="$2"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2'"

                                    shift

                                    shift

                                    ;;

                        -v|--verbose)

                                    verbose=true

                                    MMAKE="$MMAKE $1"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        -v-|--no-verbose)

                                    verbose=false

                                    MMAKE="$MMAKE $1"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        -w|--warn-undefined-vars)

                                    warn_undefined_vars=true

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        -w-|--no-warn-undefined-vars)

                                    warn_undefined_vars=false

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        --include-makefile)

                                    # XXX check that $2 exists first

                                    MMAKE="$MMAKE $1 $2"

                                    include_makefile="$include_makefile $2"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2'"

                                    shift

                                    shift

                                    ;;

@@ -177,15 +250,19 @@

 
--mercury-standard-library-directory|--mercury-stdlib-dir)

                                    MERCURY_STDLIB_DIR="$2"

                                    MERCURY_CONFIG_DIR="$2"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

 
--no-mercury-standard-library-directory|--no-mercury-stdlib-dir)

                                    unset MERCURY_STDLIB_DIR

                                    unset MERCURY_CONFIG_DIR

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

+                                  shift

                                    ;;

 

 
--mercury-config-directory-directory|--mercury-config-dir)

                                    MERCURY_CONFIG_DIR="$2"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    ;;

                        # We don't allow `MERCURY_CONFIG_DIR' to be unset

@@ -193,6 +270,7 @@

 

                        --)         

                                    MMAKE="$MMAKE $1"

+                                  MMAKE_OPTIONS="$MMAKE_OPTIONS $1"

                                    shift

                                    break

                                    ;;

@@ -215,6 +293,11 @@

            export MERCURY_STDLIB_DIR

 fi

 

+if [[ "$CAPTURE_BASE_DIR" != "" && "$CAPTURE_OUTPUT_DIR" != "" ]]; then

+          export CAPTURE_BASE_DIR

+          export CAPTURE_OUTPUT_DIR

+fi

+

 case "$MMAKE_DIR" in

            "")

                        echo "mmake: MMAKE_DIR not set"

@@ -341,6 +424,32 @@

            deps=

 fi

 

+make_target=default_target

+

+# XXX While not an exact method to detect make targets, 

+# it does the job.

+for PARM in "$@"

+do

+          case "$PARM" in

+                      # Skip any options starting with -- that are unknown.

+                      --*)

+                                  ;;

+                      # Skip any options starting with - that are unknown.

+                      -*)

+                                  ;;

+                      # Skip any options with = in them that are unknown.

+                      *=*)

+                                  ;;

+                      # If there are any parameters left and they are not
an option

+                      # then it is hoped that they are make targets.

+                      *)

+                                  # While there may be more than one
target, we only use the first one

+                                  make_target="$PARM"

+                                  break

+                                  ;;

+          esac

+done

+

 if $verbose; then

            echo MMAKE=$MMAKE

            echo export MMAKE

@@ -379,9 +488,71 @@

 echo 'endif'

 cat $deps ${MMAKE_RULES}

 } > $tmp

+

+if [[ "$CAPTURE_BASE_DIR" != "" && "$CAPTURE_OUTPUT_DIR" != "" ]]; then

+

+echo

+echo "PWD="$PWD

+echo "command: " $0 $@

+echo

+

+# create output file with a date/time stamp and subdirectory in name

+current_dir=$PWD

+# remove the base directory from the current directory

+subdirectory=${current_dir#${CAPTURE_BASE_DIR}}

+# if a leading / is in subdirectory then remove it

+subdirectory=${subdirectory#/}

+# Can not have / in a file name so replace all / with - in subdirectory.

+subdirectory=${subdirectory//\//-}

+timestamp=$(date +%Y-%m-%d-%H-%M-%S)

+# append .txt to show that it is a text file

+makecapture=$CAPTURE_OUTPUT_DIR/make.$timestamp.$subdirectory.$make_target.
txt

+#append .Makefile because it is a Makefile

+makefilename=$CAPTURE_OUTPUT_DIR/make.$timestamp.$subdirectory.$make_target
.Makefile

+

+echo
"---------------------------------------------------------------------------
------" > $makecapture

+echo >> $makecapture

+echo "PWD: "$PWD >> $makecapture

+echo "Mercury make command that started process: " $0 $MMAKE_OPTIONS $@ >>
$makecapture

+echo "Standard make command to be executed:      " ${MMAKE_MAKE}
${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} $@ >> $makecapture

+echo >> $makecapture

+echo "Note: Standard makefile $tmp saved as '$makefilename'"  >>
$makecapture 

+cp $tmp "$makefilename"

+echo "Files combined into standard makefile:" >> $makecapture

+echo $'\t'"Vars:             "$MMAKE_VARS >> $makecapture

+echo $'\t'"dv:               "$dvs >> $makecapture

+echo $'\t'"Mercury makefile: "$PWD/$MMAKEFILE >> $makecapture

+echo $'\t'"d:                "$ds >> $makecapture

+echo $'\t'"Dependencies:     "$deps >> $makecapture

+echo $'\t'"Rules:            "$MMAKE_RULES >> $makecapture

+echo >> $makecapture

+echo Include files such as Mmake.common, VERSION, Mmake.workspace,
Merucry.options, Mmake.parms may also be used, but are not list here do to
the complexity. >> $makecapture

+echo >> $makecapture

+echo
"---------------------------------------------------------------------------
------" >> $makecapture

+echo >> $makecapture

+

+case $# in

+          # Note that we can't use `exec' here, because if we did that,

+          # that `trap' code which removes $tmp would never get executed.

+          0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm}
>> $makecapture 2>&1 ;;

+          *) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm}
"$@" >> $makecapture 2>&1 ;;

+esac

+

+else

+

 case $# in

            # Note that we can't use `exec' here, because if we did that,

            # that `trap' code which removes $tmp would never get executed.

            0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm}
;;

            *) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm}
"$@" ;;

 esac

+

+fi

+

+if $capture_makeprocess; then

+          # clean up temporary exported values

+          CAPTURE_BASE_DIR=

+          CAPTURE_OUTPUT_DIR=

+          export CAPTURE_BASE_DIR

+          export CAPTURE_OUTPUT_DIR

+fi

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20070730/8b2ed77e/attachment.html>


More information about the reviews mailing list