Skip to content

Commit f481d80

Browse files
committed
wip on lisp dir
1 parent 0867ce1 commit f481d80

File tree

8 files changed

+101
-26
lines changed

8 files changed

+101
-26
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# qob
22
/.qob
33

4+
# executables
5+
qob
6+
*.exe
7+
48
# lisp
59
*.FASL
610
*.fasl

bin/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# others
1+
/lisp
22
qob.*

cmds/core/build.lisp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
:description "output directory"
3737
:short-name #\o
3838
:long-name "output"
39-
:required t
4039
:key :output)))
4140

4241
(defun handler (cmd)
4342
"Handler for `build' command."
4443
(let* ((name (clingon:getopt cmd :name))
4544
(output (clingon:getopt cmd :output)))
45+
;; Delete if exists to prevent errors.
46+
(when (uiop:file-exists-p output)
47+
(delete-file output))
4648
;; TODO: Change build path.
47-
(format t "~A" output)
48-
49-
5049
(qob:setup)
5150
(asdf:operate :build-op name)))
5251

cmds/core/list.lisp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
(defun handler (cmd)
2323
"Handler for `list' command."
2424
(declare (ignore cmd))
25-
(qob:setup)
26-
(format t "~A" (asdf/system-registry:registered-systems)))
25+
;;(qob:setup)
26+
;;(format t "~A" (asdf/system-registry:registered-systems))
27+
(qob:call-lisp "core/list"))
2728

2829
(defun command ()
2930
"List command."

scripts/build.lisp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
;;; Code
99

10+
(require 'asdf)
11+
1012
(push '*default-pathname-defaults* asdf:*central-registry*)
1113
(asdf:load-system "qob")
1214

@@ -20,9 +22,32 @@
2022

2123
;;(uiop:dump-image "./bin/qob.exe" :executable t)
2224

25+
(defun copy-directory (src-dir dst-dir)
26+
"Recursively copy the contents of SRC-DIR to DST-DIR."
27+
(let ((src (uiop:parse-native-namestring src-dir))
28+
(dst (uiop:parse-native-namestring dst-dir)))
29+
;; Ensure the source directory exists
30+
(unless (probe-file src)
31+
(error "Source directory ~a does not exist!" src))
32+
33+
;; Create destination directory if it doesn't exist
34+
(unless (probe-file dst)
35+
(ensure-directories-exist dst))
36+
37+
;; Recursively copy files and directories
38+
(dolist (entry (directory (merge-pathnames "*" src)))
39+
(let ((entry-name (uiop:parse-native-namestring entry)))
40+
(if (uiop:file-exists-p entry-name)
41+
;; Copy file
42+
(uiop:copy-file entry-name (merge-pathnames (uiop:pathname-name entry) dst))
43+
;; Recursively copy subdirectory
44+
(copy-directory entry-name (merge-pathnames (uiop:pathname-name entry) dst)))))))
45+
46+
(copy-directory "lisp" "bin/lisp")
47+
2348
(let ((exec (el-lib:el-expand-fn (if (uiop:os-windows-p)
24-
"./bin/qob.exe"
25-
"./bin/qob"))))
49+
"bin/qob.exe"
50+
"bin/qob"))))
2651
(when (uiop:file-exists-p exec)
2752
(delete-file exec)))
2853

src/el-lib.lisp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,40 @@
1010
(defpackage el-lib
1111
(:use cl)
1212
(:export el-memq
13+
el-member
1314
el-expand-fn
14-
el-member))
15+
el-executable-find
16+
el-move-path))
1517

1618
(in-package :el-lib)
1719

20+
(defvar el-executables nil
21+
"Executable cache.")
22+
23+
(defun el-executables ()
24+
"Return list of executables."
25+
(loop with path = (uiop:getenv "PATH")
26+
for p in (uiop:split-string path :separator
27+
(if (uiop:os-windows-p) ";" ":"))
28+
for dir = (probe-file p)
29+
when (uiop:directory-exists-p dir)
30+
append (uiop:directory-files dir)))
31+
32+
(defun el-executable-find (name)
33+
"Mimic `executable-find' function."
34+
(unless el-executables
35+
(setq el-executables (el-executables)))
36+
(find name el-executables
37+
:test #'equalp
38+
:key #'pathname-name))
39+
1840
(defun el-memq (elt list)
1941
"Mimic `memq' function."
2042
(member elt list :test #'eq))
2143

2244
(defun el-member (elt list)
2345
(member elt list :test #'string=))
2446

25-
(defun el-expand-fn (path-string &optional (dir-name (uiop:getcwd)))
47+
(defun el-expand-fn (path &optional (dir-name (uiop:getcwd)))
2648
"Like `expand-file-name' function."
27-
(uiop:unix-namestring
28-
(uiop:ensure-absolute-pathname
29-
(uiop:merge-pathnames*
30-
(uiop:parse-unix-namestring path-string))
31-
dir-name)))
49+
(uiop:ensure-absolute-pathname (uiop:merge-pathnames* path dir-name)))

src/packages.lisp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
(:use cl)
1212
(:export
1313
;; src/utils.lsip
14-
setup
15-
load-system
16-
asd-files
17-
asd-test-files
14+
call-lisp
15+
setup ; TODO: move to prepare.lisp
16+
load-system ; TODO: move to prepare.lisp
17+
asd-files ; TODO: move to prepare.lisp
18+
asd-test-files ; TODO: move to prepare.lisp
1819
;; src/logger.lsip
19-
print
20-
trace
21-
debug
22-
info
23-
warning
24-
error
20+
print ; TODO: move to prepare.lisp
21+
trace ; TODO: move to prepare.lisp
22+
debug ; TODO: move to prepare.lisp
23+
info ; TODO: move to prepare.lisp
24+
warning ; TODO: move to prepare.lisp
25+
error ; TODO: move to prepare.lisp
2526
;; cmds/qob.lisp
2627
command
2728
;; src/main.lsip

src/utils.lisp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@
99

1010
(in-package :qob)
1111

12+
(defvar *lisp-root* "lisp/"
13+
"Directory path points to the lisp folder.")
14+
15+
(defun program-name ()
16+
"Lisp program we target to run."
17+
(or (uiop:getenv "QOB_LISP")
18+
"sbcl"))
19+
20+
(defun lisp-script (name)
21+
"Form lisp script path."
22+
(concatenate 'string name ".lisp"))
23+
24+
(defun call-lisp (script &rest args)
25+
"Run the lisp implementation."
26+
(let ((lisp-impls (program-name)))
27+
(unless (el-lib:el-executable-find lisp-impls)
28+
(error "Defined Lisp implementation is not installed: ~A" lisp-impls))
29+
(let* ((lisp-dir (el-lib:el-expand-fn *lisp-root* sb-ext:*runtime-pathname*))
30+
(script (lisp-script script)))
31+
(format t "~A" (el-lib:el-expand-fn script lisp-dir))
32+
;; (uiop:run-program (list lisp-impls
33+
;; "--load" (el-lib:el-expand-fn script *lisp-root*)
34+
;; )
35+
;; :output t
36+
;; :force-shell t)
37+
)))
38+
1239
(defun setup ()
1340
"Setup the system."
1441
(let ((files (asd-files t)))

0 commit comments

Comments
 (0)