Merge branch 'restore-init-asdf-after-quicklisp-installation' into develop
[clbuild2:clbuild2.git] / internal / ql.sh
1 ### internal/ql.sh -- clbuild/quicklisp integration code
2 ###
3 ### Part of clbuild, a wrapper script for Lisp invocation with quicklisp
4 ### preloaded.  Based on code from clbuild by Luke Gorrie and
5 ### contributors.
6
7 test -f $base/clbuild || exit 1
8
9
10 ###
11 ### find quicklisp
12 ###
13
14 qldir="${QUICKLISP_DIR:=$(echo ~/quicklisp)}"
15 ql_setup_lisp=$qldir/setup.lisp
16 ql_core="$base"/$LISP_IMPLEMENTATION_TYPE-base.core
17
18 ###
19 ### project name to project directory lookup
20 ###
21
22 find_project() {
23     tramp=$qldir/dists/quicklisp/installed/releases/$1.txt
24     if test -f "$tramp"; then
25         cat "$tramp"
26     fi
27 }
28
29 install_quicklisp() {
30     qlidir="$base/quicklisp-installer"
31     qli="$qlidir/quicklisp.lisp"
32     mkdir -p "$qlidir"
33     wget -O "$qli" http://beta.quicklisp.org/quicklisp.lisp
34
35     old_init_asdf_1="$init_asdf_1"
36     old_init_asdf_2="$init_asdf_2"
37     init_asdf_1='(progn)'
38     init_asdf_2='(progn)'
39
40     echo "$quit" | \
41         run_lisp_raw \
42         $eval "(load \"$qli\")" \
43         $eval "(progn (quicklisp-quickstart:install :path (merge-pathnames #P\"$qldir/\")) $quit)"
44
45     # restore intialization code
46     init_asdf_1="$old_init_asdf_1"
47     init_asdf_2="$old_init_asdf_2"
48 }
49
50 ensure_quicklisp() {
51     if ! test -f "$ql_setup_lisp"; then
52         echo clbuild: quicklisp not found, installing it now... 
53         install_quicklisp
54         echo clbuild: done installing quicklisp
55     fi
56 }
57
58 quickload() {
59     if ! test -f "$ql_setup_lisp"; then
60         exec 2>&1
61         echo "quicklisp not found in ~/quicklisp"
62         exit 1
63     fi
64     echo "$quit" | run_lisp_with_ql $eval "(ql:quickload \"$1\")"
65 }
66
67 # fixme: replace with ensure_system and system_name_to_project_name
68 ensure_project() {
69     project=$1
70     system=${2:-$project}
71     if  test -z $(find_project $project); then
72         echo $project not found, installing now
73         quickload $system
74     fi
75 }
76
77 ensure_quicklisp_core() {
78     ensure_quicklisp
79     if ! (valid_core_p "$ql_core"); then
80         echo clbuild: no valid core file $ql_core, dumping now...
81         dump_core "$ql_core"
82         echo clbuild: done dumping the core file
83     fi
84     with_core_options="$core_option $ql_core $common_options"
85 }
86
87 update_all_dists() {
88     if ! test -f "$ql_setup_lisp"; then
89         echo quicklisp not found, nothing to update
90         exit 1
91     fi
92     rm_cores
93     echo "$quit" | run_lisp_with_ql $eval "(ql:update-all-dists)"
94 }
95
96 update_dist() {
97     if ! test -f "$ql_setup_lisp"; then
98         echo quicklisp not found, nothing to update
99         exit 1
100     fi
101     rm_cores
102     echo "$quit" | run_lisp_with_ql $eval "(ql:update-dist \"$1\")"
103 }
104
105 update_client() {
106     if ! test -f "$ql_setup_lisp"; then
107         echo quicklisp not found, nothing to update
108         exit 1
109     fi
110     rm_cores
111     echo "$quit" | run_lisp_with_ql $eval "(ql:update-client)"
112 }
113
114 quicklisp_system_list() {
115     echo "$quit" | run_lisp_with_ql $eval "(print (ql:system-list))"
116 }
117
118 quicklisp_system_apropos() {
119     echo "$quit" | run_lisp_with_ql $eval "(print (ql:system-apropos \"$1\"))"
120 }