[llvm-commits] [llvm-top] r40112 - in /llvm-top/trunk: build clean get install library.sh

Reid Spencer rspencer at reidspencer.com
Fri Jul 20 11:42:07 PDT 2007


Author: reid
Date: Fri Jul 20 13:42:07 2007
New Revision: 40112

URL: http://llvm.org/viewvc/llvm-project?rev=40112&view=rev
Log:
Clean up these scripts:

1. Don't use recursion inside command substitution. It hides the output from the
   command which would be better printed.
2. Make an absolute recursion depth limit of 10 to prevent fork bombs in case
   someone messes up the ModuleInfo.txt dependencies.
3. Check to make sure a module doesn't depend on itself. This could happen 
   easily if the ModuleInfo.txt is copied from another module and not modified.
   The check prevents fork bombs and gives a better error message.
4. Make the output more regular. At level 0 there is no output but errors. At
   level 1 you get basic exit status summaries. At level 2 you get step-by-step
   messages and verbose output from tools. At level 3 you get debug output.

Modified:
    llvm-top/trunk/build
    llvm-top/trunk/clean
    llvm-top/trunk/get
    llvm-top/trunk/install
    llvm-top/trunk/library.sh

Modified: llvm-top/trunk/build
URL: http://llvm.org/viewvc/llvm-project/llvm-top/trunk/build?rev=40112&r1=40111&r2=40112&view=diff

==============================================================================
--- llvm-top/trunk/build (original)
+++ llvm-top/trunk/build Fri Jul 20 13:42:07 2007
@@ -28,13 +28,11 @@
 # Process the arguments so that anything starting with - is passed down to the
 # configure scripts while anything else is a module name. Collect the arguments
 # in appropriate variables for later use.
-msg 2 "Checking out dependencies"
 process_arguments "$@"
 
 # Get (and possibly check out) the set of modules and their dependencies. This
 # sets the MODULE_DEPENDENCIES variable to the set of module names that should
 # be configured, in the correct order (least dependent first, no duplicates).
-msg 1 "Checking out dependencies"
 get_module_dependencies $MODULES
 
 # Build a list of the static build options we'll pass to the modules
@@ -44,7 +42,6 @@
 # Now that we have a list of dependent modules, we must configure each of them
 # according to the specifications of the module.
 for mod in $MODULE_DEPENDENCIES ; do
-  msg 1 "Building module $mod" 
   build_a_module "$mod"
 done
 

Modified: llvm-top/trunk/clean
URL: http://llvm.org/viewvc/llvm-project/llvm-top/trunk/clean?rev=40112&r1=40111&r2=40112&view=diff

==============================================================================
--- llvm-top/trunk/clean (original)
+++ llvm-top/trunk/clean Fri Jul 20 13:42:07 2007
@@ -21,10 +21,13 @@
 for mod in $MODULE_DEPENDENCIES ; do
   get_module_info $mod CleanCmd
   if test ! -z "$MODULE_INFO_VALUE" ; then
-    msg 0 Cleaning module $mod
+    msg 1 Cleaning module $mod
     cd $mod
     $MODULE_INFO_VALUE || die $? "Clean of module $mod failed."
   else
-    msg 0 Module $mod has no CleanCmd in the ModuleInfo.txt
+    msg 2 Module $mod has no CleanCmd in the ModuleInfo.txt
   fi
 done
+
+# Report what happened.
+msg 1 Modules cleaned: "$MODULE_DEPENDENCIES".

Modified: llvm-top/trunk/get
URL: http://llvm.org/viewvc/llvm-project/llvm-top/trunk/get?rev=40112&r1=40111&r2=40112&view=diff

==============================================================================
--- llvm-top/trunk/get (original)
+++ llvm-top/trunk/get Fri Jul 20 13:42:07 2007
@@ -17,4 +17,4 @@
 get_module_dependencies $MODULES
 
 # Report what happened.
-msg 0 Got: "$MODULE_DEPENDENCIES".
+msg 1 Modules checked out:"$MODULE_DEPENDENCIES".

Modified: llvm-top/trunk/install
URL: http://llvm.org/viewvc/llvm-project/llvm-top/trunk/install?rev=40112&r1=40111&r2=40112&view=diff

==============================================================================
--- llvm-top/trunk/install (original)
+++ llvm-top/trunk/install Fri Jul 20 13:42:07 2007
@@ -23,11 +23,14 @@
 for mod in $MODULE_DEPENDENCIES ; do
   get_module_info $mod InstallCmd
   if test ! -z "$MODULE_INFO_VALUE" ; then
-    msg 0 Installing module $mod
+    msg 1 Installing module $mod
     cd $mod
     $MODULE_INFO_VALUE || die $? "Install of module $mod failed."
     cd $LLVM_TOP
   else
-    msg 0 Module $mod has no InstallCmd in the ModuleInfo.txt
+    msg 2 Module $mod has no InstallCmd in the ModuleInfo.txt
   fi
 done
+
+# Report what happened.
+msg 1 Modules installed: "$MODULE_DEPENDENCIES".

Modified: llvm-top/trunk/library.sh
URL: http://llvm.org/viewvc/llvm-project/llvm-top/trunk/library.sh?rev=40112&r1=40111&r2=40112&view=diff

==============================================================================
--- llvm-top/trunk/library.sh (original)
+++ llvm-top/trunk/library.sh Fri Jul 20 13:42:07 2007
@@ -28,7 +28,7 @@
 
 # Generate an informative message to the user based on the verbosity level
 msg() {
-  level=$1
+  local level=$1
   shift
   if test "$level" -le "$VERBOSE" ; then
     echo "TOP-$level: $*"
@@ -37,13 +37,15 @@
 
 # Die with an error message
 die() {
-  EXIT_CODE=$1
+  local code=$1
   shift
-  echo "TOP-$EXIT_CODE: Error: $*"
-  exit $EXIT_CODE
+  echo "TOP-$code: Error: $*"
+  exit $code
 }
 
 process_arguments() {
+  msg 2 "Processing arguments"
+  local arg=""
   for arg in "$@" ; do
     case "$arg" in
       LLVM_TOP=*) LLVM_TOP=`echo "$arg" | sed -e 's/LLVM_TOP=//'` ;;
@@ -63,6 +65,7 @@
   # now if we didn't get any modules on the command line.
   if test -z "$MODULES" ; then
     MODULES=""
+    local modinfo=""
     for modinfo in */ModuleInfo.txt ; do
       mod=`dirname $modinfo`
       mod=`basename $modinfo`
@@ -73,22 +76,27 @@
 
 # Check out a single module. 
 checkout_a_module() {
-  module=$1
+  local module=$1
+  msg 1 "Checking out module '$module'"
   if test -d "$module" ; then
-    msg 0 "Module $module is already checked out."
+    msg 2 "Module '$module' is already checked out."
     return 0
   fi
   if test -e "$module" ; then
-    msg 0 "Module $module is not a directory! Checkout skipped."
+    die 2 "Module '$module' is not a directory!"
     return 0
   fi
-  msg 1 "Checking out module $module"
+  local quiet=""
+  if test "$VERBOSE" -le 1 ; then
+    quiet="-q"
+  fi
+  msg 3 "Running svn checkout for '$module'"
   if test "$module" = "llvm-gcc-4.0" ; then
-    $SVN checkout svn://anonsvn.opensource.apple.com/svn/llvm/trunk $module ||
-      die $? "Checkout of module $module failed."
+    $SVN checkout $quiet svn://anonsvn.opensource.apple.com/svn/llvm/trunk \
+      $module || die $? "Checkout of module $module failed."
   else
-    $SVN checkout $SVNROOT/$module/trunk $module || \
-      die $? "Checkout of module $module failed."
+    $SVN checkout $quiet $SVNROOT/$module/trunk $module || \
+      die $? "Checkout of module '$module' failed."
   fi
   return 0
 }
@@ -97,20 +105,21 @@
 # the module isn't already checked out, then it gets checked out. The value
 # of the info item is returned in the MODULE_INFO_VALUE variable.
 get_module_info() {
-  module="$1"
-  item_name="$2"
+  local module="$1"
+  local item_name="$2"
+  msg 2 "Getting '$item_name' module info for '$module'"
   if test ! -d "$module" ; then
     checkout_a_module "$module" || die $? "Checkout failed."
   fi
-  module_info="$module/ModuleInfo.txt"
+  local module_info="$module/ModuleInfo.txt"
   if test -f "$module_info" ; then
-    item_value=`grep -i "$item_name:" $module_info | \
+    local item_value=`grep -i "$item_name:" $module_info | \
                 sed -e "s/$item_name: *//g"`
     if test "$?" -ne 0 ; then 
       die $? "Searching file '$module_info for $item_name' failed."
     fi
   else
-    msg 0 "Module $module has no ModuleInfo.txt file (ignored)."
+    msg 1 "Module $module has no ModuleInfo.txt file (ignored)."
   fi
   MODULE_INFO_VALUE="$item_value"
 }
@@ -121,41 +130,68 @@
 # have been satisfied. Upon exit the MODULE_DEPENDENCIES variable contains
 # the list of module names from least dependent to most dependent in the
 # correct configure/build order.
-get_module_dependencies() {
-  for module in $* ; do
-    get_module_info $module DepModule
-    if test ! -z "$MODULE_INFO_VALUE" ; then
-      msg 1 "Module '$module' depends on $MODULE_INFO_VALUE"
-      deps=`get_module_dependencies $MODULE_INFO_VALUE` || \
-         die $? "get_module_dependencies failed"
-      for dep in $MODULE_INFO_VALUE ; do
-        matching=`echo "$MODULE_DEPENDENCIES" | grep "$dep"`
-        if test -z "$matching" ; then
-          MODULE_DEPENDENCIES="$MODULE_DEPENDENCIES $dep"
-        fi
-      done
+add_module_if_not_duplicate() {
+  local mod_to_add="$1"
+  local mod=""
+  for mod in $MODULE_DEPENDENCIES ; do
+    local has_mod=`echo "$mod" | grep "$mod_to_add"`
+    if test ! -z "$has_mod" ; then
+      return 0
     fi
-    matching=`echo "$MODULE_DEPENDENCIES" | grep "$module"`
-    if test -z "$matching" ; then
-      MODULE_DEPENDENCIES="$MODULE_DEPENDENCIES $module"
+    msg 3 "Looping in add_module_if_not_duplicate"
+  done
+  msg 2 "Adding module '$mod_to_add' to list"
+  MODULE_DEPENDENCIES="$MODULE_DEPENDENCIES $mod_to_add"
+}
+
+get_a_modules_dependencies() {
+  if test "$RECURSION_DEPTH" -gt 10 ; then
+    die 2 "Recursing too deeply on module dependencies"
+  fi
+  let RECURSION_DEPTH="$RECURSION_DEPTH + 1"
+  local module="$1"
+  msg 2 "Getting dependencies for module '$module'"
+  get_module_info $module DepModule
+  if test ! -z "$MODULE_INFO_VALUE" ; then
+    local my_deps="$MODULE_INFO_VALUE"
+    msg 2 "Module '$module' depends on '$my_deps'"
+    local has_me=`echo "$my_deps" | grep "$module"`
+    if test -z "$has_me" ; then
+      local dep=""
+      for dep in $my_deps ; do
+        get_a_modules_dependencies "$dep"
+        msg 3 "Looping in get_a_modules_dependencies"
+      done
+    else
+      die 1 "Module '$module' has a dependency on itself!"
     fi
+  fi
+  add_module_if_not_duplicate "$1"
+}
+
+get_module_dependencies() {
+  msg 2 "Getting module dependencies: $*"
+  local module=""
+  for module in "$@" ; do
+    RECURSION_DEPTH=0
+    get_a_modules_dependencies $module
+    msg 3 "Looping in get_module_dependencies"
   done
-  return 0
 }
 
 build_a_module() {
-  module="$1"
-  msg 2 "Getting module info for $module"
+  local module="$1"
+  msg 1 "Building module '$module'"   
   get_module_info $module BuildCmd
   if test -z "$MODULE_INFO_VALUE" ; then
-    msg 0 "Module $module has no BuildCmd entry so it will not be built."
+    msg 2 "Module $module has no BuildCmd entry so it will not be built."
     return 0
   fi
-  build_cmd="$MODULE_INFO_VALUE MODULE=$module $build_args"
-  msg 1 "Building Module $module with this command:"
-  msg 1 "  $build_cmd"
+  local build_cmd="$MODULE_INFO_VALUE MODULE=$module $build_args"
+  msg 1 "Building Module '$module'"
+  msg 2 "Build Command: $build_cmd"
   cd $module
-  $build_cmd || die $? "Build of $module failed."
+  $build_cmd || die $? "Build of module '$module' failed."
   cd $LLVM_TOP
 }
 





More information about the llvm-commits mailing list