1 | (in-package :abcl/build) |
---|
2 | |
---|
3 | ;; TODO function to deal with looking up a locally preferred mirrors |
---|
4 | (defun ant-zip-uri () |
---|
5 | #p"https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.16-bin.zip" |
---|
6 | |
---|
7 | #+(or) ;; need apache-ant-1.9 for JVM version 49.0 |
---|
8 | #p"https://www-eu.apache.org/dist/ant/binaries/apache-ant-1.10.12-bin.zip") |
---|
9 | |
---|
10 | (defun xdg/ant-executable () |
---|
11 | (xdg/executable (ant-zip-uri) "bin/ant")) |
---|
12 | |
---|
13 | #+(or) |
---|
14 | (defun xdg/ant-executable () |
---|
15 | (let* ((uri (ant-zip-uri)) |
---|
16 | (directory (xdg/abcl-install-root uri)) |
---|
17 | (ant-root-name (let ((name (pathname-name uri))) |
---|
18 | (subseq name 0 (- (length name) (length "-bin"))))) |
---|
19 | (ant-home (merge-pathnames (make-pathname :directory `(:relative ,ant-root-name)) |
---|
20 | directory)) |
---|
21 | (ant (merge-pathnames #p"bin/ant" ant-home)) |
---|
22 | result) |
---|
23 | (dolist (p (possible-executable-names ant)) |
---|
24 | (when (probe-file p) |
---|
25 | (return-from xdg/ant-executable |
---|
26 | (values |
---|
27 | (probe-file p) |
---|
28 | ant)))) |
---|
29 | ;; failure |
---|
30 | (values |
---|
31 | nil |
---|
32 | ant))) |
---|
33 | |
---|
34 | (defun ant/install () |
---|
35 | (unless (xdg/ant-executable) |
---|
36 | (xdg/install (ant-zip-uri) :type :unzip)) |
---|
37 | (values |
---|
38 | (xdg/ant-executable) |
---|
39 | (directory (merge-pathnames "**/*" |
---|
40 | (xdg/abcl-install-root (ant-zip-uri)))))) |
---|
41 | |
---|
42 | (defparameter *ant-home* nil) |
---|
43 | |
---|
44 | (define-condition no-installed-ant (error) |
---|
45 | ((searched)) |
---|
46 | (:report (lambda (condition stream) |
---|
47 | (declare (ignore condition)) |
---|
48 | (format stream "Unable to introspect Apache Ant installation.")))) |
---|
49 | |
---|
50 | |
---|
51 | ;; TODO after this routines executes *ANT-EXECUTABLE-DIRECTORY* and XDG/ANT-EXECUTABLE will work |
---|
52 | (defun ensure-ant (&key (ant-home nil ant-home-p)) |
---|
53 | "Ensure that Apache Ant may be invoked, installing one if necessary" |
---|
54 | (cond |
---|
55 | ((and (null ant-home) ant-home-p) |
---|
56 | (warn "Unimplemented explicit auto-configuration run.")) |
---|
57 | ((and ant-home ant-home-p) |
---|
58 | (warn "Unimplemented explicit configuration with specified directory directory.")) |
---|
59 | (t |
---|
60 | (if *ant-home* |
---|
61 | *ant-home* |
---|
62 | (restart-case |
---|
63 | (let ((ant-home (some-directory-containing "ant"))) |
---|
64 | (unless ant-home |
---|
65 | (signal 'no-installed-ant)) |
---|
66 | (setf *ant-home ant-home)) |
---|
67 | (install-ant () |
---|
68 | (ant/install))))))) |
---|
69 | |
---|
70 | (defmacro with-ensured-ant ((ant) &body body) |
---|
71 | `(progn |
---|
72 | (unless ,ant |
---|
73 | (setf ,ant (ensure-ant))) |
---|
74 | ,@body)) |
---|
75 | |
---|
76 | (defun ant/call (ant-file target-or-targets) |
---|
77 | "Synchronously invoke external Apache Ant on ANT-FILE with TARGET-OR-TARGETS" |
---|
78 | (let ((ant-file-pathname (if (typep ant-file 'pathname) |
---|
79 | ant-file |
---|
80 | (merge-pathnames ant-file))) |
---|
81 | ant) |
---|
82 | (with-ensured-ant (ant) |
---|
83 | (warn "About to invoke synchronous call to run external proccessâŠ") |
---|
84 | (uiop:run-program |
---|
85 | `(,ant "-buildfile" |
---|
86 | ,(stringify ant-file-pathname) |
---|
87 | ,@(listify target-or-targets)) |
---|
88 | :ignore-error-status t |
---|
89 | :error-output :string |
---|
90 | :output :string)))) |
---|