From b71aa1cc3b05c8c4b1256c54f8ccb6bef4066694 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 11 Oct 2009 10:59:58 +0200 Subject: In CGI mode, create and load a single FASL file instead of loading each source file directly. Ignore-this: ea3269e86aae4bb2642cb25bb0db9d42 darcs-hash:4ec74e8bdc53cd16d103ce15cfe3a6d812f2c514 --- compile.lisp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ journal-admin.cgi | 21 +++++++++++++++++++- journal.cgi | 21 +++++++++++++++++++- run.lisp | 58 ------------------------------------------------------- 4 files changed, 93 insertions(+), 60 deletions(-) create mode 100755 compile.lisp delete mode 100755 run.lisp diff --git a/compile.lisp b/compile.lisp new file mode 100755 index 0000000..5806995 --- /dev/null +++ b/compile.lisp @@ -0,0 +1,53 @@ +#! /usr/bin/env clisp +;;;; -*- coding: utf-8; mode: lisp -*- +;;;; Copyright 2007, Matthias Andreas Benkard. + +;;;------------------------------------------------------------------------ +;;; This file is part of The Mulkblog Project. +;;; +;;; The Mulkblog Project is free software. You can redistribute it and/or +;;; modify it under the terms of the Affero General Public License as +;;; published by Affero, Inc.; either version 1 of the License, or +;;; (at your option) any later version. +;;; +;;; The Mulkblog Project is distributed in the hope that it will be +;;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty +;;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; Affero General Public License for more details. +;;; +;;; You should have received a copy of the Affero General Public +;;; License in the COPYING file that comes with The Mulkblog Project; if +;;; not, write to Affero, Inc., 510 Third Street, Suite 225, San +;;; Francisco, CA 94107 USA. +;;;------------------------------------------------------------------------ + +(in-package #:cl-user) + +;;; TAKE NOTICE: If you want to run this script from the command line or +;;; from a web server, be sure to use a core image including the systems +;;; this script depends upon. The ASDF system definition has mainly +;;; been written for purposes of debugging, development and +;;; documentation. + +(defclass compile-source-simple-op (asdf:operation) ()) +(defmethod asdf:perform ((o compile-source-simple-op) (c asdf:component)) + nil) +(defmethod asdf:perform ((o compile-source-simple-op) (m asdf:module)) + (dolist (c (asdf:module-components m)) + (load (compile-file (asdf:component-pathname c))))) + + +#+clisp +(unless (asdf:find-system :mulk-journal nil) + (let ((*package* (find-package :asdf))) + (load (merge-pathnames "mulk-journal.asd" system::*current-source-file*)))) + + +;;; The following does not generally work in a CGI setting because of +;;; security restrictions. Then again, loading all the dependencies +;;; individually rather than using a core image would certainly be too +;;; slow for any serious CGI usage, anyway, so what the heck. Loading +;;; our own files (no dependencies) using a manually loaded system +;;; definition (see above) works, which suffices for our needs. +(unless (find-package '#:mulk.journal) + (asdf:oos 'compile-source-simple-op '#:mulk-journal)) diff --git a/journal-admin.cgi b/journal-admin.cgi index 5fa1272..53d7c97 100755 --- a/journal-admin.cgi +++ b/journal-admin.cgi @@ -8,4 +8,23 @@ else LISPINIT_DIR="$NFSN_SITE_ROOT/protected/journal" fi -exec env LC_ALL=de_DE.UTF-8 clisp -M "$LISPINIT_DIR/lispinit.mem.gz" "$DIR/run.lisp" --admin-mode +mtime_of() { + stat -n -f "%m" -t "%s" "$1" || echo -n 0 +} + +FASL_FILE="$LISPINIT_DIR/journal-full.fas" + +lisp_mtime=0 +for x in $DIR/*.lisp; do + mtime=`mtime_of "$x"` + if [ $mtime -gt $lisp_mtime ]; then + lisp_mtime=$mtime + fi +done + +if ! [ -f "$FASL_FILE" -a \( `mtime_of "$FASL_FILE"` -gt $lisp_mtime \) ]; then + env LC_ALL=de_DE.UTF-8 clisp -M "$LISPINIT_DIR/lispinit.mem.gz" "$DIR/compile.lisp" &&\ + find "$DIR" -name "*.fas" -print0 | xargs -0 cat > "$FASL_FILE" +fi + +exec env LC_ALL=de_DE.UTF-8 clisp -q -q -M "$LISPINIT_DIR/lispinit.mem.gz" -x "(progn (load \"$FASL_FILE\") (cl-user::script-main))" --admin-mode diff --git a/journal.cgi b/journal.cgi index bbec698..c34c2e7 100755 --- a/journal.cgi +++ b/journal.cgi @@ -8,4 +8,23 @@ else LISPINIT_DIR="$NFSN_SITE_ROOT/protected/journal" fi -exec env LC_ALL=de_DE.UTF-8 clisp -M "$LISPINIT_DIR/lispinit.mem.gz" "$DIR/run.lisp" +mtime_of() { + stat -n -f "%m" -t "%s" "$1" || echo -n 0 +} + +FASL_FILE="$LISPINIT_DIR/journal-full.fas" + +lisp_mtime=0 +for x in $DIR/*.lisp; do + mtime=`mtime_of "$x"` + if [ $mtime -gt $lisp_mtime ]; then + lisp_mtime=$mtime + fi +done + +if ! [ -f "$FASL_FILE" -a \( `mtime_of "$FASL_FILE"` -gt $lisp_mtime \) ]; then + env LC_ALL=de_DE.UTF-8 clisp -M "$LISPINIT_DIR/lispinit.mem.gz" "$DIR/compile.lisp" &&\ + find "$DIR" -name "*.fas" -print0 | xargs -0 cat > "$FASL_FILE" +fi + +exec env LC_ALL=de_DE.UTF-8 clisp -q -q -M "$LISPINIT_DIR/lispinit.mem.gz" -x "(progn (load \"$FASL_FILE\") (cl-user::script-main))" diff --git a/run.lisp b/run.lisp deleted file mode 100755 index c77cab7..0000000 --- a/run.lisp +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env clisp -;;;; -*- coding: utf-8; mode: lisp -*- -;;;; Copyright 2007, Matthias Andreas Benkard. - -;;;------------------------------------------------------------------------ -;;; This file is part of The Mulkblog Project. -;;; -;;; The Mulkblog Project is free software. You can redistribute it and/or -;;; modify it under the terms of the Affero General Public License as -;;; published by Affero, Inc.; either version 1 of the License, or -;;; (at your option) any later version. -;;; -;;; The Mulkblog Project is distributed in the hope that it will be -;;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty -;;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; Affero General Public License for more details. -;;; -;;; You should have received a copy of the Affero General Public -;;; License in the COPYING file that comes with The Mulkblog Project; if -;;; not, write to Affero, Inc., 510 Third Street, Suite 225, San -;;; Francisco, CA 94107 USA. -;;;------------------------------------------------------------------------ - -(in-package #:cl-user) - -;;; TAKE NOTICE: If you want to run this script from the command line or -;;; from a web server, be sure to use a core image including the systems -;;; this script depends upon. The ASDF system definition has mainly -;;; been written for purposes of debugging, development and -;;; documentation. - -(defclass load-source-simple-op (asdf:operation) ()) -(defmethod asdf:perform ((o load-source-simple-op) (c asdf:component)) - nil) -(defmethod asdf:perform ((o load-source-simple-op) (m asdf:module)) - (dolist (c (asdf:module-components m)) - (load (asdf:component-pathname c)))) - - -#+clisp -(unless (asdf:find-system :mulk-journal nil) - (let ((*package* (find-package :asdf))) - (load (merge-pathnames "mulk-journal.asd" - system::*current-source-file*)))) - - -;;; The following does not generally work in a CGI setting because of -;;; security restrictions. Then again, loading all the dependencies -;;; individually rather than using a core image would certainly be too -;;; slow for any serious CGI usage, anyway, so what the heck. Loading -;;; our own files (no dependencies) using a manually loaded system -;;; definition (see above) works, which suffices for our needs. -(unless (find-package '#:mulk.journal) - (asdf:oos 'load-source-simple-op '#:mulk-journal)) - - -#+clisp -(script-main) -- cgit v1.2.3