From b8edd5cda82111ba11ed585ed158067e802b294e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 22 Oct 2015 14:40:54 +0200 Subject: [PATCH] android: arrange resources directory Separate different directories for the resources. #P"SYS:" -> #P"lisp/lib" - ECLDIR with the modules $HOME -> lisp/home - user provided files, quicklisp, 3rd party contribs lisp/etc - init scripts and the configuration --- .../android/assets/lisp/{ => etc}/init.lisp | 53 ++++++++++++------- .../android/assets/lisp/{ => etc}/user.lisp | 3 +- examples/android/jni/ecl_boot.c | 15 ++++-- 3 files changed, 47 insertions(+), 24 deletions(-) rename examples/android/assets/lisp/{ => etc}/init.lisp (62%) rename examples/android/assets/lisp/{ => etc}/user.lisp (98%) diff --git a/examples/android/assets/lisp/init.lisp b/examples/android/assets/lisp/etc/init.lisp similarity index 62% rename from examples/android/assets/lisp/init.lisp rename to examples/android/assets/lisp/etc/init.lisp index 1874e5d62..015e2094d 100644 --- a/examples/android/assets/lisp/init.lisp +++ b/examples/android/assets/lisp/etc/init.lisp @@ -7,22 +7,30 @@ (setq *default-directory* *default-pathname-defaults*) (defvar *ecl-home* *default-directory*) -(ext:setenv "HOME" (namestring *ecl-home*)) -(setf asdf:*user-cache* - (merge-pathnames #P"../cache/" *default-pathname-defaults*)) +(ext:setenv "USER-CACHE" + (namestring (merge-pathnames #P"../cache/" *ecl-home*))) +(setf asdf:*user-cache* (merge-pathnames #P"../cache/" *default-pathname-defaults*)) (format t "Loading the modules~%") (require :ASDF) (require :SOCKETS) (require :SERVE-EVENT) +;; swank probes sys:serve-event.fas (which doesn't exist) +;; (pushnew :SERVE-EVENT *features*) + (pushnew (namestring *default-pathname-defaults*) asdf:*central-registry*) +(pushnew (namestring (merge-pathnames #P"home/slime-2.14/" *ecl-home*)) + asdf:*central-registry*) (format t "Preparing swank~%") (handler-case (asdf:oos 'asdf:load-op :swank :verbose t) (condition (c) (format t "condition ~A happened~%" c) + (format t "filepath SYS:SLIME-2.14;SWANK.ASD.NEWEST: ~A~%" + (truename #P"SYS:SLIME-2.14;SWANK.ASD.NEWEST")) + (force-output) (error c))) (swank-loader:init :load-contribs t :setup t @@ -30,17 +38,17 @@ :quiet nil) ;; The following "patches" swank to work correctly on android/iOS -;; (in-package :swank/backend) -;; (defimplementation lisp-implementation-program () -;; "Return the argv[0] of the running Lisp process, or NIL." -;; ;; (lisp-implementation-type) -;; nil) +(in-package :swank/backend) +(defimplementation lisp-implementation-program () + "Return the argv[0] of the running Lisp process, or NIL." + ;; "org.lisp.ecl" + nil) (in-package :swank) (defun repl-input-stream-read (connection stdin) (loop (let* ((socket (connection.socket-io connection)) - (inputs (list socket #-(or) stdin)) + (inputs (list socket #+(or) stdin)) (ready (wait-for-input inputs))) (describe (list 'hobaa connection stdin socket inputs ready)) (cond ((eq ready :interrupt) @@ -58,6 +66,18 @@ (return (read-non-blocking stdin))) (t (assert (null ready))))))) +;; (format t "Loading user.lisp~%") +;; (handler-case (cond ((probe-file #P"user.lisp") +;; (format t "user exists~%") +;; (load "user")) +;; (T (format t "user.lisp doesn't exist~%"))) +;; (condition (c) +;; (format t "condition ~A happened~%" c) +;; (error c))) + +(when (probe-file #P"etc/user.lisp") + (load "etc/user")) + (format t "Starting swank~%") (mp:process-run-function "SLIME-listener" @@ -65,17 +85,10 @@ (let ((swank::*loopback-interface* "0.0.0.0")) (swank:create-server :port 4005 :dont-close t - :style nil #|:spawn|# + ;; :style nil #|:spawn|# )) - )) - -(format t "Loading user.lisp~%") -(handler-case (cond ((probe-file #P"user.lisp") - (format t "user exists~%") - (load "user")) - (T (format t "user.lisp doesn't exist~%"))) - (condition (c) - (format t "condition ~A happened~%" c) - (error c))) + )) (format t "Initialization done~%") +(force-output) +(sleep 3) diff --git a/examples/android/assets/lisp/user.lisp b/examples/android/assets/lisp/etc/user.lisp similarity index 98% rename from examples/android/assets/lisp/user.lisp rename to examples/android/assets/lisp/etc/user.lisp index c0e9f28d7..553e0bd0a 100644 --- a/examples/android/assets/lisp/user.lisp +++ b/examples/android/assets/lisp/etc/user.lisp @@ -1,8 +1,9 @@ (in-package :cl-user) -(require 'bytecmp) + (setq *default-directory* *default-pathname-defaults*) +(format t "user.lisp 1~%") (defun sysinfo (&optional (out *standard-output*)) "Print the current environment to a stream." (declare (stream out)) diff --git a/examples/android/jni/ecl_boot.c b/examples/android/jni/ecl_boot.c index 293ac73d7..ead376263 100644 --- a/examples/android/jni/ecl_boot.c +++ b/examples/android/jni/ecl_boot.c @@ -41,10 +41,19 @@ int ecl_boot(const char *root_dir) LOGI("ECL boot beginning\n"); - sprintf(tmp, "%s/", root_dir); + LOGI("Setting directories\n"); + setenv("HOME", root_dir, 1); + + sprintf(tmp, "%s/lib/", root_dir); setenv("ECLDIR", tmp, 1); - LOGI("ECLDIR set\n"); + sprintf(tmp, "%s/etc/", root_dir); + setenv("ETC", tmp, 1); + + sprintf(tmp, "%s/home/", root_dir); + setenv("HOME", tmp, 1); + + LOGI("Directories set\n"); // ecl_set_option(ECL_OPT_TRAP_SIGFPE, 0); // ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0); @@ -85,7 +94,7 @@ void ecl_toplevel(const char *home) sprintf(tmp, "(setq *default-pathname-defaults* #p\"%s/\")", home); si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL); si_select_package(ecl_make_simple_base_string("CL-USER", 7)); - si_safe_eval(3, c_string_to_object("(load \"init\")"), Cnil, OBJNULL); + si_safe_eval(3, c_string_to_object("(load \"etc/init\")"), Cnil, OBJNULL); } CL_CATCH_ALL_END; LOGI("EXIT TOP LEVEL\n");