[SM-Commit] GIT changes to master sorcery by Andrew Stitt (1693807b4c35b0262f4ba9c309d4cae516f7b9e3)

Andrew Stitt scm at mail.sourcemage.org
Sun Aug 20 13:37:33 EDT 2006


GIT changes to master sorcery by Andrew Stitt <astitt at sourcemage.org>:

 ChangeLog                              |   16 +
 var/lib/sorcery/modules/build_api/api1 |   53 +-----
 var/lib/sorcery/modules/build_api/api2 |   80 +--------
 var/lib/sorcery/modules/libapi         |  266 +++++++++++++--------------------
 var/lib/sorcery/modules/libcast        |    4 
 var/lib/sorcery/modules/libdepends     |  106 ++++---------
 var/lib/sorcery/modules/libdispel      |   28 ---
 var/lib/sorcery/modules/libspell       |  184 ++++++++++++++++++++++
 var/lib/sorcery/modules/libsummon      |   11 -
 var/lib/sorcery/modules/libtriggers    |    6 
 10 files changed, 381 insertions(+), 373 deletions(-)

New commits:
commit 1693807b4c35b0262f4ba9c309d4cae516f7b9e3
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    update changelog

commit ad1ff42eefded2d8c6a366115d0979abdc8b5190
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    more changes for 10914
    any spell file can have a <FILENAME>_CMD in DETAILS, except PREPARE by nature
    added a way for sorcery to specify a message to run if the spell file
    exists -- wont work particularly well for section/grimoire files though
    updated libapi docs

commit 748bed1b3b8ad4f69669952a2f73e3a16e9c24c8
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    add sanity check to libdepends

commit 134bdc86e2801bc03b664f0babbbd7dba7654464
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    most of the alpha-level work for bug 10914, seems to work, needs more testing

commit a4fde6d34aa28e59effb44f339d52e7381b473d9
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    always persistent_save

commit 23955205a2c2c4f239fdf1a3ec3f77b6819c971b
Author: Andrew Stitt <astitt at sourcemage.org>
Commit: Andrew Stitt <astitt at sourcemage.org>

    add trivial function to walk inheritence tree

diff --git a/ChangeLog b/ChangeLog
index b47e7b3..c05c281 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2006-09-20 Andrew Stitt <astitt at sourcemage.org>
+	* libspell: new library for all spell execution (except DETAILS
+	  for now). Handles inheritence scheme and creates function stubs
+	  automatically for every file. Fixes bug 10914.
+	* build_api/api1, build_api/api2, libcast, libdepends, libdispel,
+	  libsummon, libtriggers: remove old file execution code,
+	  and use run_spell_file
+	* libapi: update documentation, add blurb about default_*_<filename>
+	  functions. Remove no-op stubs since they exist for everything
+	  implicitly. Change default_<filename> functions to
+	  default_sorcery_<filename> to remove confusion.
+
+2006-09-19 Andrew Stitt <astitt at sourcemage.org>
+	* libdepends: raise an error if a spell or provider name contains
+	  a space
+
 2006-08-13 Paul Mahon <pmahon at sourcemage.org>
 	* cast: shorten screen names (fixes bug #12133)
 
diff --git a/var/lib/sorcery/modules/build_api/api1 b/var/lib/sorcery/modules/build_api/api1
index a47f1ab..f345d4b 100755
--- a/var/lib/sorcery/modules/build_api/api1
+++ b/var/lib/sorcery/modules/build_api/api1
@@ -91,17 +91,7 @@ function run_pre_build() {
   mkdir -p  $BUILD_DIRECTORY
   cd  $BUILD_DIRECTORY
 
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/PRE_BUILD  ];  then
-    debug "build_api/api1" "run_pre_build() - Prebuild script exists, now sourcing "
-    . $SCRIPT_DIRECTORY/PRE_BUILD
-  elif [[ "$PRE_BUILD_CMD" ]] ; then
-    $PRE_BUILD_CMD
-  else
-    debug "build_api/api1" "run_pre_build() - Prebuild script not found, using default"
-    default_pre_build
-  fi &&
-  persistent_save
+  run_spell_file PRE_BUILD pre_build
 }
 
 
@@ -132,15 +122,7 @@ function run_build()  {
 
   run_config_loc
   (
-    persistent_load &&
-    if  [  -x  $SCRIPT_DIRECTORY/BUILD  ];  then
-      .  $SCRIPT_DIRECTORY/BUILD
-    elif [[ "$BUILD_CMD" ]] ; then
-      $BUILD_CMD
-    else
-      default_build
-    fi &&
-    persistent_save
+    run_spell_file BUILD build
   ) 2> >(tee -a $C_LOG 1>&2 >> $VOYEUR_STDERR) \
      > >(tee -a $C_LOG >> $VOYEUR_STDOUT) # see bug 7201
 
@@ -163,15 +145,7 @@ #---------------------------------------
 function run_post_build() {
 
   debug "build_api/api1" "Starting run_post_build()"
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/POST_BUILD  ];  then
-           . $SCRIPT_DIRECTORY/POST_BUILD
-  elif [[ "$POST_BUILD_CMD" ]] ; then
-    $POST_BUILD_CMD
-  else
-    default_post_build
-  fi
-  persistent_save
+  run_spell_file POST_BUILD post_build
 
   # Lock made in prepare_install
   unlock_resources "libgrimoire" "install"
@@ -187,14 +161,7 @@ #---------------------------------------
 function run_post_install() {
 
   debug "build_api/api1" "Starting run_post_install()"
-  persistent_load &&
-  if    [  -x  $SCRIPT_DIRECTORY/POST_INSTALL  ]
-  then
-    . $SCRIPT_DIRECTORY/POST_INSTALL
-  elif [[ "$POST_INSTALL_CMD" ]] ; then
-    $POST_INSTALL_CMD
-  fi &&
-  persistent_save
+  run_spell_file INSTALL install
 }
 
 
@@ -203,9 +170,9 @@ ## @Type API
 ## Creates the source directory and unpacks the source package into it.
 ## Used if no PRE_BUILD script is found for a spell.
 #---------------------------------------------------------------------
-function real_default_pre_build() {
+function real_default_sorcery_pre_build() {
 
-  debug "build_api/api1" "Starting real_default_pre_build() - SOURCE=$SOURCE SOURCE_DIRECTORY=$SOURCE_DIRECTORY"
+  debug "build_api/api1" "Starting real_default_sorcery_pre_build() - SOURCE=$SOURCE SOURCE_DIRECTORY=$SOURCE_DIRECTORY"
   mk_source_dir        $SOURCE_DIRECTORY  &&
   unpack_file
 
@@ -230,9 +197,9 @@ ##  make    install
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function real_default_build() {
+function real_default_sorcery_build() {
 
-  debug "build_api/api1" "Starting real_default_build()"
+  debug "build_api/api1" "Starting real_default_sorcery_build()"
   OPTS="$OPTS --build=${BUILD}"
   #If this switches are used, they _may_ stop distcc and ccache from working
   # for some spells (bug 3798)
@@ -259,9 +226,9 @@ ## Installs configuration files and docu
 ## Used if no POST_BUILD script is found for a spell.
 ##
 #---------------------------------------------------------------------
-function real_default_post_build() {
+function real_default_sorcery_post_build() {
 
-  debug "build_api/api1" "Starting real_default_post_build()"
+  debug "build_api/api1" "Starting real_default_sorcery_post_build()"
 
   install_xinetd
   install_initd
diff --git a/var/lib/sorcery/modules/build_api/api2 b/var/lib/sorcery/modules/build_api/api2
index 1413172..a9a92ee 100755
--- a/var/lib/sorcery/modules/build_api/api2
+++ b/var/lib/sorcery/modules/build_api/api2
@@ -117,15 +117,7 @@ function run_pre_build() {
   cd  "$BUILD_DIRECTORY"
 
   verify_sources &&
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/PRE_BUILD  ];  then
-    . $SCRIPT_DIRECTORY/PRE_BUILD
-  elif [[ "$PRE_BUILD_CMD" ]] ; then
-    $PRE_BUILD_CMD
-  else
-    default_pre_build
-  fi &&
-  persistent_save
+  run_spell_file PRE_BUILD pre_build
 }
 
 
@@ -155,15 +147,7 @@ function run_build()  {
   pwd
   message "$SPELL    $VERSION"
 
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/BUILD  ];  then
-    .  $SCRIPT_DIRECTORY/BUILD
-  elif [[ "$BUILD_CMD" ]] ; then
-    $BUILD_CMD
-  else
-    default_build
-  fi &&
-  persistent_save
+  run_spell_file BUILD build
 
   if  [  "$?"  !=  0  ];  then
     message  "${PROBLEM_COLOR}"      \
@@ -190,15 +174,7 @@ function run_pre_install() {
     cd "$BUILD_DIRECTORY"
   fi
   
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/PRE_INSTALL  ];  then
-    .  $SCRIPT_DIRECTORY/PRE_INSTALL 
-  elif [[ "$PRE_INSTALL_CMD" ]] ; then
-    $PRE_INSTALL_CMD
-  else
-    default_pre_install
-  fi &&
-  persistent_save &&
+  run_spell_file PRE_INSTALL pre_install
   echo  "Compile log for $SPELL $VERSION Completed Build on `date  -u`"  >>  $C_LOG
   pwd > $S_PWD
 }
@@ -222,17 +198,8 @@ function run_install() {
     cd "$BUILD_DIRECTORY"
   fi
 
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/INSTALL  ];  then
-    .  $SCRIPT_DIRECTORY/INSTALL 
-  elif [[ "$INSTALL_CMD" ]] ; then
-    $INSTALL_CMD
-  else
-    default_install
-  fi &&
-  persistent_save
-
-
+  run_spell_file INSTALL install
+  
   if  [  "$?"  !=  0  ];  then
     message  "${PROBLEM_COLOR}"      \
              "! Problem Detected !"  \
@@ -260,14 +227,7 @@ function run_post_install() {
   else
     cd "${INSTALL_ROOT:-/}"
   fi &&
-  if    [  -x  $SCRIPT_DIRECTORY/POST_INSTALL  ]; then
-    . $SCRIPT_DIRECTORY/POST_INSTALL
-  elif [[ "$POST_INSTALL_CMD" ]] ; then
-    $POST_INSTALL_CMD
-  else
-    default_post_install
-  fi &&
-  persistent_save &&
+  run_spell_file POST_INSTALL post_install
   unlock_resources "libgrimoire" "install"
 }
 #--------------------------------------------------------------------
@@ -291,15 +251,7 @@ #---------------------------------------
 function run_final() {
 
   debug "build_api/api2" "Starting run_final()"
-  persistent_load &&
-  cd "${INSTALL_ROOT:-/}"
-  if    [  -x  $SCRIPT_DIRECTORY/FINAL  ]
-  then
-    . $SCRIPT_DIRECTORY/FINAL
-  elif [[ "$FINAL_CMD" ]] ; then
-    $FINAL_CMD
-  fi &&
-  persistent_save
+  run_spell_file FINAL final
 }
 
 #---------------------------------------------------------------------
@@ -308,7 +260,7 @@ ## Creates the source directory and unpa
 ## Used if no PRE_BUILD script is found for a spell.
 ##
 #---------------------------------------------------------------------
-function real_default_pre_build() {
+function real_default_sorcery_pre_build() {
 
   debug "libgrimoire" "default_pre_build() - SOURCE=$SOURCE SOURCE_DIRECTORY=$SOURCE_DIRECTORY"
   mk_source_dir        $SOURCE_DIRECTORY  &&
@@ -331,8 +283,8 @@ ##  make
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function real_default_build() {
-  debug "build_api/api2" "real_default_build"
+function real_default_sorcery_build() {
+  debug "build_api/api2" "real_default_sorcery_build"
 
   OPTS="$OPTS --build=${BUILD}"
   #If these switches are used, they _may_ stop distcc and ccache from working
@@ -359,8 +311,8 @@ ##  prepare_install
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function real_default_pre_install() {
-  debug "build_api/api2" "Starting real_default_pre_install"
+function real_default_sorcery_pre_install() {
+  debug "build_api/api2" "Starting real_default_sorcery_pre_install"
   prepare_install
 }
 
@@ -373,8 +325,8 @@ ##  make    install
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function real_default_install() {
-  debug "build_api/api2" "Starting real_default_install"
+function real_default_sorcery_install() {
+  debug "build_api/api2" "Starting real_default_sorcery_install"
   make    install
 }
 
@@ -386,9 +338,9 @@ ## Used if no POST_INSTALL script is fou
 ##
 ## This is identical to api1's post_build
 #---------------------------------------------------------------------
-function real_default_post_install() {
+function real_default_sorcery_post_install() {
 
-  debug "build_api/api2" "Starting real_default_post_install"
+  debug "build_api/api2" "Starting real_default_sorcery_post_install"
   install_xinetd
   install_initd
   install_pam_confs
diff --git a/var/lib/sorcery/modules/libapi b/var/lib/sorcery/modules/libapi
index 04db510..3392d19 100755
--- a/var/lib/sorcery/modules/libapi
+++ b/var/lib/sorcery/modules/libapi
@@ -18,72 +18,88 @@ #---------------------------------------
 
 #---------------------------------------------------------------------
 # functions defined in here: (in alphabetical order)
-#    acquire_src            (libsummon)
-#    config_query           (libmisc)
-#    config_query_list      (libmisc)
-#    config_query_option    (libmisc)
-#    config_query_string    (libmisc)
-#    conflicts              (libgrimoire)  
-#    default_build          (build_api/...)   
-#    default_configure      (libdepends)
-#    default_depends        (libdepends)
-#    default_download       (libsummon)
-#    default_install        (build_api/api2)   (BUILD_API==2 only)
-#    default_post_build     (build_api/api1)   (BUILD_API==1 only)
-#    default_post_install   (build_api/api2)   (BUILD_API==2 only)
-#    default_post_remove    (libdispel)
-#    default_pre_build      (build_api/common)   
-#    default_pre_install    (build_api/api2)   (BUILD_API==2 only)
-#    default_pre_remove     (libdispel)
-#    default_prepare        (libdepends)
-#    depends                (libdepends)
-#    devoke_installwatch    (libtrack)
-#    download_src           (libsummon)
-#    force_depends          (libdepends)
-#    gather_docs            (build_api/common)
-#    get_spell_provider     (libstate)
-#    get_source_nums        (libmisc)
-#    guess_compressor       (libunpack)
-#    handle_changed_config  (libresurrect)
-#    is_depends_enabled     (libstate)
-#    installed_version      (libgrimoire)   
-#    install_config_file    (libresurrect)
-#    invoke_installwatch    (libtrack)
-#    list_add               (libmisc)
-#    list_find              (libmisc)
-#    list_remove            (libmisc)
-#    message                (libmisc)      
-#    mk_source_dir          (libgrimoire)   
-#    on_cast                (libtriggers)   
-#    on_dispel              (libtriggers)  
-#    on_pre_cast            (libtriggers)   
-#    on_pre_dispel          (libtriggers)   
-#    optional_depends       (libdepends)
-#    persistent_add         (libmisc)
-#    persistent_clear       (libmisc)
-#    persistent_load        (libmisc)
-#    persistent_remove      (libmisc)
-#    persistent_save        (libmisc)
-#    prepare_install        (libgrimoire)   
-#    provider_ok            (libstate)
-#    query                  (libmisc)       
-#    query_string           (libmisc)
-#    runtime_depends        (libdepends)
-#    rm_source_dir          (libgrimoire)
-#    sedit                  (libmisc)       
-#    sub_depends            (libdepends)
-#    show_depends           (libdepends)
-#    spell_exiled           (libstate)
-#    spell_held             (libstate)
-#    spell_installed        (libstate)
-#    spell_ok               (libstate)
-#    suggest_depends        (libdepends)
-#    track_manual           (libtrack)
-#    uncompress             (libunpack)
-#    unpack                 (libunpack) (deprecated)
-#    unpack_file            (libunpack)
-#    unpack_file_simple     (libunpack)
-#    verify_file            (libunpack)
+#    acquire_src                    (libsummon)
+#    config_query                   (libmisc)
+#    config_query_list              (libmisc)
+#    config_query_option            (libmisc)
+#    config_query_string            (libmisc)
+#    conflicts                      (libgrimoire)  
+#    default_sorcery_build          (build_api/...)   
+#    default_sorcery_download       (libsummon)
+#    default_sorcery_install        (build_api/api2)   (BUILD_API==2 only)
+#    default_sorcery_post_build     (build_api/api1)   (BUILD_API==1 only)
+#    default_sorcery_post_install   (build_api/api2)   (BUILD_API==2 only)
+#    default_sorcery_pre_build      (build_api/common)   
+#    default_sorcery_pre_install    (build_api/api2)   (BUILD_API==2 only)
+#    depends                        (libdepends)
+#    devoke_installwatch            (libtrack)
+#    download_src                   (libsummon)
+#    force_depends                  (libdepends)
+#    gather_docs                    (build_api/common)
+#    get_spell_provider             (libstate)
+#    get_source_nums                (libmisc)
+#    guess_compressor               (libunpack)
+#    handle_changed_config          (libresurrect)
+#    is_depends_enabled             (libstate)
+#    installed_version              (libgrimoire)   
+#    install_config_file            (libresurrect)
+#    invoke_installwatch            (libtrack)
+#    list_add                       (libmisc)
+#    list_find                      (libmisc)
+#    list_remove                    (libmisc)
+#    message                        (libmisc)      
+#    mk_source_dir                  (libgrimoire)   
+#    on_cast                        (libtriggers)   
+#    on_dispel                      (libtriggers)  
+#    on_pre_cast                    (libtriggers)   
+#    on_pre_dispel                  (libtriggers)   
+#    optional_depends               (libdepends)
+#    persistent_add                 (libmisc)
+#    persistent_clear               (libmisc)
+#    persistent_load                (libmisc)
+#    persistent_remove              (libmisc)
+#    persistent_save                (libmisc)
+#    prepare_install                (libgrimoire)   
+#    provider_ok                    (libstate)
+#    query                          (libmisc)       
+#    query_string                   (libmisc)
+#    runtime_depends                (libdepends)
+#    rm_source_dir                  (libgrimoire)
+#    sedit                          (libmisc)       
+#    sub_depends                    (libdepends)
+#    show_depends                   (libdepends)
+#    spell_exiled                   (libstate)
+#    spell_held                     (libstate)
+#    spell_installed                (libstate)
+#    spell_ok                       (libstate)
+#    suggest_depends                (libdepends)
+#    track_manual                   (libtrack)
+#    uncompress                     (libunpack)
+#    unpack                         (libunpack) (deprecated)
+#    unpack_file                    (libunpack)
+#    unpack_file_simple             (libunpack)
+#    verify_file                    (libunpack)
+#
+# The following are implicitly defined for each spell file
+# (filename is first lowercased):
+# default_<filename>
+# default_section_<filename>
+# default_grimoire_<filename>
+# default_sorcery_<filename>
+#
+# It is supported to have a file at the spell, section, or grimoire level,
+# the more specific one overrides the less specific.
+# Depending on context default_<filename> calls one of the default
+# section, grimoire or sorcery functions. Calling it will always run the
+# next level up.
+#
+# The default_section_<filename> and default_grimoire_<filename> functions
+# first check for the filename (capitalized) in the section or grimoire.
+# If it doesn't exist, default_<filename> is called (which runs the next
+# step up).
+#
+# If the default_sorcery_<filename> function is not defined here, it is
+# simply "true".
 #
 # Read-only variable that might be of use to a spell:
 # SOURCE_CACHE, OPTS, BUILD HOST, INSTALL_ROOT
@@ -256,7 +272,7 @@ function conflicts () {
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_build> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_build> for more details.
 ## Used if no BUILD script is found for a spell
 ## Default build for BUILD_API==1 is:
 ## <pre>
@@ -280,50 +296,26 @@ ##  make
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function default_build () {
-    debug "libapi" "default_build - $*"
-    real_default_build "$@"
-}
-
-#---------------------------------------------------------------------
-## @Type API
-## @See <@function var.lib.sorcery.modules.libdepends.html,real_default_configure> for more details.
-##
-## Default configure code, just no-op for now.
-##
-#---------------------------------------------------------------------
-function default_configure() {
-    debug "libapi" "$FUNCNAME - $*"
-    real_default_configure "$@"
+function default_sorcery_build () {
+    debug "libapi" "default_sorcery_build - $*"
+    real_default_sorcery_build "$@"
 }
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libdepends.html,real_default_depends> for more details.
-##
-## Default depends code, just no-op for now.
-##
-#---------------------------------------------------------------------
-function default_depends() {
-    debug "libapi" "$FUNCNAME - $*"
-    real_default_depends "$@"
-}
-
-#---------------------------------------------------------------------
-## @Type API
-## @See <@function var.lib.sorcery.modules.libsummon.html,real_default_download> for more details.
+## @See <@function var.lib.sorcery.modules.libsummon.html,real_default_sorcery_download> for more details.
 ##
 ## Default download code, downloads each SOURCE[[:digit:]]*
 ##
 #---------------------------------------------------------------------
-function default_download() {
+function default_sorcery_download() {
     debug "libapi" "$FUNCNAME - $*"
-    real_default_download "$@"
+    real_default_sorcery_download "$@"
 }
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_install> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_install> for more details.
 ## Only defined for BUILD_API==2
 ## Used if no INSTALL script is found.
 ## Default install is:
@@ -332,65 +324,53 @@ ##  make    install
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function default_install () {
-    debug "libapi" "default_install - $*"
-    real_default_install "$@"
+function default_sorcery_install () {
+    debug "libapi" "default_sorcery_install - $*"
+    real_default_sorcery_install "$@"
 }
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_post_build> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_post_build> for more details.
 ## Only defined for BUILD_API==1
 ## Installs configuration files and documentation.  Stops installwatch.
 ## Used if no POST_BUILD script is found for a spell.
-## equivalent to default_post_install in BUILD_API==2
+## equivalent to default_sorcery_post_install in BUILD_API==2
 ##
 #---------------------------------------------------------------------
-function default_post_build () {
-    debug "libapi" "default_post_build - $*"
-    real_default_post_build "$@"
+function default_sorcery_post_build () {
+    debug "libapi" "default_sorcery_post_build - $*"
+    real_default_sorcery_post_build "$@"
 }
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_post_install> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_post_install> for more details.
 ## Only defined for BUILD_API==2
 ## Installs configuration files and documentation.  Stops installwatch.
 ## Used if no POST_INSTALL script is found for a spell.
-## equivalent to default_post_build in BUILD_API==1
-##
-#---------------------------------------------------------------------
-function default_post_install () {
-    debug "libapi" "default_post_install - $*"
-    real_default_post_install "$@"
-}
-
-#---------------------------------------------------------------------
-## @Type API
-## @See <@function var.lib.sorcery.modules.libdispel.html,real_default_post_remove> for more details.
-##
-## Default post_remove code, just no-op for now.
+## equivalent to default_sorcery_post_build in BUILD_API==1
 ##
 #---------------------------------------------------------------------
-function default_post_remove() {
-    debug "libapi" "$FUNCNAME - $*"
-    real_default_post_remove "$@"
+function default_sorcery_post_install () {
+    debug "libapi" "default_sorcery_post_install - $*"
+    real_default_sorcery_post_install "$@"
 }
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_pre_build> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_pre_build> for more details.
 ## Creates the source directory and unpacks the source package into it.
 ## Used if no PRE_BUILD script is found for a spell.
 #---------------------------------------------------------------------
-function default_pre_build () {
-    debug "libapi" "default_pre_build - $*"
-    real_default_pre_build "$@"
+function default_sorcery_pre_build () {
+    debug "libapi" "default_sorcery_pre_build - $*"
+    real_default_sorcery_pre_build "$@"
 } 
 
 #---------------------------------------------------------------------
 ## @Type API
-## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_pre_install> for more details.
+## @See <@function var.lib.sorcery.modules.libgrimoire.html,real_default_sorcery_pre_install> for more details.
 ## Only defined for BUILD_API==2
 ## Used if no PRE_INSTALL script is found.
 ## Default pre_install is:
@@ -399,33 +379,9 @@ ##  prepare_install
 ## </pre>
 ##
 #---------------------------------------------------------------------
-function default_pre_install () {
-    debug "libapi" "default_pre_install - $*"
-    real_default_pre_install "$@"
-}
-
-#---------------------------------------------------------------------
-## @Type API
-## @See <@function var.lib.sorcery.modules.libdispel.html,real_default_pre_remove> for more details.
-##
-## Default pre_remove code, just no-op for now.
-##
-#---------------------------------------------------------------------
-function default_pre_remove() {
-    debug "libapi" "$FUNCNAME - $*"
-    real_default_pre_remove "$@"
-}
-
-#---------------------------------------------------------------------
-## @Type API
-## @See <@function var.lib.sorcery.modules.libdepends.html,real_default_prepare> for more details.
-##
-## Default prepare code, just no-op for now.
-##
-#---------------------------------------------------------------------
-function default_prepare() {
-    debug "libapi" "$FUNCNAME - $*"
-    real_default_prepare "$@"
+function default_sorcery_pre_install () {
+    debug "libapi" "default_sorcery_pre_install - $*"
+    real_default_sorcery_pre_install "$@"
 }
 
 #---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libcast b/var/lib/sorcery/modules/libcast
index 62657cf..8a6c00f 100755
--- a/var/lib/sorcery/modules/libcast
+++ b/var/lib/sorcery/modules/libcast
@@ -99,9 +99,7 @@ function run_conflicts() {
 
   if  [  -x  $SCRIPT_DIRECTORY/CONFLICTS  ]; then
     local CONFLICTS=$(
-        persistent_load
-        . $SCRIPT_DIRECTORY/CONFLICTS
-        persistent_save
+        run_spell_file CONFLICTS conflicts
     )
 
     local tmp to_dispel=""
diff --git a/var/lib/sorcery/modules/libdepends b/var/lib/sorcery/modules/libdepends
index f3e126e..a964efe 100755
--- a/var/lib/sorcery/modules/libdepends
+++ b/var/lib/sorcery/modules/libdepends
@@ -87,26 +87,14 @@ function run_prepare() 
   # these are here so you can source section/grimoire level scripts in
   # PREPARE, which by definition runs before the spell is loaded
   # and they are defined as usual (see bug 8329)
-  local SPELL_DIRECTORY=$SCRIPT_DIRECTORY
-  local SECTION_DIRECTORY=${SPELL_DIRECTORY%/*}
-  local GRIMOIRE=${SECTION_DIRECTORY%/*}
+  codex_get_spell_paths "$SCRIPT_DIRECTORY"
 
   local PROTECT_SORCERY=yes
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/PREPARE  ];  then
-    . $SCRIPT_DIRECTORY/PREPARE
-  else
-    default_prepare
-  fi
+  run_spell_file PREPARE prepare
   rc=$?
-  persistent_save
   return $rc
 }
 
-function real_default_prepare() {
-  :
-}
-
 #---------------------------------------------------------------------
 ## This will be home to all "other" questions we are supposed to ask about
 ## during this phase of things, right now its a placeholder
@@ -129,55 +117,38 @@ #---------------------------------------
 ## Run the spell's CONFIGURE script if it exists
 ## @param Spell to configure
 #---------------------------------------------------------------------
-function run_configure() 
-{
-
+function run_configure() {
   local SPELL=$1
   debug "cast" "run_configure() - SCRIPT_DIRECTORY = $SCRIPT_DIRECTORY"
 
-  local PROTECT_SORCERY=yes
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/CONFIGURE  ];  then
+  function run_configure_msg() {
     depends_message  "${SPELL}" "running configuration..."
-    . $SCRIPT_DIRECTORY/CONFIGURE
-  else
-    default_configure
-  fi
+  }
+
+  local PROTECT_SORCERY=yes
+  run_spell_file CONFIGURE configure run_configure_msg
   rc=$?
-  persistent_save
   return $rc
 }
 
-function real_default_configure() {
-  :
-}
-
 #---------------------------------------------------------------------
 ## Run a spell's DEPENDS if it exists
 ## @param Spell
 #---------------------------------------------------------------------
-function run_depends() 
-{ 
+function run_depends() { 
   local SPELL=$1
   debug "cast" "run_depends() - SCRIPT_DIRECTORY = $SCRIPT_DIRECTORY"
+
+  function run_depends_msg() {
+    depends_message  "${SPELL}" "checking dependencies..."
+  }
  
   local PROTECT_SORCERY=yes
-  persistent_load &&
-  if  [  -x  $SCRIPT_DIRECTORY/DEPENDS  ];  then
-    depends_message  "${SPELL}" "checking dependencies..."
-    .  $SCRIPT_DIRECTORY/DEPENDS
-  else
-    default_depends
-  fi
+  run_spell_file DEPENDS depends run_depends_msg
   rc=$?
-  persistent_save
   return $rc
 }
 
-function real_default_depends() {
-  :
-}
-
 #---------------------------------------------------------------------
 ## Run a spell's UP_TRIGGERS if it exists
 ## @param Spell
@@ -185,17 +156,14 @@ #---------------------------------------
 function run_up_triggers() {
   local SPELL=$1
   debug "cast" "run_up_triggers() - SCRIPT_DIRECTORY = $SCRIPT_DIRECTORY"
- 
-  local PROTECT_SORCERY=yes
-  if  [  -x  $SCRIPT_DIRECTORY/UP_TRIGGERS ];  then
+
+  function run_up_triggers_msg() {
     depends_message  "${SPELL}" "checking for reverse triggers..."
-    # we need &&'s to preserve the proper return code (persistant_save
-    # will probably succeed even if PREPARE fails)
-    persistent_load &&
-    . $SCRIPT_DIRECTORY/UP_TRIGGERS &&
-    persistent_save
-  fi
-  
+  }
+  local PROTECT_SORCERY=yes
+  run_spell_file UP_TRIGGERS up_triggers run_up_triggers_msg
+  rc=$?
+  return $rc
 }
 
 #---------------------------------------------------------------------
@@ -272,6 +240,7 @@ function process_sub_depends() {
   local requester=$1
   local sub_dependee=$2
   local sub_depends=$3
+  local PROTECT_SORCERY=yes
 
   if test -x $SCRIPT_DIRECTORY/SUB_DEPENDS; then
     if ! list_find "$(hash_get processed_sub_depends $sub_dependee)" "$sub_depends"; then
@@ -279,9 +248,7 @@ function process_sub_depends() {
 
       local THIS_SUB_DEPENDS=$sub_depends
       local PROCESSED_SUB_DEPENDS=$(hash_get processed_sub_depends $sub_dependee)
-      persistent_load &&
-      source $SCRIPT_DIRECTORY/SUB_DEPENDS &&
-      persistent_save || return 1
+      run_spell_file SUB_DEPENDS sub_depends || return 1
       hash_append processed_sub_depends $sub_dependee $sub_depends
     else
       debug libdepends "SUB_DEPENDS: $sub_dependee needs to provide $sub_depends but has already been processed"
@@ -646,6 +613,12 @@ function real_generic_required_depends()
     shift 2
   fi
 
+  if [[ $1 != ${1/ /} ]] ; then
+    message "${PROBLEM_COLOR}Spell names must not contain spaces:" \
+            "${DEFAULT_COLOR}${SPELL_COLOR}$1${DEFAULT_COLOR}"
+    return 1
+  fi
+
   # see if theres another grimoire
   if [[ "$4" ]] && ! [[ "$OVERRIDE_GRIMOIRES" ]] ; then
     local grimoire here nothere current
@@ -775,6 +748,12 @@ function real_generic_optional_depends()
     shift 2
   fi
 
+  if [[ $1 != ${1/ /} ]] ; then
+    message "${PROBLEM_COLOR}Spell names must not contain spaces:" \
+            "${DEFAULT_COLOR}${SPELL_COLOR}$1${DEFAULT_COLOR}"
+    return 1
+  fi
+
   # see if theres another grimoire
   if [[ "$5" ]] && ! [[ "$OVERRIDE_GRIMOIRES" ]] ; then
     local grimoire here nothere current
@@ -1338,10 +1317,8 @@ function real_sub_depends() {
       if ! tablet_set_spell $sub_dependee ; then
         codex_set_current_spell_by_name $sub_dependee || return 1
       fi
-      test -x $SCRIPT_DIRECTORY/PRE_SUB_DEPENDS || return 1
-      persistent_load &&
-      source $SCRIPT_DIRECTORY/PRE_SUB_DEPENDS; rc=$?
-      persistent_save
+      run_spell_file PRE_SUB_DEPENDS pre_sub_depends
+      rc=$?
       return $rc
     ) && {
       debug "libdepends" "adding altruistic sub-depends for $sub_dependee with $sub_depends from $requester"
@@ -1445,15 +1422,8 @@ function private_add_triggerees() {
   # run the trigger check file
   # this is made into a sub-function just to reduce duplication...
   function private_add_triggerees_sub1() {
-    running_trigger=0
-    persistent_load
-    if test -x $SCRIPT_DIRECTORY/TRIGGER_CHECK; then
-      source $SCRIPT_DIRECTORY/TRIGGER_CHECK
-    else
-      default_trigger_check
-    fi
+    run_spell_file TRIGGER_CHECK trigger_check
     running_trigger=$?
-    persistent_save
     if [[ $running_trigger == 0 ]] ; then
       private_up_trigger "$SPELL" "$TARGET" "$ACTION"
     fi
diff --git a/var/lib/sorcery/modules/libdispel b/var/lib/sorcery/modules/libdispel
index 0c9dae4..ea078cc 100755
--- a/var/lib/sorcery/modules/libdispel
+++ b/var/lib/sorcery/modules/libdispel
@@ -273,46 +273,22 @@ #-----
 function pre_remove() {
   local rc=0
   if  [[ $SCRIPT_DIRECTORY ]] ; then
-    persistent_load &&
-    if test  -x  $SCRIPT_DIRECTORY/PRE_REMOVE ; then
-      . $SCRIPT_DIRECTORY/PRE_REMOVE
-    else
-      default_pre_remove
-    fi
-    rc=$?
-    persistent_save
+    run_spell_file PRE_REMOVE pre_remove
   fi
   return $rc
 }
 
-function real_default_pre_remove() {
-  :
-}
-
 #-----
 ## Run the POST_REMOVE script if it exists.
 #-----
 function post_remove() {
   local rc=0
   if  [[ $SCRIPT_DIRECTORY ]] ; then
-    persistent_load &&
-    if test  -x  $SCRIPT_DIRECTORY/POST_REMOVE ; then
-      . $SCRIPT_DIRECTORY/POST_REMOVE
-    else
-      default_post_remove
-    fi
-    rc=$?
-    persistent_save
+    run_spell_file POST_REMOVE post_remove
   fi
   return $rc
 }
 
-function real_default_post_remove() {
-  :
-}
-
-
-
 #---------------------------------------------------------------------
 ## Dispel a spell
 #---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libspell b/var/lib/sorcery/modules/libspell
new file mode 100644
index 0000000..8993d0f
--- /dev/null
+++ b/var/lib/sorcery/modules/libspell
@@ -0,0 +1,184 @@
+#!/bin/bash
+#---------------------------------------------------------------------
+## @Synopsis Functions for running spell files.
+## @Copyright (C) 2006 The Source Mage Team <http://www.sourcemage.org>
+## @Contributers Andrew Stitt <astitt at sourcemage.org>
+##
+## This file implements SourceMage's spell file inheritence scheme.
+## In a nutshell, sorcery implements a default for each and every spell
+## file, usually this is "true". There can be an override at the grimoire
+## or section level, in addition to the spell file itself. This means
+## you can write a spell level PRE_BUILD, do some stuff then call
+## default_pre_build, which will run a section level PRE_BUILD if it
+## exists, or run a grimoire level PRE_BUILD if that exists, or run the
+## sorcery supplied default. See bug 10914.
+#---------------------------------------------------------------------
+
+#---------------------------------------------------------------------
+## Setup default functions for spell files. Several of the core functions
+## are declared here as false so they exist, but are re-defined when in
+## the proper context. This is merely a safety valve.
+#---------------------------------------------------------------------
+function load_spell_file_functions() {
+  for each in $(
+    cat << EOF
+PREPARE:prepare
+CONFIGURE:configure
+DEPENDS:depends
+
+PRE_SUB_DEPENDS:pre_sub_depends
+SUB_DEPENDS:sub_depends
+
+CONFLICTS:conflicts
+
+PRE_BUILD:pre_build
+BUILD:build
+PRE_INSTALL:pre_install
+INSTALL:install
+POST_BUILD:post_build
+POST_INSTALL:post_install
+FINAL:final
+
+UP_TRIGGERS:up_triggers
+TRIGGERS:triggers
+TRIGGER_CHECK:trigger_check
+
+DOWNLOAD:download
+
+PRE_REMOVE:pre_remove
+POST_REMOVE:post_remove
+
+PRE_RESURRECT:pre_resurrect
+POST_RESURRECT:post_resurrect
+EOF
+); do
+    local NAME=${each%:*}
+    local name=${each#*:}
+
+    # Create the four libapi entry points for each file
+    eval "function default_${name}() {
+      real_default_${name}
+    }"
+    eval "function default_section_${name}() {
+      real_default_section_${name}
+    }"
+    eval "function default_grimoire_${name}() {
+      real_default_grimoire_${name}
+    }"
+    eval "function default_sorcery_${name}() {
+      real_default_sorcery_${name}
+    }"
+
+
+    # real_default_<file> always refers to the level above in the hierarchy.
+    # (section, grimoire or sorcery).
+    # its defined here as false, but is re-declared at various stages.
+    eval "function real_default_${name}() {
+      false
+    }"
+
+    # These two functions run the section/grimoire function and update
+    # the real_default_<file> function. Ignore this generic declaration,
+    # it is changed at runtime to private_default_<section|grimoire>_generic.
+    eval "function real_default_section_${name}() {
+      false
+    }"
+    eval "function real_default_grimoire_${name}() {
+      false
+    }"
+
+    # If there isnt a sorcery default function, declare one as "true".
+    # Note that, the right thing happens regardless of what order lib files
+    # are sourced in.
+    declare -F real_default_sorcery_${name} &>/dev/null ||
+    eval "function real_default_sorcery_${name}() {
+      true
+    }"
+  done
+}
+load_spell_file_functions
+
+
+#---------------------------------------------------------------------
+## Run a section level file, or the default grimoire level function.
+#---------------------------------------------------------------------
+private_default_section_generic() {
+  eval "function real_default_${2}() {
+    default_grimoire_${2}
+  }"
+  if test -x "$SECTION_DIRECTORY/${1}"; then
+    source "$SECTION_DIRECTORY/${1}"
+  else
+    default_grimoire_${2}
+  fi
+  eval "function real_default_${2}() {
+    default_section_${2}
+  }"
+}
+
+#---------------------------------------------------------------------
+## Run a grimoire level file, or the default sorcery level function.
+#---------------------------------------------------------------------
+private_default_grimoire_generic() {
+  eval "function real_default_${2}() {
+    default_sorcery_${2}
+  }"
+  if test -x "$GRIMOIRE/${1}"; then
+    source "$GRIMOIRE/${1}"
+  else
+    default_sorcery_${2}
+  fi
+  eval "function real_default_${2}() {
+    default_grimoire_${2}
+  }"
+}
+
+#---------------------------------------------------------------------
+## Core entry point for sorcery to run a spell file.
+## Arms real_default_*_file functions then runs the spell file/cmd/function
+#---------------------------------------------------------------------
+function run_spell_file() {
+  local rc=0
+  local spell_file=$1
+  local function_suffix=$2
+  local spell_cmd_var=${1}_CMD
+  local spell_cmd=${!spell_cmd_var}
+
+  # this is mostly used for messages like "<spell> checking dependencies"
+  local pre_function=$3
+
+  eval "function real_default_${function_suffix}() {
+    default_section_${function_suffix}
+  }"
+  eval "function real_default_section_${function_suffix}() {
+    private_default_section_generic "${spell_file}" ${function_suffix}
+  }"
+  eval "function real_default_grimoire_${function_suffix}() {
+    private_default_grimoire_generic ${spell_file} ${function_suffix}
+  }"
+
+  persistent_load &&
+  if test -x "$SCRIPT_DIRECTORY/$spell_file"; then
+    [[ $pre_function ]] && $pre_function
+    . $SCRIPT_DIRECTORY/$spell_file
+  elif [[ "$spell_cmd" ]] ; then
+    [[ $pre_function ]] && $pre_function
+    $spell_cmd
+  else
+    default_${function_suffix}
+  fi;rc=$?
+  persistent_save
+
+  # restore these, so they're always false except when needed
+  eval "function real_default_${function_suffix}() {
+    false
+  }"
+  eval "function real_default_section_${function_suffix}() {
+    false
+  }"
+  eval "function real_default_grimoire_${function_suffix}() {
+    false
+  }"
+  return $rc
+}
+
diff --git a/var/lib/sorcery/modules/libsummon b/var/lib/sorcery/modules/libsummon
index c152800..97c36b2 100755
--- a/var/lib/sorcery/modules/libsummon
+++ b/var/lib/sorcery/modules/libsummon
@@ -40,14 +40,7 @@ function summon_spell() {
     # and instead jump through hoops to get the return code correctly
     ( local rc=1
       run_details    &&
-      persistent_load &&
-      if test -x $SCRIPT_DIRECTORY/DOWNLOAD ; then
-        . $SCRIPT_DIRECTORY/DOWNLOAD
-      else
-        default_download
-      fi &&
-      persistent_save
-      # save the rc, then unlock
+      run_spell_file DOWNLOAD download
       rc=$?
 
       if [[ $rc == 0 ]]; then
@@ -89,7 +82,7 @@ ## 
 ## Call acquire_src for each SOURCEx_URL
 ##
 #-------------------------------------------------------------------------
-function real_default_download() {
+function real_default_sorcery_download() {
   $STD_DEBUG
   local SOURCE_NUMBER
   for SOURCE_NUMBER in $(real_get_source_nums X); do
diff --git a/var/lib/sorcery/modules/libtriggers b/var/lib/sorcery/modules/libtriggers
index 1029e23..50a3c73 100755
--- a/var/lib/sorcery/modules/libtriggers
+++ b/var/lib/sorcery/modules/libtriggers
@@ -18,11 +18,7 @@ #---------------------------------------
 function run_triggers() {
   debug "libtriggers" "Starting run_triggers() on $SPELL"
 
-  if [ -x $SCRIPT_DIRECTORY/TRIGGERS ]; then
-    persistent_load
-    . $SCRIPT_DIRECTORY/TRIGGERS
-    persistent_save
-  fi
+  run_spell_file TRIGGERS triggers
 
 }
 



More information about the SM-Commit mailing list