bug-texinfo
[Top][All Lists]
Advanced

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

FYI: --mostly-clean and aux file management strengthening


From: Akim Demaille
Subject: FYI: --mostly-clean and aux file management strengthening
Date: Thu, 22 Dec 2005 16:20:16 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Hi,

This patch does really two related things:

- to strengthen the handling of aux files, because I have finally
  discovered that the log files contains very useful and easily
  accessible information.

- to implement a --mostly-clean option.  I know Karl doesn't like this
  name, but currently I know none better, and it really means what it
  does: removing the by-products of a compilation, just as
  mostly-clean in Makefiles.

I have exercised it quite a bit, but the test suite is not strong
enough, so I fear there remains issues.  I'm checking in anyway,
because it works in the common cases, and if there remain bugs, that
the best means to have them reported...

It doesn't work for HTML (yet).


Index: ChangeLog
from  Akim Demaille  <address@hidden>

        Implement --mostly-clean, improve the detection of aux files.
        * util/texi2dvi ($action): New.
        (--mostly-clean): New.
        (cd_orig): New.
        (generated_files_get, aux_file_p, index_file_p, xref_files_p):
        New.
        (get_index_files): Remove, replaced by the previous functions.
        (get_xref_files): Rename as...
        (xref_files_get): this.
        (run_index): Use generated_files_get.
        (clean): Rename as...
        (mostly_clean): this.
        Strengthen.
        ($t2ddir): Try to have a `local' absolute file name, not a fully
        absolute one to avoid very very long file names.
        * util/texi2dvi.test: Exercise --mostly-clean.

Index: doc/texi2dvi.1
===================================================================
RCS file: /cvsroot/texinfo/texinfo/doc/texi2dvi.1,v
retrieving revision 1.44
diff -u -u -r1.44 texi2dvi.1
--- doc/texi2dvi.1 19 Dec 2005 16:58:52 -0000 1.44
+++ doc/texi2dvi.1 22 Dec 2005 15:14:42 -0000
@@ -1,5 +1,5 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.36.
-.TH TEXI2DVI "1" "December 2005" "texi2dvi 1.67" "User Commands"
+.TH TEXI2DVI "1" "December 2005" "texi2dvi 1.68" "User Commands"
 .SH NAME
 texi2dvi \- convert Texinfo documents to DVI
 .SH SYNOPSIS
@@ -89,6 +89,10 @@
 specify where the tidy compilation is performed.
 implies \fB\-\-tidy\fR
 defaults to TEXI2DVI_BUILD_DIRECTORY [/tmp/akim.t2d]
+.TP
+\fB\-\-mostly\-clean\fR
+remove the auxiliary files and directories
+but not the output
 .PP
 The MODE specifies where the TeX compilation takes place, and, as a
 consequence, how auxiliary files are treated.  The build mode
Index: doc/version.texi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/doc/version.texi,v
retrieving revision 1.33
diff -u -u -r1.33 version.texi
--- doc/version.texi 16 Nov 2005 17:46:33 -0000 1.33
+++ doc/version.texi 22 Dec 2005 15:14:43 -0000
@@ -1,4 +1,4 @@
address@hidden UPDATED 13 November 2005
address@hidden UPDATED-MONTH November 2005
address@hidden UPDATED 22 December 2005
address@hidden UPDATED-MONTH December 2005
 @set EDITION 4.8
 @set VERSION 4.8
Index: util/texi2dvi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/util/texi2dvi,v
retrieving revision 1.68
diff -u -u -r1.68 texi2dvi
--- util/texi2dvi 19 Dec 2005 16:58:52 -0000 1.68
+++ util/texi2dvi 22 Dec 2005 15:14:43 -0000
@@ -91,6 +91,8 @@
       --build-dir=DIR  specify where the tidy compilation is performed.
                        implies --tidy
                        defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
+  --mostly-clean       remove the auxiliary files and directories
+                       but not the output
 
 The MODE specifies where the TeX compilation takes place, and, as a
 consequence, how auxiliary files are treated.  The build mode
@@ -135,14 +137,15 @@
 # Initialize variables for option overriding and otherwise.
 # Don't use `unset' since old bourne shells don't have this command.
 # Instead, assign them an empty value.
-line_error=true # Pass --file-line-error to TeX.
+action=compile
 batch=false     # true for batch mode
 debug=false
 escape="\\"
 expand=         # t for expansion via makeinfo
 includes=
-out_lang=dvi
+line_error=true # Pass --file-line-error to TeX.
 oname=          # --output
+out_lang=dvi
 quiet=false     # by default let the tools' message be displayed
 recode=false
 set_language=
@@ -188,6 +191,20 @@
 }
 
 
+# cd_orig
+# -------
+# Return to the original directory.
+cd_orig ()
+{
+  # In case $orig_pwd is on a different drive (for DOS).
+  cd /
+
+  # Return to the original directory so that
+  # - the next file is processed in correct conditions
+  # - the temporary file can be removed
+  cd "$orig_pwd" || exit 1
+}
+
 # func_dirname FILE
 # -----------------
 # Return the directory part of FILE.
@@ -364,19 +381,6 @@
 done
 
 
-# get_index_files FILE1 FILE2...
-# ------------------------------
-# Select the files that are indexes to run texindex/makeindex onto.
-get_index_files ()
-{
-  for file
-  do
-    case `sed '1q' $file` in
-      "\\entry{"*|"\\indexentry{"*) echo "$file";;
-    esac
-  done
-}
-
 # absolute_filenames TEX-PATH -> TEX-PATH
 # ---------------------------------------
 # Convert relative paths to absolute paths, so we can run in another
@@ -453,43 +457,96 @@
 ## Managing xref files.  ##
 ## --------------------- ##
 
+# aux_file_p FILE
+# ---------------
+# Return with success with FILE is an aux file.
+aux_file_p ()
+{
+  case $1 in
+    *.aux) return 0;;
+    *)     return 1;;
+  esac
+}
 
-# xref_files_get FILENAME-NOEXT
-# -----------------------------
-# Compute the list of xref files (indexes, tables and lists).
-xref_files_get ()
+# index_file_p FILE
+# -----------------
+# Return with success with FILE is an index file.
+index_file_p ()
 {
-  if $tidy; then
-    # In a tidy build, all the files around as actual outputs.
-    ls * 2>/dev/null
-  else
-    # Find all files having root filename with a two-letter extension,
-    # saves the ones that are really Texinfo-related files.
-    # - .?o?
-    #   .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
-    # - bu[0-9]*.aux
-    #   Sub bibliography when using the LaTeX bibunits package.
-    ls "$1".?o? "$1".aux bu[0-9]*.aux "$1".?? "$1".idx 2>/dev/null
-  fi |
+  case `sed '1q' $1` in
+    "\\entry{"*|"\\indexentry{"*) return 0;;
+    *) return 1;;
+  esac
+}
+
+# xref_file_p FILE
+# ----------------
+# Return with success if FILE is an xref file (indexes, tables and lists).
+xref_file_p ()
+{
+  # If the file is not suitable to be an index or xref file, don't
+  # process it.  It's suitable if the first character is a
+  # backslash or right quote or at, as long as the first line isn't
+  # \input texinfo.
+  case `sed '1q' $1` in
+    "\\input texinfo"*) return 1;;
+    [\\''@]*)           return 0;;
+           *)           return 1;;
+  esac
+}
+
+
+# generated_files_get FILENAME-NOEXT [PREDICATE-FILTER]
+# -----------------------------------------------------
+# Return the list of files generated by the TeX compilation of FILENAME-NOEXT.
+generated_files_get ()
+{
+  local filter=true
+  if test -n "$2"; then
+    filter=$2
+  fi
+
+  # Gather the files created by TeX.
+  (
+    if test -f "$1.log"; then
+      sed -n -e "s,^\\\\openout.* = \`\\(.*\\)'\\.,\\1,p" "$1.log"
+    fi
+    echo "$1.log"
+  ) |
+  # Depending on these files, infer outputs from other tools.
   while read file; do
-    # If the file is not suitable to be an index or xref file, don't
-    # process it.  It's suitable if the first character is a
-    # backslash or right quote or at, as long as the first line isn't
-    # \input texinfo.
-    case `sed '1q' $file` in
-      "\\input texinfo"*) ;;
-      [\\''@]*) echo "./$file";;
+    echo $file
+    case $language in
+      (texinfo)
+        # texindex: texinfo.cp -> texinfo.cps
+       index_file_p $file && echo ${file}s
+       ;;
+      (latex)
+       # bibtex: *.aux -> *.bbl and *.blg.
+        if aux_file_p $file; then
+          echo $file | sed 's/^\(.*\)\.aux$/\1.bbl/'
+         echo $file | sed 's/^\(.*\)\.aux$/\1.blg/'
+       fi
+       ;;
     esac
-  done
+  done |
+  # Filter existing files matching the criterion.
+  while read file; do
+    if test -f $file && $filter $file; then
+      echo $file
+    fi
+  done |
+  sort
 }
 
+
 # xref_files_save
 # ---------------
 # Save the xref files.
 xref_files_save ()
 {
   # Save copies of auxiliary files for later comparison.
-  xref_files_orig=`xref_files_get  "$in_noext"`
+  xref_files_orig=`generated_files_get "$in_noext" xref_file_p`
   if test -n "$xref_files_orig"; then
     verbose "Backing up xref files: $xref_files_orig"
     cp $xref_files_orig "$work_bak"
@@ -512,7 +569,7 @@
 
   # If old and new lists don't at least have the same file list,
   # then one file or another has definitely changed.
-  xref_files_new=`xref_files_get  "$in_noext"`
+  xref_files_new=`generated_files_get "$in_noext" xref_file_p`
   verbose "Original xref files = $xref_files_orig"
   verbose "New xref files      = $xref_files_new"
   test "x$xref_files_orig" != "x$xref_files_new" &&
@@ -533,6 +590,8 @@
   return 1
 }
 
+
+
 ## ----------------------- ##
 ## Running the TeX suite.  ##
 ## ----------------------- ##
@@ -655,9 +714,8 @@
           || grep 'No file .*\.bbl\.' "$in_noext.log") \
         >&6 2>&1; \
   then
-    # If using the bibunits package, we might have to run bibtex
-    # on subfiles.
-    for f in "$in_noext".aux bu[0-9]*.aux
+    generated_files_get "$in_noext" |
+    while read f
     do
       if test -s "$f" && \
          (grep '^\\bibstyle[{]' "$f"   \
@@ -687,7 +745,7 @@
     latex)   texindex=${MAKEINDEX:-makeindex};;
     texinfo) texindex=${TEXINDEX:-texindex};;
   esac
-  index_files=`get_index_files $xref_files_orig`
+  index_files=`generated_files_get $in_noext index_file_p`
   if test -n "$texindex" && test -n "$index_files"; then
     verbose "Running $texindex $index_files ..."
     $texindex $index_files 2>&5 1>&2 ||
@@ -966,13 +1024,7 @@
     html   ) run_to_html;;
   esac
 
-  # In case $orig_pwd is on a different drive (for DOS).
-  cd /
-
-  # Return to the original directory so that
-  # - the next file is processed in correct conditions
-  # - the temporary file can be removed
-  cd "$orig_pwd" || exit 1
+  cd_orig
 }
 
 
@@ -1016,32 +1068,19 @@
 }
 
 
-# clean ()
-# --------
-# Remove auxiliary files.
-clean ()
+# mostly_clean ()
+# ---------------
+# Remove auxiliary files and directories.
+mostly_clean ()
 {
-  # In case $orig_pwd is on a different drive (for DOS).
-  cd /
-
-  # Return to the original directory so that
-  # - the next file is processed in correct conditions
-  # - the temporary file can be removed
-  cd "$orig_pwd" || exit 1
-
-  if $tidy; then
-    # Simply remove the build dir.
-    verbose "Removing $t2ddir"
-    rm -rf "$t2ddir"
-  else
-    # Find the auxiliary files, and remove them.
+  cd_orig
+  local to_remove="$t2ddir"
+  $tidy || {
     local log=$work_build/$in_noext.log
-    if test -f "$log"; then
-      local aux=$(sed -n "s,^\\\\openout.* = \`\\(.*\\)'\\.,$work_build/\\1,p" 
"$log")
-      cp $work_build/$in_noext.log /tmp
-      echo rm $aux
-    fi
-  fi
+    to_remove=$to_remove" $log "$(generated_files_get "$work_build/$in_noext")
+  }
+  verbose "Removing" $to_remove
+  rm -rf $to_remove
 }
 
 
@@ -1093,6 +1132,7 @@
       list_append includes "$val"
       ;;
     -l | --lang | --language) shift; set_language=$1;;
+    --mostly-clean) action=mostly-clean;;
     -o | --out  | --output)
       shift
       # Make it absolute, just in case we also have --clean, or whatever.
@@ -1124,9 +1164,9 @@
 shift
 
 # $tidy:  compile in a t2d directory.
-# $clean: remove the t2d directory afterward.
+# $clean: remove all the aux files.
 case $build_mode in
-  local) clean=true;  tidy=false;;
+  local) clean=false; tidy=false;;
   tidy)  clean=false; tidy=true;;
   clean) clean=true;  tidy=true;;
       *) fatal 1 "invalid build mode: $build_mode";;
@@ -1303,12 +1343,15 @@
   case $build_dir in
       '' | . ) t2ddir=$out_noext.t2d ;;
       *) # Avoid collisions between multiple occurrences of the same
-        # file.
-        t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" | sed 's,/,!,g'`
+        # file.  The sed expression is fragile if the cwd has
+        # active characters.
+        t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" |
+             sed "s,^$orig_pwd/,," |
+             sed 's,/,!,g'`
   esac
   # Remove it at exit if clean mode.
   $clean &&
-    trap "clean" 0 1 2 15
+    trap "mostly_clean" 0 1 2 15
 
   ensure_dir "$build_dir" "$t2ddir"
 
@@ -1334,11 +1377,18 @@
   # Make those directories.
   ensure_dir "$work_build" "$work_bak"
 
-  # Compile the document.
-  compile
+  case $action in
+    compile)
+      # Compile the document.
+      compile
+      # Remove temporary files.
+      $clean && mostly_clean
+      ;;
 
-  # Remove temporary files.
-  $clean && clean
+    mostly-clean)
+      mostly_clean
+      ;;
+  esac
 done
 
 verbose "done."
Index: util/texi2dvi.test
===================================================================
RCS file: /cvsroot/texinfo/texinfo/util/texi2dvi.test,v
retrieving revision 1.5
diff -u -u -r1.5 texi2dvi.test
--- util/texi2dvi.test 11 Nov 2005 00:02:31 -0000 1.5
+++ util/texi2dvi.test 22 Dec 2005 15:14:43 -0000
@@ -45,7 +45,9 @@
 TEXI2DVI_pass --build=tidy --batch input.texi -o output.dvi
 # There should only be the DVI and the TEXI file.
 test "`list_files`" = "input.texi output.dvi output.t2d"
-rm -r output.t2d output.dvi
+TEXI2DVI_pass --build=tidy --batch input.texi -o output.dvi --mostly-clean
+test "`list_files`" = "input.texi output.dvi"
+rm output.dvi
 
 cp input.texi input2.texi
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]