eliscript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,1676 @@
|
|
|
1
|
+
;;; eliscript-project.el --- Multi-file project builds -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; Compile a graph of local Eliscript modules into an equivalent ESM tree.
|
|
6
|
+
;; Dependency discovery happens on expanded IR so generated imports participate
|
|
7
|
+
;; in the same build as imports written directly in source.
|
|
8
|
+
|
|
9
|
+
;;; Code:
|
|
10
|
+
|
|
11
|
+
(require 'cl-lib)
|
|
12
|
+
(require 'json)
|
|
13
|
+
(require 'subr-x)
|
|
14
|
+
(require 'eliscript)
|
|
15
|
+
(require 'eliscript-diagnostic)
|
|
16
|
+
(require 'eliscript-ir)
|
|
17
|
+
|
|
18
|
+
(define-error 'eliscript-project-error
|
|
19
|
+
"Eliscript project build error"
|
|
20
|
+
'eliscript-compile-error)
|
|
21
|
+
|
|
22
|
+
(cl-defstruct (eliscript-project-macro-dependency
|
|
23
|
+
(:constructor eliscript-project-macro-dependency-create))
|
|
24
|
+
specifier
|
|
25
|
+
source
|
|
26
|
+
digest
|
|
27
|
+
content)
|
|
28
|
+
|
|
29
|
+
(cl-defstruct (eliscript-project-module
|
|
30
|
+
(:constructor eliscript-project-module-create))
|
|
31
|
+
source
|
|
32
|
+
output
|
|
33
|
+
source-map
|
|
34
|
+
source-digest
|
|
35
|
+
output-digest
|
|
36
|
+
source-map-digest
|
|
37
|
+
dependencies
|
|
38
|
+
macro-dependencies
|
|
39
|
+
portable-entries
|
|
40
|
+
reused
|
|
41
|
+
reason)
|
|
42
|
+
|
|
43
|
+
(cl-defstruct (eliscript-project-build-result
|
|
44
|
+
(:constructor eliscript-project-build-result-create))
|
|
45
|
+
root
|
|
46
|
+
out-dir
|
|
47
|
+
entry
|
|
48
|
+
entry-output
|
|
49
|
+
entries
|
|
50
|
+
entry-outputs
|
|
51
|
+
modules
|
|
52
|
+
manifest
|
|
53
|
+
digest
|
|
54
|
+
compiled-count
|
|
55
|
+
reused-count
|
|
56
|
+
mode
|
|
57
|
+
portable-entries
|
|
58
|
+
cache-enabled
|
|
59
|
+
cache-status
|
|
60
|
+
cache-reason
|
|
61
|
+
cache-read-ms
|
|
62
|
+
work-ms
|
|
63
|
+
manifest-write-ms
|
|
64
|
+
total-ms)
|
|
65
|
+
|
|
66
|
+
(cl-defstruct (eliscript-project-cache
|
|
67
|
+
(:constructor eliscript-project-cache-create))
|
|
68
|
+
records
|
|
69
|
+
sources
|
|
70
|
+
manifest
|
|
71
|
+
digest
|
|
72
|
+
source-version)
|
|
73
|
+
|
|
74
|
+
(cl-defstruct (eliscript-project-cache-lookup
|
|
75
|
+
(:constructor eliscript-project-cache-lookup-create))
|
|
76
|
+
cache
|
|
77
|
+
reason)
|
|
78
|
+
|
|
79
|
+
(cl-defstruct (eliscript-project-cache-decision
|
|
80
|
+
(:constructor eliscript-project-cache-decision-create))
|
|
81
|
+
module
|
|
82
|
+
reason)
|
|
83
|
+
|
|
84
|
+
(cl-defstruct (eliscript-project-request
|
|
85
|
+
(:constructor eliscript-project-request-create))
|
|
86
|
+
entry
|
|
87
|
+
entries
|
|
88
|
+
out-dir
|
|
89
|
+
root
|
|
90
|
+
portable-entries
|
|
91
|
+
macro-capabilities
|
|
92
|
+
macro-file-dependencies
|
|
93
|
+
use-cache
|
|
94
|
+
configuration)
|
|
95
|
+
|
|
96
|
+
(defconst eliscript-project-manifest-filename "eliscript-project.json"
|
|
97
|
+
"Filename of the deterministic project build manifest.")
|
|
98
|
+
|
|
99
|
+
(defconst eliscript-project-cache-format "eliscript-project-cache"
|
|
100
|
+
"Stable identity of private incremental project metadata.")
|
|
101
|
+
|
|
102
|
+
(defconst eliscript-project-cache-version 2
|
|
103
|
+
"Version of private incremental metadata in the project manifest.")
|
|
104
|
+
|
|
105
|
+
(defconst eliscript-project-cache-legacy-version 1
|
|
106
|
+
"Oldest private cache version accepted for read-only migration.")
|
|
107
|
+
|
|
108
|
+
(defconst eliscript-project-build-report-version 1
|
|
109
|
+
"Version of the public project build decision report.")
|
|
110
|
+
|
|
111
|
+
(defconst eliscript-project-build-report-multi-version 2
|
|
112
|
+
"Version of the multi-entry project build decision report.")
|
|
113
|
+
|
|
114
|
+
(defconst eliscript-project-configuration-version 1
|
|
115
|
+
"Current version of the public `eliscript.json' request schema.")
|
|
116
|
+
|
|
117
|
+
(defconst eliscript-project-configuration-multi-version 2
|
|
118
|
+
"Version of the public multi-entry project request schema.")
|
|
119
|
+
|
|
120
|
+
(defconst eliscript-project-configuration-format "eliscript-project-request"
|
|
121
|
+
"Stable identity of the versioned project request schema family.")
|
|
122
|
+
|
|
123
|
+
(defconst eliscript-project-configuration-filename "eliscript.json"
|
|
124
|
+
"Conventional filename for an Eliscript project request.")
|
|
125
|
+
|
|
126
|
+
(defconst eliscript-project--configuration-keys-v1
|
|
127
|
+
'(schemaVersion sourceRoot entry outDir portableEntries
|
|
128
|
+
macroCapabilities macroFileDependencies cache)
|
|
129
|
+
"Complete top-level key set accepted by configuration version 1.")
|
|
130
|
+
|
|
131
|
+
(defconst eliscript-project--configuration-keys-v2
|
|
132
|
+
'(schemaVersion sourceRoot entries outDir portableEntries
|
|
133
|
+
macroCapabilities macroFileDependencies cache)
|
|
134
|
+
"Complete top-level key set accepted by configuration version 2.")
|
|
135
|
+
|
|
136
|
+
(defvar eliscript-project-use-cache t
|
|
137
|
+
"When non-nil, project builds may reuse verified manifest artifacts.")
|
|
138
|
+
|
|
139
|
+
(defconst eliscript-project--macro-capabilities '("read-file")
|
|
140
|
+
"Macro capabilities implemented by the project host.")
|
|
141
|
+
|
|
142
|
+
(defconst eliscript-project--compiler-directory
|
|
143
|
+
(file-name-directory (or load-file-name buffer-file-name))
|
|
144
|
+
"Directory whose compiler sources determine incremental cache validity.")
|
|
145
|
+
|
|
146
|
+
(defun eliscript-project--elapsed-ms (started-at)
|
|
147
|
+
"Return non-negative milliseconds elapsed since STARTED-AT."
|
|
148
|
+
(max 0.0 (* 1000.0 (- (float-time) started-at))))
|
|
149
|
+
|
|
150
|
+
(defun eliscript-project--report-ms (milliseconds)
|
|
151
|
+
"Round MILLISECONDS to three decimal places for a build report."
|
|
152
|
+
(/ (float (round (* milliseconds 1000.0))) 1000.0))
|
|
153
|
+
|
|
154
|
+
(defun eliscript-project--fail (filename span format-string &rest arguments)
|
|
155
|
+
"Signal a project error at SPAN in FILENAME.
|
|
156
|
+
|
|
157
|
+
FORMAT-STRING and ARGUMENTS describe the failure."
|
|
158
|
+
(apply #'eliscript-diagnostic-signal
|
|
159
|
+
'eliscript-project-error "ELI-B0001" "project-build"
|
|
160
|
+
filename span format-string arguments))
|
|
161
|
+
|
|
162
|
+
(defun eliscript-project--configuration-fail
|
|
163
|
+
(filename format-string &rest arguments)
|
|
164
|
+
"Signal a configuration failure in FILENAME.
|
|
165
|
+
|
|
166
|
+
FORMAT-STRING and ARGUMENTS describe the failure."
|
|
167
|
+
(apply #'eliscript-diagnostic-signal
|
|
168
|
+
'eliscript-project-error "ELI-B0002" "project-config"
|
|
169
|
+
filename nil format-string arguments))
|
|
170
|
+
|
|
171
|
+
(defun eliscript-project--safe-relative-path-p (path)
|
|
172
|
+
"Return non-nil when PATH is a non-empty contained relative path."
|
|
173
|
+
(and (stringp path)
|
|
174
|
+
(not (string-empty-p path))
|
|
175
|
+
(not (file-name-absolute-p path))
|
|
176
|
+
(not (member ".." (split-string path "[/\\\\]" t)))))
|
|
177
|
+
|
|
178
|
+
(defun eliscript-project--configuration-field
|
|
179
|
+
(configuration key default)
|
|
180
|
+
"Return KEY from CONFIGURATION, or DEFAULT when it is absent."
|
|
181
|
+
(let ((entry (assq key configuration)))
|
|
182
|
+
(if entry (cdr entry) default)))
|
|
183
|
+
|
|
184
|
+
(defun eliscript-project--configuration-path
|
|
185
|
+
(filename directory key value)
|
|
186
|
+
"Resolve relative configuration path VALUE below DIRECTORY.
|
|
187
|
+
|
|
188
|
+
FILENAME and KEY identify invalid values in diagnostics."
|
|
189
|
+
(unless (eliscript-project--safe-relative-path-p value)
|
|
190
|
+
(eliscript-project--configuration-fail
|
|
191
|
+
filename "%s must be a contained relative path" key))
|
|
192
|
+
(expand-file-name value directory))
|
|
193
|
+
|
|
194
|
+
(defun eliscript-project--read-configuration-json ()
|
|
195
|
+
"Read one JSON value while preserving every object entry."
|
|
196
|
+
(let ((json-object-type 'alist)
|
|
197
|
+
(json-array-type 'list)
|
|
198
|
+
(json-key-type 'symbol)
|
|
199
|
+
(json-null :null)
|
|
200
|
+
(json-false :false))
|
|
201
|
+
(prog1 (json-read)
|
|
202
|
+
(skip-chars-forward " \t\r\n")
|
|
203
|
+
(unless (eobp)
|
|
204
|
+
(signal 'json-error '("trailing content after JSON value"))))))
|
|
205
|
+
|
|
206
|
+
(defun eliscript-project-read-configuration (filename)
|
|
207
|
+
"Read and validate a versioned project request from FILENAME."
|
|
208
|
+
(let* ((expanded (expand-file-name filename))
|
|
209
|
+
(canonical
|
|
210
|
+
(if (file-regular-p expanded)
|
|
211
|
+
(file-truename expanded)
|
|
212
|
+
(eliscript-project--configuration-fail
|
|
213
|
+
expanded "configuration file does not exist")))
|
|
214
|
+
(directory (file-name-directory canonical))
|
|
215
|
+
configuration)
|
|
216
|
+
(condition-case error-data
|
|
217
|
+
(with-temp-buffer
|
|
218
|
+
(insert-file-contents canonical)
|
|
219
|
+
(setq configuration
|
|
220
|
+
(eliscript-project--read-configuration-json)))
|
|
221
|
+
(error
|
|
222
|
+
(eliscript-project--configuration-fail
|
|
223
|
+
canonical "invalid JSON: %s" (error-message-string error-data))))
|
|
224
|
+
(unless (and (listp configuration)
|
|
225
|
+
(cl-every #'consp configuration))
|
|
226
|
+
(eliscript-project--configuration-fail
|
|
227
|
+
canonical "configuration root must be an object"))
|
|
228
|
+
(let (seen duplicate)
|
|
229
|
+
(dolist (key (mapcar #'car configuration))
|
|
230
|
+
(if (memq key seen)
|
|
231
|
+
(unless duplicate (setq duplicate key))
|
|
232
|
+
(push key seen)))
|
|
233
|
+
(when duplicate
|
|
234
|
+
(eliscript-project--configuration-fail
|
|
235
|
+
canonical "duplicate configuration key: %s" duplicate)))
|
|
236
|
+
(let* ((version
|
|
237
|
+
(eliscript-project--configuration-field
|
|
238
|
+
configuration 'schemaVersion nil))
|
|
239
|
+
(configuration-keys
|
|
240
|
+
(cond
|
|
241
|
+
((equal version eliscript-project-configuration-version)
|
|
242
|
+
eliscript-project--configuration-keys-v1)
|
|
243
|
+
((equal version eliscript-project-configuration-multi-version)
|
|
244
|
+
eliscript-project--configuration-keys-v2)
|
|
245
|
+
(t
|
|
246
|
+
(eliscript-project--configuration-fail
|
|
247
|
+
canonical "unsupported schemaVersion: %s" version))))
|
|
248
|
+
(unknown
|
|
249
|
+
(sort
|
|
250
|
+
(cl-remove-if
|
|
251
|
+
(lambda (key)
|
|
252
|
+
(memq key configuration-keys))
|
|
253
|
+
(mapcar #'car configuration))
|
|
254
|
+
(lambda (left right)
|
|
255
|
+
(string-lessp (symbol-name left) (symbol-name right))))))
|
|
256
|
+
(when unknown
|
|
257
|
+
(eliscript-project--configuration-fail
|
|
258
|
+
canonical "unknown configuration key: %s" (car unknown))))
|
|
259
|
+
(let* ((version
|
|
260
|
+
(eliscript-project--configuration-field
|
|
261
|
+
configuration 'schemaVersion nil))
|
|
262
|
+
(source-root
|
|
263
|
+
(eliscript-project--configuration-field
|
|
264
|
+
configuration 'sourceRoot "."))
|
|
265
|
+
(entry
|
|
266
|
+
(eliscript-project--configuration-field
|
|
267
|
+
configuration 'entry nil))
|
|
268
|
+
(entries
|
|
269
|
+
(eliscript-project--configuration-field
|
|
270
|
+
configuration 'entries nil))
|
|
271
|
+
(out-dir
|
|
272
|
+
(eliscript-project--configuration-field
|
|
273
|
+
configuration 'outDir nil))
|
|
274
|
+
(portable-entries
|
|
275
|
+
(eliscript-project--configuration-field
|
|
276
|
+
configuration 'portableEntries nil))
|
|
277
|
+
(macro-capabilities
|
|
278
|
+
(eliscript-project--configuration-field
|
|
279
|
+
configuration 'macroCapabilities nil))
|
|
280
|
+
(macro-file-dependencies
|
|
281
|
+
(eliscript-project--configuration-field
|
|
282
|
+
configuration 'macroFileDependencies nil))
|
|
283
|
+
(cache
|
|
284
|
+
(eliscript-project--configuration-field
|
|
285
|
+
configuration 'cache t)))
|
|
286
|
+
(unless (and (listp portable-entries)
|
|
287
|
+
(cl-every
|
|
288
|
+
(lambda (name)
|
|
289
|
+
(and (stringp name) (not (string-empty-p name))))
|
|
290
|
+
portable-entries))
|
|
291
|
+
(eliscript-project--configuration-fail
|
|
292
|
+
canonical "portableEntries must be an array of non-empty strings"))
|
|
293
|
+
(unless (= (length portable-entries)
|
|
294
|
+
(length (delete-dups (copy-sequence portable-entries))))
|
|
295
|
+
(eliscript-project--configuration-fail
|
|
296
|
+
canonical "portableEntries must not contain duplicates"))
|
|
297
|
+
(unless (and (listp macro-capabilities)
|
|
298
|
+
(cl-every
|
|
299
|
+
(lambda (name)
|
|
300
|
+
(and (stringp name) (not (string-empty-p name))))
|
|
301
|
+
macro-capabilities))
|
|
302
|
+
(eliscript-project--configuration-fail
|
|
303
|
+
canonical "macroCapabilities must be an array of non-empty strings"))
|
|
304
|
+
(unless (= (length macro-capabilities)
|
|
305
|
+
(length (delete-dups (copy-sequence macro-capabilities))))
|
|
306
|
+
(eliscript-project--configuration-fail
|
|
307
|
+
canonical "macroCapabilities must not contain duplicates"))
|
|
308
|
+
(let ((unsupported
|
|
309
|
+
(cl-find-if
|
|
310
|
+
(lambda (name)
|
|
311
|
+
(not (member name eliscript-project--macro-capabilities)))
|
|
312
|
+
macro-capabilities)))
|
|
313
|
+
(when unsupported
|
|
314
|
+
(eliscript-project--configuration-fail
|
|
315
|
+
canonical "unsupported macro capability: %s" unsupported)))
|
|
316
|
+
(unless (and (listp macro-file-dependencies)
|
|
317
|
+
(cl-every #'eliscript-project--safe-relative-path-p
|
|
318
|
+
macro-file-dependencies))
|
|
319
|
+
(eliscript-project--configuration-fail
|
|
320
|
+
canonical
|
|
321
|
+
"macroFileDependencies must contain only contained relative paths"))
|
|
322
|
+
(unless (= (length macro-file-dependencies)
|
|
323
|
+
(length
|
|
324
|
+
(delete-dups (copy-sequence macro-file-dependencies))))
|
|
325
|
+
(eliscript-project--configuration-fail
|
|
326
|
+
canonical "macroFileDependencies must not contain duplicates"))
|
|
327
|
+
(when (and macro-file-dependencies
|
|
328
|
+
(not (member "read-file" macro-capabilities)))
|
|
329
|
+
(eliscript-project--configuration-fail
|
|
330
|
+
canonical
|
|
331
|
+
"macroFileDependencies require the read-file macro capability"))
|
|
332
|
+
(unless (memq cache '(t :false))
|
|
333
|
+
(eliscript-project--configuration-fail
|
|
334
|
+
canonical "cache must be a boolean"))
|
|
335
|
+
(when (equal version eliscript-project-configuration-multi-version)
|
|
336
|
+
(unless (and (listp entries) entries
|
|
337
|
+
(cl-every #'eliscript-project--safe-relative-path-p
|
|
338
|
+
entries))
|
|
339
|
+
(eliscript-project--configuration-fail
|
|
340
|
+
canonical
|
|
341
|
+
"entries must be an array of contained relative paths"))
|
|
342
|
+
(unless (= (length entries)
|
|
343
|
+
(length (delete-dups (copy-sequence entries))))
|
|
344
|
+
(eliscript-project--configuration-fail
|
|
345
|
+
canonical "entries must not contain duplicates"))
|
|
346
|
+
(when (and (> (length entries) 1) portable-entries)
|
|
347
|
+
(eliscript-project--configuration-fail
|
|
348
|
+
canonical
|
|
349
|
+
"multi-entry portable project configurations are not supported")))
|
|
350
|
+
(let* ((root
|
|
351
|
+
(eliscript-project--configuration-path
|
|
352
|
+
canonical directory 'sourceRoot source-root))
|
|
353
|
+
(entry-paths
|
|
354
|
+
(if (equal version
|
|
355
|
+
eliscript-project-configuration-multi-version)
|
|
356
|
+
(sort
|
|
357
|
+
(mapcar
|
|
358
|
+
(lambda (source)
|
|
359
|
+
(eliscript-project--configuration-path
|
|
360
|
+
canonical root 'entries source))
|
|
361
|
+
entries)
|
|
362
|
+
#'string-lessp)
|
|
363
|
+
(list
|
|
364
|
+
(eliscript-project--configuration-path
|
|
365
|
+
canonical root 'entry entry))))
|
|
366
|
+
(output-path
|
|
367
|
+
(eliscript-project--configuration-path
|
|
368
|
+
canonical directory 'outDir out-dir)))
|
|
369
|
+
(eliscript-project-request-create
|
|
370
|
+
:entry (and (= (length entry-paths) 1) (car entry-paths))
|
|
371
|
+
:entries (and (equal version
|
|
372
|
+
eliscript-project-configuration-multi-version)
|
|
373
|
+
entry-paths)
|
|
374
|
+
:out-dir output-path
|
|
375
|
+
:root root
|
|
376
|
+
:portable-entries portable-entries
|
|
377
|
+
:macro-capabilities (sort macro-capabilities #'string-lessp)
|
|
378
|
+
:macro-file-dependencies
|
|
379
|
+
(sort macro-file-dependencies #'string-lessp)
|
|
380
|
+
:use-cache (eq cache t)
|
|
381
|
+
:configuration canonical)))))
|
|
382
|
+
|
|
383
|
+
(defun eliscript-project-execute (request)
|
|
384
|
+
"Execute validated project build REQUEST through the shared operation."
|
|
385
|
+
(unless (eliscript-project-request-p request)
|
|
386
|
+
(eliscript-project--fail nil nil "project request is invalid"))
|
|
387
|
+
(let* ((entry (eliscript-project-request-entry request))
|
|
388
|
+
(requested-entries (eliscript-project-request-entries request))
|
|
389
|
+
(entries (or requested-entries (and entry (list entry))))
|
|
390
|
+
(out-dir (eliscript-project-request-out-dir request))
|
|
391
|
+
(root (eliscript-project-request-root request))
|
|
392
|
+
(portable-entries
|
|
393
|
+
(eliscript-project-request-portable-entries request))
|
|
394
|
+
(macro-capabilities
|
|
395
|
+
(eliscript-project-request-macro-capabilities request))
|
|
396
|
+
(macro-file-dependencies
|
|
397
|
+
(eliscript-project-request-macro-file-dependencies request))
|
|
398
|
+
(eliscript-project-use-cache
|
|
399
|
+
(eliscript-project-request-use-cache request)))
|
|
400
|
+
(unless (and entries
|
|
401
|
+
(cl-every
|
|
402
|
+
(lambda (source)
|
|
403
|
+
(and (stringp source) (not (string-empty-p source))))
|
|
404
|
+
entries)
|
|
405
|
+
(= (length entries)
|
|
406
|
+
(length (delete-dups (copy-sequence entries)))))
|
|
407
|
+
(eliscript-project--fail nil nil "project request entries are invalid"))
|
|
408
|
+
(unless (and (stringp out-dir) (not (string-empty-p out-dir)))
|
|
409
|
+
(eliscript-project--fail (car entries) nil
|
|
410
|
+
"project request output is invalid"))
|
|
411
|
+
(unless (or (null root) (stringp root))
|
|
412
|
+
(eliscript-project--fail (car entries) nil
|
|
413
|
+
"project request root is invalid"))
|
|
414
|
+
(unless (and (listp portable-entries)
|
|
415
|
+
(cl-every
|
|
416
|
+
(lambda (name)
|
|
417
|
+
(or (symbolp name)
|
|
418
|
+
(and (stringp name) (not (string-empty-p name)))))
|
|
419
|
+
portable-entries))
|
|
420
|
+
(eliscript-project--fail
|
|
421
|
+
(car entries) nil "project request portable entries are invalid"))
|
|
422
|
+
(when (and (> (length entries) 1) portable-entries)
|
|
423
|
+
(eliscript-project--fail
|
|
424
|
+
(car entries) nil
|
|
425
|
+
"multi-entry portable project requests are not supported"))
|
|
426
|
+
(unless (and (listp macro-capabilities)
|
|
427
|
+
(cl-every
|
|
428
|
+
(lambda (name)
|
|
429
|
+
(member name eliscript-project--macro-capabilities))
|
|
430
|
+
macro-capabilities))
|
|
431
|
+
(eliscript-project--fail
|
|
432
|
+
(car entries) nil "project request macro capabilities are invalid"))
|
|
433
|
+
(unless (= (length macro-capabilities)
|
|
434
|
+
(length (delete-dups (copy-sequence macro-capabilities))))
|
|
435
|
+
(eliscript-project--fail
|
|
436
|
+
(car entries) nil
|
|
437
|
+
"project request macro capabilities must not contain duplicates"))
|
|
438
|
+
(unless (and (listp macro-file-dependencies)
|
|
439
|
+
(cl-every #'eliscript-project--safe-relative-path-p
|
|
440
|
+
macro-file-dependencies))
|
|
441
|
+
(eliscript-project--fail
|
|
442
|
+
(car entries) nil "project request macro file dependencies are invalid"))
|
|
443
|
+
(unless (= (length macro-file-dependencies)
|
|
444
|
+
(length
|
|
445
|
+
(delete-dups (copy-sequence macro-file-dependencies))))
|
|
446
|
+
(eliscript-project--fail
|
|
447
|
+
(car entries) nil
|
|
448
|
+
"project request macro file dependencies must not contain duplicates"))
|
|
449
|
+
(when (and macro-file-dependencies
|
|
450
|
+
(not (member "read-file" macro-capabilities)))
|
|
451
|
+
(eliscript-project--fail
|
|
452
|
+
(car entries) nil
|
|
453
|
+
"macro file dependencies require the read-file macro capability"))
|
|
454
|
+
(setq macro-capabilities
|
|
455
|
+
(sort (copy-sequence macro-capabilities) #'string-lessp)
|
|
456
|
+
macro-file-dependencies
|
|
457
|
+
(sort (copy-sequence macro-file-dependencies) #'string-lessp))
|
|
458
|
+
(if portable-entries
|
|
459
|
+
(eliscript-project-build-portable
|
|
460
|
+
(car entries) portable-entries out-dir root
|
|
461
|
+
macro-capabilities macro-file-dependencies)
|
|
462
|
+
(eliscript-project--build-many
|
|
463
|
+
entries out-dir root macro-capabilities macro-file-dependencies))))
|
|
464
|
+
|
|
465
|
+
(defun eliscript-project--canonical-directory (directory label)
|
|
466
|
+
"Return canonical DIRECTORY with a trailing slash, or fail using LABEL."
|
|
467
|
+
(let ((path (expand-file-name directory)))
|
|
468
|
+
(unless (file-directory-p path)
|
|
469
|
+
(eliscript-project--fail path nil "%s is not a directory" label))
|
|
470
|
+
(file-name-as-directory (file-truename path))))
|
|
471
|
+
|
|
472
|
+
(defun eliscript-project--canonical-source (path root filename span)
|
|
473
|
+
"Return canonical source PATH after validating it against ROOT.
|
|
474
|
+
|
|
475
|
+
FILENAME and SPAN identify the import responsible for PATH."
|
|
476
|
+
(let ((expanded (expand-file-name path)))
|
|
477
|
+
(unless (file-regular-p expanded)
|
|
478
|
+
(eliscript-project--fail
|
|
479
|
+
filename span "local Eliscript module does not exist: %s" path))
|
|
480
|
+
(let ((canonical (file-truename expanded)))
|
|
481
|
+
(unless (file-in-directory-p canonical root)
|
|
482
|
+
(eliscript-project--fail
|
|
483
|
+
filename span "local Eliscript module escapes project root: %s" path))
|
|
484
|
+
canonical)))
|
|
485
|
+
|
|
486
|
+
(defun eliscript-project--macro-dependencies (specifiers root filename)
|
|
487
|
+
"Resolve declared macro file SPECIFIERS below ROOT for FILENAME."
|
|
488
|
+
(let ((dependencies
|
|
489
|
+
(mapcar
|
|
490
|
+
(lambda (specifier)
|
|
491
|
+
(let ((expanded (expand-file-name specifier root)))
|
|
492
|
+
(unless (file-regular-p expanded)
|
|
493
|
+
(eliscript-project--fail
|
|
494
|
+
filename nil
|
|
495
|
+
"macro file dependency does not exist: %s" specifier))
|
|
496
|
+
(let ((source (file-truename expanded)))
|
|
497
|
+
(unless (file-in-directory-p source root)
|
|
498
|
+
(eliscript-project--fail
|
|
499
|
+
filename nil
|
|
500
|
+
"macro file dependency escapes project root: %s" specifier))
|
|
501
|
+
(let ((snapshot
|
|
502
|
+
(eliscript-project--read-utf8-input source specifier)))
|
|
503
|
+
(eliscript-project-macro-dependency-create
|
|
504
|
+
:specifier specifier
|
|
505
|
+
:source source
|
|
506
|
+
:digest (car snapshot)
|
|
507
|
+
:content (cdr snapshot))))))
|
|
508
|
+
specifiers)))
|
|
509
|
+
(unless (= (length dependencies)
|
|
510
|
+
(length
|
|
511
|
+
(delete-dups
|
|
512
|
+
(mapcar #'eliscript-project-macro-dependency-source
|
|
513
|
+
dependencies))))
|
|
514
|
+
(eliscript-project--fail
|
|
515
|
+
filename nil "macro file dependencies resolve to duplicates"))
|
|
516
|
+
dependencies))
|
|
517
|
+
|
|
518
|
+
(defun eliscript-project--read-utf8-input (filename specifier)
|
|
519
|
+
"Return FILENAME's SHA-256 digest and UTF-8 text for macro SPECIFIER."
|
|
520
|
+
(let (bytes decoded)
|
|
521
|
+
(with-temp-buffer
|
|
522
|
+
(set-buffer-multibyte nil)
|
|
523
|
+
(insert-file-contents-literally filename)
|
|
524
|
+
(setq bytes (buffer-string)))
|
|
525
|
+
(setq decoded (decode-coding-string bytes 'utf-8-unix))
|
|
526
|
+
(unless (and (not (cl-some (lambda (character)
|
|
527
|
+
(> character #x10ffff))
|
|
528
|
+
decoded))
|
|
529
|
+
(equal bytes
|
|
530
|
+
(encode-coding-string decoded 'utf-8-unix t)))
|
|
531
|
+
(eliscript-project--fail
|
|
532
|
+
filename nil "macro file dependency is not valid UTF-8: %s" specifier))
|
|
533
|
+
(cons (secure-hash 'sha256 bytes) decoded)))
|
|
534
|
+
|
|
535
|
+
(defun eliscript-project--macro-context (capabilities dependencies)
|
|
536
|
+
"Create a compiler macro context from CAPABILITIES and DEPENDENCIES."
|
|
537
|
+
(let ((capability-table (make-hash-table :test #'equal))
|
|
538
|
+
(file-table (make-hash-table :test #'equal)))
|
|
539
|
+
(dolist (capability capabilities)
|
|
540
|
+
(puthash capability t capability-table))
|
|
541
|
+
(dolist (dependency dependencies)
|
|
542
|
+
(puthash
|
|
543
|
+
(eliscript-project-macro-dependency-specifier dependency)
|
|
544
|
+
(eliscript-project-macro-dependency-content dependency)
|
|
545
|
+
file-table))
|
|
546
|
+
(list :capabilities capability-table :files file-table)))
|
|
547
|
+
|
|
548
|
+
(defun eliscript-project--macro-dependency-records (dependencies root)
|
|
549
|
+
"Return stable manifest records for macro DEPENDENCIES below ROOT."
|
|
550
|
+
(vconcat
|
|
551
|
+
(mapcar
|
|
552
|
+
(lambda (dependency)
|
|
553
|
+
`((path . ,(file-relative-name
|
|
554
|
+
(eliscript-project-macro-dependency-source dependency) root))
|
|
555
|
+
(digest . ,(eliscript-project-macro-dependency-digest dependency))))
|
|
556
|
+
dependencies)))
|
|
557
|
+
|
|
558
|
+
(defun eliscript-project--source-output (source root out-dir)
|
|
559
|
+
"Map Eliscript SOURCE below ROOT into its ESM path below OUT-DIR."
|
|
560
|
+
(let ((relative (file-relative-name source root)))
|
|
561
|
+
(expand-file-name
|
|
562
|
+
(concat (string-remove-suffix ".eli" relative) ".mjs")
|
|
563
|
+
out-dir)))
|
|
564
|
+
|
|
565
|
+
(defun eliscript-project--same-file-path-p (left right)
|
|
566
|
+
"Return non-nil when LEFT and RIGHT name the same physical file."
|
|
567
|
+
(or (string-equal (file-truename left) (file-truename right))
|
|
568
|
+
(and (file-exists-p left)
|
|
569
|
+
(file-exists-p right)
|
|
570
|
+
(condition-case nil
|
|
571
|
+
(file-equal-p left right)
|
|
572
|
+
(file-error nil)))))
|
|
573
|
+
|
|
574
|
+
(defun eliscript-project--path-contained-p (root candidate)
|
|
575
|
+
"Return non-nil when CANDIDATE is lexically contained below canonical ROOT."
|
|
576
|
+
(let ((relative
|
|
577
|
+
(file-relative-name candidate (file-name-as-directory root))))
|
|
578
|
+
(and (not (file-name-absolute-p relative))
|
|
579
|
+
(not (string-equal relative ".."))
|
|
580
|
+
(not (string-prefix-p (file-name-as-directory "..") relative)))))
|
|
581
|
+
|
|
582
|
+
(defun eliscript-project--validate-output-isolation
|
|
583
|
+
(sources macro-dependencies root out-dir)
|
|
584
|
+
"Validate every generated path before writing SOURCES below OUT-DIR.
|
|
585
|
+
|
|
586
|
+
MACRO-DEPENDENCIES and SOURCES are protected inputs. ROOT maps source paths
|
|
587
|
+
to output paths. Existing symbolic and hard links cannot redirect generated
|
|
588
|
+
artifacts onto an input, another artifact, or outside OUT-DIR."
|
|
589
|
+
(let* ((protected
|
|
590
|
+
(append
|
|
591
|
+
sources
|
|
592
|
+
(mapcar #'eliscript-project-macro-dependency-source
|
|
593
|
+
macro-dependencies)))
|
|
594
|
+
(artifacts
|
|
595
|
+
(append
|
|
596
|
+
(apply
|
|
597
|
+
#'append
|
|
598
|
+
(mapcar
|
|
599
|
+
(lambda (source)
|
|
600
|
+
(let ((output
|
|
601
|
+
(eliscript-project--source-output
|
|
602
|
+
source root out-dir)))
|
|
603
|
+
(list output (concat output ".map"))))
|
|
604
|
+
sources))
|
|
605
|
+
(list (expand-file-name
|
|
606
|
+
eliscript-project-manifest-filename out-dir))))
|
|
607
|
+
validated)
|
|
608
|
+
(dolist (artifact artifacts)
|
|
609
|
+
(let ((physical
|
|
610
|
+
(condition-case nil
|
|
611
|
+
(file-truename artifact)
|
|
612
|
+
(file-error
|
|
613
|
+
(eliscript-project--fail
|
|
614
|
+
artifact nil
|
|
615
|
+
"generated artifact path cannot be resolved: %s"
|
|
616
|
+
artifact)))))
|
|
617
|
+
(unless (eliscript-project--path-contained-p out-dir physical)
|
|
618
|
+
(eliscript-project--fail
|
|
619
|
+
artifact nil "generated artifact escapes output directory: %s"
|
|
620
|
+
artifact))
|
|
621
|
+
(when (cl-some
|
|
622
|
+
(lambda (input)
|
|
623
|
+
(eliscript-project--same-file-path-p artifact input))
|
|
624
|
+
protected)
|
|
625
|
+
(eliscript-project--fail
|
|
626
|
+
artifact nil "generated artifact would overwrite an input: %s"
|
|
627
|
+
artifact))
|
|
628
|
+
(when (cl-some
|
|
629
|
+
(lambda (previous)
|
|
630
|
+
(eliscript-project--same-file-path-p artifact previous))
|
|
631
|
+
validated)
|
|
632
|
+
(eliscript-project--fail
|
|
633
|
+
artifact nil "generated artifacts resolve to the same file: %s"
|
|
634
|
+
artifact))
|
|
635
|
+
(push artifact validated)))))
|
|
636
|
+
|
|
637
|
+
(defun eliscript-project--relative-import (target importer)
|
|
638
|
+
"Return an ESM import from IMPORTER to TARGET."
|
|
639
|
+
(let ((relative
|
|
640
|
+
(file-relative-name target (file-name-directory importer))))
|
|
641
|
+
(if (or (string-prefix-p "./" relative)
|
|
642
|
+
(string-prefix-p "../" relative))
|
|
643
|
+
relative
|
|
644
|
+
(concat "./" relative))))
|
|
645
|
+
|
|
646
|
+
(defun eliscript-project--local-import-p (specifier)
|
|
647
|
+
"Return non-nil when SPECIFIER is a relative Eliscript source import."
|
|
648
|
+
(and (string-suffix-p ".eli" specifier)
|
|
649
|
+
(or (string-prefix-p "./" specifier)
|
|
650
|
+
(string-prefix-p "../" specifier))))
|
|
651
|
+
|
|
652
|
+
(defun eliscript-project--read-source (filename)
|
|
653
|
+
"Read FILENAME as a string."
|
|
654
|
+
(with-temp-buffer
|
|
655
|
+
(insert-file-contents filename)
|
|
656
|
+
(buffer-string)))
|
|
657
|
+
|
|
658
|
+
(defun eliscript-project--file-digest (filename)
|
|
659
|
+
"Return the lowercase SHA-256 digest of FILENAME's exact bytes."
|
|
660
|
+
(with-temp-buffer
|
|
661
|
+
(set-buffer-multibyte nil)
|
|
662
|
+
(insert-file-contents-literally filename)
|
|
663
|
+
(secure-hash 'sha256 (current-buffer))))
|
|
664
|
+
|
|
665
|
+
(defun eliscript-project--json-digest (object)
|
|
666
|
+
"Return SHA-256 over the compact UTF-8 JSON encoding of OBJECT."
|
|
667
|
+
(secure-hash
|
|
668
|
+
'sha256
|
|
669
|
+
(encode-coding-string (json-serialize object) 'utf-8-unix t)))
|
|
670
|
+
|
|
671
|
+
(defun eliscript-project--compiler-digest ()
|
|
672
|
+
"Return a digest identifying the loaded seed compiler implementation."
|
|
673
|
+
(let ((files
|
|
674
|
+
(sort
|
|
675
|
+
(directory-files-recursively
|
|
676
|
+
eliscript-project--compiler-directory "\\.el\\'")
|
|
677
|
+
#'string-lessp))
|
|
678
|
+
parts)
|
|
679
|
+
(dolist (file files)
|
|
680
|
+
(push
|
|
681
|
+
(format "%s\0%s"
|
|
682
|
+
(file-relative-name file eliscript-project--compiler-directory)
|
|
683
|
+
(eliscript-project--file-digest file))
|
|
684
|
+
parts))
|
|
685
|
+
(secure-hash
|
|
686
|
+
'sha256
|
|
687
|
+
(encode-coding-string (mapconcat #'identity (nreverse parts) "\n")
|
|
688
|
+
'utf-8-unix t))))
|
|
689
|
+
|
|
690
|
+
(defun eliscript-project--portable-entry-names (entries)
|
|
691
|
+
"Return stable string names for portable ENTRIES."
|
|
692
|
+
(sort
|
|
693
|
+
(delete-dups
|
|
694
|
+
(mapcar (lambda (entry)
|
|
695
|
+
(if (symbolp entry) (symbol-name entry) entry))
|
|
696
|
+
entries))
|
|
697
|
+
#'string-lessp))
|
|
698
|
+
|
|
699
|
+
(defun eliscript-project--cache-module (module root)
|
|
700
|
+
"Return private cache metadata for MODULE relative to ROOT."
|
|
701
|
+
`((source . ,(file-relative-name
|
|
702
|
+
(eliscript-project-module-source module) root))
|
|
703
|
+
(dependencies
|
|
704
|
+
. ,(vconcat
|
|
705
|
+
(mapcar (lambda (dependency)
|
|
706
|
+
(file-relative-name dependency root))
|
|
707
|
+
(or (eliscript-project-module-dependencies module) nil))))
|
|
708
|
+
,@(when (eliscript-project-module-macro-dependencies module)
|
|
709
|
+
`((macroDependencies
|
|
710
|
+
. ,(eliscript-project--macro-dependency-records
|
|
711
|
+
(eliscript-project-module-macro-dependencies module) root))))
|
|
712
|
+
(portableEntries
|
|
713
|
+
. ,(vconcat
|
|
714
|
+
(or (eliscript-project-module-portable-entries module) nil)))))
|
|
715
|
+
|
|
716
|
+
(defun eliscript-project--cache-identity-module (record)
|
|
717
|
+
"Normalize parsed cache RECORD for deterministic digest verification."
|
|
718
|
+
`((source . ,(alist-get 'source record))
|
|
719
|
+
(dependencies . ,(vconcat (alist-get 'dependencies record)))
|
|
720
|
+
,@(when (assq 'macroDependencies record)
|
|
721
|
+
`((macroDependencies
|
|
722
|
+
. ,(vconcat (alist-get 'macroDependencies record)))))
|
|
723
|
+
(portableEntries . ,(vconcat (alist-get 'portableEntries record)))))
|
|
724
|
+
|
|
725
|
+
(defun eliscript-project--manifest-identity-module (record)
|
|
726
|
+
"Normalize parsed public manifest RECORD for digest verification."
|
|
727
|
+
(mapcar
|
|
728
|
+
(lambda (entry)
|
|
729
|
+
(if (eq (car entry) 'macroDependencies)
|
|
730
|
+
(cons 'macroDependencies (vconcat (cdr entry)))
|
|
731
|
+
entry))
|
|
732
|
+
record))
|
|
733
|
+
|
|
734
|
+
(defun eliscript-project--cache-version-kind (cache)
|
|
735
|
+
"Return the supported version kind of CACHE, or nil."
|
|
736
|
+
(cond
|
|
737
|
+
((and (equal (alist-get 'format cache) eliscript-project-cache-format)
|
|
738
|
+
(equal (alist-get 'version cache) eliscript-project-cache-version))
|
|
739
|
+
'current)
|
|
740
|
+
((and (null (alist-get 'format cache))
|
|
741
|
+
(equal (alist-get 'version cache)
|
|
742
|
+
eliscript-project-cache-legacy-version))
|
|
743
|
+
'legacy)))
|
|
744
|
+
|
|
745
|
+
(defun eliscript-project--cache-identity (cache cache-modules version-kind)
|
|
746
|
+
"Normalize CACHE and CACHE-MODULES for VERSION-KIND digest verification."
|
|
747
|
+
(let ((identity
|
|
748
|
+
`((version . ,(alist-get 'version cache))
|
|
749
|
+
(compilerDigest . ,(alist-get 'compilerDigest cache))
|
|
750
|
+
(mode . ,(alist-get 'mode cache))
|
|
751
|
+
(portableEntries . ,(vconcat (alist-get 'portableEntries cache)))
|
|
752
|
+
(modules
|
|
753
|
+
. ,(vconcat
|
|
754
|
+
(mapcar
|
|
755
|
+
#'eliscript-project--cache-identity-module
|
|
756
|
+
cache-modules))))))
|
|
757
|
+
(if (eq version-kind 'current)
|
|
758
|
+
(cons `(format . ,(alist-get 'format cache)) identity)
|
|
759
|
+
identity)))
|
|
760
|
+
|
|
761
|
+
(defun eliscript-project--cache-miss (reason)
|
|
762
|
+
"Return a cache lookup miss with stable REASON."
|
|
763
|
+
(eliscript-project-cache-lookup-create :reason reason))
|
|
764
|
+
|
|
765
|
+
(defun eliscript-project--read-cache
|
|
766
|
+
(out-dir entry-outputs mode portable-entries compiler-digest)
|
|
767
|
+
"Read reusable build metadata for the requested project configuration."
|
|
768
|
+
(let ((manifest-path
|
|
769
|
+
(expand-file-name eliscript-project-manifest-filename out-dir)))
|
|
770
|
+
(cond
|
|
771
|
+
((not eliscript-project-use-cache)
|
|
772
|
+
(eliscript-project--cache-miss "cache-disabled"))
|
|
773
|
+
((not (file-regular-p manifest-path))
|
|
774
|
+
(eliscript-project--cache-miss "manifest-missing"))
|
|
775
|
+
(t
|
|
776
|
+
(condition-case nil
|
|
777
|
+
(let* ((manifest
|
|
778
|
+
(with-temp-buffer
|
|
779
|
+
(insert-file-contents manifest-path)
|
|
780
|
+
(json-parse-buffer
|
|
781
|
+
:object-type 'alist :array-type 'list
|
|
782
|
+
:null-object nil :false-object :false)))
|
|
783
|
+
(cache (alist-get 'cache manifest))
|
|
784
|
+
(identity-modules (alist-get 'modules manifest))
|
|
785
|
+
(cache-modules (alist-get 'modules cache))
|
|
786
|
+
(cache-version-kind
|
|
787
|
+
(and (consp cache)
|
|
788
|
+
(eliscript-project--cache-version-kind cache)))
|
|
789
|
+
(expected-entries
|
|
790
|
+
(mapcar
|
|
791
|
+
(lambda (entry-output)
|
|
792
|
+
(file-relative-name entry-output out-dir))
|
|
793
|
+
entry-outputs)))
|
|
794
|
+
(cond
|
|
795
|
+
((or (not (equal (alist-get 'format manifest)
|
|
796
|
+
"eliscript-project"))
|
|
797
|
+
(not (memq (alist-get 'version manifest) '(1 2)))
|
|
798
|
+
(not (listp identity-modules)))
|
|
799
|
+
(eliscript-project--cache-miss "manifest-version-changed"))
|
|
800
|
+
((and (equal (alist-get 'version manifest) 1)
|
|
801
|
+
(not (equal (list (alist-get 'entry manifest))
|
|
802
|
+
expected-entries)))
|
|
803
|
+
(eliscript-project--cache-miss "entry-changed"))
|
|
804
|
+
((and (equal (alist-get 'version manifest) 2)
|
|
805
|
+
(not (equal (alist-get 'entries manifest)
|
|
806
|
+
expected-entries)))
|
|
807
|
+
(eliscript-project--cache-miss "entries-changed"))
|
|
808
|
+
((let ((graph-identity
|
|
809
|
+
(if (equal (alist-get 'version manifest) 1)
|
|
810
|
+
`((format . ,(alist-get 'format manifest))
|
|
811
|
+
(version . 1)
|
|
812
|
+
(entry . ,(alist-get 'entry manifest))
|
|
813
|
+
(modules
|
|
814
|
+
. ,(vconcat
|
|
815
|
+
(mapcar
|
|
816
|
+
#'eliscript-project--manifest-identity-module
|
|
817
|
+
identity-modules))))
|
|
818
|
+
`((format . ,(alist-get 'format manifest))
|
|
819
|
+
(version . 2)
|
|
820
|
+
(entries . ,(vconcat (alist-get 'entries manifest)))
|
|
821
|
+
(modules
|
|
822
|
+
. ,(vconcat
|
|
823
|
+
(mapcar
|
|
824
|
+
#'eliscript-project--manifest-identity-module
|
|
825
|
+
identity-modules)))))))
|
|
826
|
+
(not (equal (alist-get 'digest manifest)
|
|
827
|
+
(eliscript-project--json-digest graph-identity))))
|
|
828
|
+
(eliscript-project--cache-miss "graph-digest-invalid"))
|
|
829
|
+
((not (consp cache))
|
|
830
|
+
(eliscript-project--cache-miss "cache-missing"))
|
|
831
|
+
((not cache-version-kind)
|
|
832
|
+
(eliscript-project--cache-miss "cache-version-changed"))
|
|
833
|
+
((not (listp cache-modules))
|
|
834
|
+
(eliscript-project--cache-miss "cache-records-invalid"))
|
|
835
|
+
((let ((cache-identity
|
|
836
|
+
(eliscript-project--cache-identity
|
|
837
|
+
cache cache-modules cache-version-kind)))
|
|
838
|
+
(not (equal (alist-get 'digest cache)
|
|
839
|
+
(eliscript-project--json-digest cache-identity))))
|
|
840
|
+
(eliscript-project--cache-miss "cache-digest-invalid"))
|
|
841
|
+
((not (equal (alist-get 'compilerDigest cache)
|
|
842
|
+
compiler-digest))
|
|
843
|
+
(eliscript-project--cache-miss "compiler-changed"))
|
|
844
|
+
((not (equal (alist-get 'mode cache) mode))
|
|
845
|
+
(eliscript-project--cache-miss "mode-changed"))
|
|
846
|
+
((not (equal (alist-get 'portableEntries cache)
|
|
847
|
+
portable-entries))
|
|
848
|
+
(eliscript-project--cache-miss "portable-roots-changed"))
|
|
849
|
+
(t
|
|
850
|
+
(let ((identities (make-hash-table :test #'equal))
|
|
851
|
+
(records (make-hash-table :test #'equal))
|
|
852
|
+
sources)
|
|
853
|
+
(dolist (record identity-modules)
|
|
854
|
+
(let ((source (alist-get 'source record)))
|
|
855
|
+
(when (stringp source)
|
|
856
|
+
(puthash source record identities))))
|
|
857
|
+
(dolist (metadata cache-modules)
|
|
858
|
+
(let* ((source (alist-get 'source metadata))
|
|
859
|
+
(identity (and (stringp source)
|
|
860
|
+
(gethash source identities))))
|
|
861
|
+
(when identity
|
|
862
|
+
(puthash source (cons identity metadata) records)
|
|
863
|
+
(push source sources))))
|
|
864
|
+
(if (and (= (length identity-modules)
|
|
865
|
+
(hash-table-count identities))
|
|
866
|
+
(= (length cache-modules)
|
|
867
|
+
(hash-table-count records))
|
|
868
|
+
(= (hash-table-count identities)
|
|
869
|
+
(hash-table-count records)))
|
|
870
|
+
(eliscript-project-cache-lookup-create
|
|
871
|
+
:cache
|
|
872
|
+
(eliscript-project-cache-create
|
|
873
|
+
:records records
|
|
874
|
+
:sources (sort sources #'string-lessp)
|
|
875
|
+
:manifest (file-truename manifest-path)
|
|
876
|
+
:digest (alist-get 'digest manifest)
|
|
877
|
+
:source-version (alist-get 'version cache))
|
|
878
|
+
:reason "verified")
|
|
879
|
+
(eliscript-project--cache-miss
|
|
880
|
+
"cache-records-invalid"))))))
|
|
881
|
+
(error
|
|
882
|
+
(eliscript-project--cache-miss "manifest-unreadable")))))))
|
|
883
|
+
|
|
884
|
+
(defun eliscript-project--cache-decision
|
|
885
|
+
(source root out-dir cache
|
|
886
|
+
&optional expected-portable-entries expected-macro-dependencies)
|
|
887
|
+
"Return the cache decision for SOURCE.
|
|
888
|
+
|
|
889
|
+
EXPECTED-PORTABLE-ENTRIES is a sorted string list. The symbol `any' accepts
|
|
890
|
+
the entries recorded by CACHE for complete-graph reuse. Macro dependencies
|
|
891
|
+
must match their current project-relative paths and content digests."
|
|
892
|
+
(if (not cache)
|
|
893
|
+
(eliscript-project-cache-decision-create :reason "not-cached")
|
|
894
|
+
(condition-case nil
|
|
895
|
+
(let* ((relative (file-relative-name source root))
|
|
896
|
+
(pair
|
|
897
|
+
(gethash relative
|
|
898
|
+
(eliscript-project-cache-records cache)))
|
|
899
|
+
(identity (car pair))
|
|
900
|
+
(metadata (cdr pair))
|
|
901
|
+
(output
|
|
902
|
+
(eliscript-project--source-output source root out-dir))
|
|
903
|
+
(source-map (concat output ".map"))
|
|
904
|
+
(portable-entries
|
|
905
|
+
(alist-get 'portableEntries metadata))
|
|
906
|
+
(macro-dependency-records
|
|
907
|
+
(append (alist-get 'macroDependencies metadata) nil))
|
|
908
|
+
(expected-macro-records
|
|
909
|
+
(append
|
|
910
|
+
(eliscript-project--macro-dependency-records
|
|
911
|
+
expected-macro-dependencies root)
|
|
912
|
+
nil))
|
|
913
|
+
reason)
|
|
914
|
+
(setq reason
|
|
915
|
+
(cond
|
|
916
|
+
((not pair) "not-cached")
|
|
917
|
+
((not (equal (alist-get 'output identity)
|
|
918
|
+
(file-relative-name output out-dir)))
|
|
919
|
+
"output-path-changed")
|
|
920
|
+
((not (equal (alist-get 'sourceMap identity)
|
|
921
|
+
(file-relative-name source-map out-dir)))
|
|
922
|
+
"source-map-path-changed")
|
|
923
|
+
((not (or (eq expected-portable-entries 'any)
|
|
924
|
+
(equal portable-entries
|
|
925
|
+
expected-portable-entries)))
|
|
926
|
+
"portable-entries-changed")
|
|
927
|
+
((not (equal macro-dependency-records
|
|
928
|
+
expected-macro-records))
|
|
929
|
+
"macro-dependencies-changed")
|
|
930
|
+
((not (equal (alist-get 'sourceDigest identity)
|
|
931
|
+
(eliscript-project--file-digest source)))
|
|
932
|
+
"source-changed")
|
|
933
|
+
((not (file-regular-p output)) "output-missing")
|
|
934
|
+
((not (file-regular-p source-map)) "source-map-missing")
|
|
935
|
+
((not (equal (alist-get 'outputDigest identity)
|
|
936
|
+
(eliscript-project--file-digest output)))
|
|
937
|
+
"output-digest-changed")
|
|
938
|
+
((not (equal (alist-get 'sourceMapDigest identity)
|
|
939
|
+
(eliscript-project--file-digest source-map)))
|
|
940
|
+
"source-map-digest-changed")))
|
|
941
|
+
(if reason
|
|
942
|
+
(eliscript-project-cache-decision-create :reason reason)
|
|
943
|
+
(condition-case nil
|
|
944
|
+
(let ((dependencies
|
|
945
|
+
(mapcar
|
|
946
|
+
(lambda (dependency)
|
|
947
|
+
(eliscript-project--canonical-source
|
|
948
|
+
(expand-file-name dependency root)
|
|
949
|
+
root source nil))
|
|
950
|
+
(alist-get 'dependencies metadata))))
|
|
951
|
+
(eliscript-project-cache-decision-create
|
|
952
|
+
:module
|
|
953
|
+
(eliscript-project-module-create
|
|
954
|
+
:source source
|
|
955
|
+
:output output
|
|
956
|
+
:source-map source-map
|
|
957
|
+
:source-digest (alist-get 'sourceDigest identity)
|
|
958
|
+
:output-digest (alist-get 'outputDigest identity)
|
|
959
|
+
:source-map-digest (alist-get 'sourceMapDigest identity)
|
|
960
|
+
:dependencies dependencies
|
|
961
|
+
:macro-dependencies expected-macro-dependencies
|
|
962
|
+
:portable-entries portable-entries
|
|
963
|
+
:reused t
|
|
964
|
+
:reason "verified")
|
|
965
|
+
:reason "verified"))
|
|
966
|
+
(error
|
|
967
|
+
(eliscript-project-cache-decision-create
|
|
968
|
+
:reason "dependencies-invalid")))))
|
|
969
|
+
(error
|
|
970
|
+
(eliscript-project-cache-decision-create
|
|
971
|
+
:reason "artifact-unreadable")))))
|
|
972
|
+
|
|
973
|
+
(defun eliscript-project--cached-build-result
|
|
974
|
+
(root out-dir entries cache mode portable-entries macro-dependencies
|
|
975
|
+
started-at cache-read-ms)
|
|
976
|
+
"Return a fully reused result for ENTRIES from CACHE, or nil.
|
|
977
|
+
|
|
978
|
+
STARTED-AT and CACHE-READ-MS provide the complete build timing boundary."
|
|
979
|
+
(when (and cache
|
|
980
|
+
(= (eliscript-project-cache-source-version cache)
|
|
981
|
+
eliscript-project-cache-version))
|
|
982
|
+
(let (modules valid)
|
|
983
|
+
(setq valid t)
|
|
984
|
+
(dolist (relative (eliscript-project-cache-sources cache))
|
|
985
|
+
(let* ((source (expand-file-name relative root))
|
|
986
|
+
(decision
|
|
987
|
+
(and (file-regular-p source)
|
|
988
|
+
(eliscript-project--cache-decision
|
|
989
|
+
(file-truename source) root out-dir cache 'any
|
|
990
|
+
macro-dependencies)))
|
|
991
|
+
(module
|
|
992
|
+
(and decision
|
|
993
|
+
(eliscript-project-cache-decision-module decision))))
|
|
994
|
+
(if module
|
|
995
|
+
(push module modules)
|
|
996
|
+
(setq valid nil))))
|
|
997
|
+
(when (and valid
|
|
998
|
+
(cl-every
|
|
999
|
+
(lambda (entry)
|
|
1000
|
+
(cl-find entry modules
|
|
1001
|
+
:key #'eliscript-project-module-source
|
|
1002
|
+
:test #'equal))
|
|
1003
|
+
entries))
|
|
1004
|
+
(setq modules
|
|
1005
|
+
(sort modules
|
|
1006
|
+
(lambda (left right)
|
|
1007
|
+
(string-lessp
|
|
1008
|
+
(eliscript-project-module-source left)
|
|
1009
|
+
(eliscript-project-module-source right)))))
|
|
1010
|
+
(let* ((total-ms (eliscript-project--elapsed-ms started-at))
|
|
1011
|
+
(work-ms (max 0.0 (- total-ms cache-read-ms))))
|
|
1012
|
+
(eliscript-project-build-result-create
|
|
1013
|
+
:root root
|
|
1014
|
+
:out-dir out-dir
|
|
1015
|
+
:entry (and (= (length entries) 1) (car entries))
|
|
1016
|
+
:entry-output
|
|
1017
|
+
(and (= (length entries) 1)
|
|
1018
|
+
(eliscript-project--source-output (car entries) root out-dir))
|
|
1019
|
+
:entries entries
|
|
1020
|
+
:entry-outputs
|
|
1021
|
+
(mapcar
|
|
1022
|
+
(lambda (entry)
|
|
1023
|
+
(eliscript-project--source-output entry root out-dir))
|
|
1024
|
+
entries)
|
|
1025
|
+
:modules modules
|
|
1026
|
+
:manifest (eliscript-project-cache-manifest cache)
|
|
1027
|
+
:digest (eliscript-project-cache-digest cache)
|
|
1028
|
+
:compiled-count 0
|
|
1029
|
+
:reused-count (length modules)
|
|
1030
|
+
:mode mode
|
|
1031
|
+
:portable-entries portable-entries
|
|
1032
|
+
:cache-enabled t
|
|
1033
|
+
:cache-status "hit"
|
|
1034
|
+
:cache-reason "verified"
|
|
1035
|
+
:cache-read-ms cache-read-ms
|
|
1036
|
+
:work-ms work-ms
|
|
1037
|
+
:manifest-write-ms 0.0
|
|
1038
|
+
:total-ms total-ms))))))
|
|
1039
|
+
|
|
1040
|
+
(defun eliscript-project--write-module
|
|
1041
|
+
(program source source-text output-path dependencies macro-dependencies
|
|
1042
|
+
portable-entries reason)
|
|
1043
|
+
"Emit PROGRAM for SOURCE and write it to OUTPUT-PATH with a source map."
|
|
1044
|
+
(let* ((map-path (concat output-path ".map"))
|
|
1045
|
+
(map-directory (file-name-directory map-path))
|
|
1046
|
+
(generated-name (file-name-nondirectory output-path))
|
|
1047
|
+
(source-name (file-relative-name source map-directory))
|
|
1048
|
+
(emission
|
|
1049
|
+
(eliscript-emit-ir-module-with-source-map
|
|
1050
|
+
program source-text generated-name source-name))
|
|
1051
|
+
(javascript
|
|
1052
|
+
(concat (eliscript-emission-javascript emission)
|
|
1053
|
+
"//# sourceMappingURL="
|
|
1054
|
+
(file-name-nondirectory map-path)
|
|
1055
|
+
"\n")))
|
|
1056
|
+
(make-directory map-directory t)
|
|
1057
|
+
(with-temp-file map-path
|
|
1058
|
+
(insert (eliscript-emission-source-map emission)))
|
|
1059
|
+
(with-temp-file output-path
|
|
1060
|
+
(insert javascript))
|
|
1061
|
+
(eliscript-project-module-create
|
|
1062
|
+
:source source
|
|
1063
|
+
:output output-path
|
|
1064
|
+
:source-map map-path
|
|
1065
|
+
:source-digest (eliscript-project--file-digest source)
|
|
1066
|
+
:output-digest (eliscript-project--file-digest output-path)
|
|
1067
|
+
:source-map-digest (eliscript-project--file-digest map-path)
|
|
1068
|
+
:dependencies dependencies
|
|
1069
|
+
:macro-dependencies macro-dependencies
|
|
1070
|
+
:portable-entries portable-entries
|
|
1071
|
+
:reused nil
|
|
1072
|
+
:reason reason)))
|
|
1073
|
+
|
|
1074
|
+
(defun eliscript-project--manifest-module (module root out-dir)
|
|
1075
|
+
"Return the stable manifest record for MODULE below ROOT and OUT-DIR."
|
|
1076
|
+
`((source . ,(file-relative-name
|
|
1077
|
+
(eliscript-project-module-source module) root))
|
|
1078
|
+
(output . ,(file-relative-name
|
|
1079
|
+
(eliscript-project-module-output module) out-dir))
|
|
1080
|
+
(sourceMap . ,(file-relative-name
|
|
1081
|
+
(eliscript-project-module-source-map module) out-dir))
|
|
1082
|
+
(sourceDigest . ,(eliscript-project-module-source-digest module))
|
|
1083
|
+
(outputDigest . ,(eliscript-project-module-output-digest module))
|
|
1084
|
+
(sourceMapDigest
|
|
1085
|
+
. ,(eliscript-project-module-source-map-digest module))
|
|
1086
|
+
,@(when (eliscript-project-module-macro-dependencies module)
|
|
1087
|
+
`((macroDependencies
|
|
1088
|
+
. ,(eliscript-project--macro-dependency-records
|
|
1089
|
+
(eliscript-project-module-macro-dependencies module) root))))))
|
|
1090
|
+
|
|
1091
|
+
(defun eliscript-project--write-manifest
|
|
1092
|
+
(root out-dir entry-outputs modules mode portable-entries compiler-digest)
|
|
1093
|
+
"Write and return (PATH DIGEST) for the build rooted at ENTRY-OUTPUTS.
|
|
1094
|
+
|
|
1095
|
+
ROOT and OUT-DIR provide stable relative namespaces for MODULES."
|
|
1096
|
+
(let* ((records
|
|
1097
|
+
(vconcat
|
|
1098
|
+
(mapcar
|
|
1099
|
+
(lambda (module)
|
|
1100
|
+
(eliscript-project--manifest-module module root out-dir))
|
|
1101
|
+
modules)))
|
|
1102
|
+
(relative-entries
|
|
1103
|
+
(mapcar
|
|
1104
|
+
(lambda (entry-output)
|
|
1105
|
+
(file-relative-name entry-output out-dir))
|
|
1106
|
+
entry-outputs))
|
|
1107
|
+
(identity
|
|
1108
|
+
(if (= (length relative-entries) 1)
|
|
1109
|
+
`((format . "eliscript-project")
|
|
1110
|
+
(version . 1)
|
|
1111
|
+
(entry . ,(car relative-entries))
|
|
1112
|
+
(modules . ,records))
|
|
1113
|
+
`((format . "eliscript-project")
|
|
1114
|
+
(version . 2)
|
|
1115
|
+
(entries . ,(vconcat relative-entries))
|
|
1116
|
+
(modules . ,records))))
|
|
1117
|
+
(digest (eliscript-project--json-digest identity))
|
|
1118
|
+
(manifest-path
|
|
1119
|
+
(expand-file-name eliscript-project-manifest-filename out-dir))
|
|
1120
|
+
(cache-identity
|
|
1121
|
+
`((format . ,eliscript-project-cache-format)
|
|
1122
|
+
(version . ,eliscript-project-cache-version)
|
|
1123
|
+
(compilerDigest . ,compiler-digest)
|
|
1124
|
+
(mode . ,mode)
|
|
1125
|
+
(portableEntries . ,(vconcat portable-entries))
|
|
1126
|
+
(modules
|
|
1127
|
+
. ,(vconcat
|
|
1128
|
+
(mapcar
|
|
1129
|
+
(lambda (module)
|
|
1130
|
+
(eliscript-project--cache-module module root))
|
|
1131
|
+
modules)))))
|
|
1132
|
+
(cache
|
|
1133
|
+
(append
|
|
1134
|
+
cache-identity
|
|
1135
|
+
`((digest . ,(eliscript-project--json-digest cache-identity))))))
|
|
1136
|
+
(make-directory out-dir t)
|
|
1137
|
+
(with-temp-file manifest-path
|
|
1138
|
+
(insert
|
|
1139
|
+
(json-serialize
|
|
1140
|
+
(append identity `((digest . ,digest) (cache . ,cache))))
|
|
1141
|
+
"\n"))
|
|
1142
|
+
(list (file-truename manifest-path) digest)))
|
|
1143
|
+
|
|
1144
|
+
(defun eliscript-project--build-result
|
|
1145
|
+
(root out-dir entries modules mode portable-entries compiler-digest
|
|
1146
|
+
cache-lookup started-at cache-read-ms)
|
|
1147
|
+
"Create a complete project build result for ENTRIES and MODULES.
|
|
1148
|
+
|
|
1149
|
+
STARTED-AT and CACHE-READ-MS provide the complete build timing boundary."
|
|
1150
|
+
(let* ((entry-outputs
|
|
1151
|
+
(mapcar
|
|
1152
|
+
(lambda (entry)
|
|
1153
|
+
(eliscript-project--source-output entry root out-dir))
|
|
1154
|
+
entries))
|
|
1155
|
+
(manifest-started-at (float-time))
|
|
1156
|
+
(manifest-data
|
|
1157
|
+
(eliscript-project--write-manifest
|
|
1158
|
+
root out-dir entry-outputs modules mode portable-entries
|
|
1159
|
+
compiler-digest))
|
|
1160
|
+
(manifest-write-ms
|
|
1161
|
+
(eliscript-project--elapsed-ms manifest-started-at))
|
|
1162
|
+
(total-ms (eliscript-project--elapsed-ms started-at))
|
|
1163
|
+
(work-ms
|
|
1164
|
+
(max 0.0 (- total-ms cache-read-ms manifest-write-ms)))
|
|
1165
|
+
(compiled-count
|
|
1166
|
+
(cl-count-if-not #'eliscript-project-module-reused modules))
|
|
1167
|
+
(reused-count
|
|
1168
|
+
(cl-count-if #'eliscript-project-module-reused modules))
|
|
1169
|
+
(cache (eliscript-project-cache-lookup-cache cache-lookup))
|
|
1170
|
+
(lookup-reason
|
|
1171
|
+
(eliscript-project-cache-lookup-reason cache-lookup))
|
|
1172
|
+
(cache-enabled (not (equal lookup-reason "cache-disabled")))
|
|
1173
|
+
(cache-status
|
|
1174
|
+
(cond
|
|
1175
|
+
((not cache-enabled) "disabled")
|
|
1176
|
+
((not cache) "miss")
|
|
1177
|
+
((= reused-count (length modules)) "hit")
|
|
1178
|
+
((> reused-count 0) "partial")
|
|
1179
|
+
(t "miss")))
|
|
1180
|
+
(cache-reason
|
|
1181
|
+
(cond
|
|
1182
|
+
((not cache) lookup-reason)
|
|
1183
|
+
((equal cache-status "hit") "verified")
|
|
1184
|
+
((equal cache-status "partial") "dirty-modules")
|
|
1185
|
+
(t "all-modules-dirty"))))
|
|
1186
|
+
(eliscript-project-build-result-create
|
|
1187
|
+
:root root
|
|
1188
|
+
:out-dir out-dir
|
|
1189
|
+
:entry (and (= (length entries) 1) (car entries))
|
|
1190
|
+
:entry-output (and (= (length entries) 1) (car entry-outputs))
|
|
1191
|
+
:entries entries
|
|
1192
|
+
:entry-outputs entry-outputs
|
|
1193
|
+
:modules modules
|
|
1194
|
+
:manifest (car manifest-data)
|
|
1195
|
+
:digest (cadr manifest-data)
|
|
1196
|
+
:compiled-count compiled-count
|
|
1197
|
+
:reused-count reused-count
|
|
1198
|
+
:mode mode
|
|
1199
|
+
:portable-entries portable-entries
|
|
1200
|
+
:cache-enabled cache-enabled
|
|
1201
|
+
:cache-status cache-status
|
|
1202
|
+
:cache-reason cache-reason
|
|
1203
|
+
:cache-read-ms cache-read-ms
|
|
1204
|
+
:work-ms work-ms
|
|
1205
|
+
:manifest-write-ms manifest-write-ms
|
|
1206
|
+
:total-ms total-ms)))
|
|
1207
|
+
|
|
1208
|
+
(defun eliscript-project-build-report (result)
|
|
1209
|
+
"Return a stable JSON-compatible report for project build RESULT."
|
|
1210
|
+
(unless (eliscript-project-build-result-p result)
|
|
1211
|
+
(signal 'wrong-type-argument
|
|
1212
|
+
(list 'eliscript-project-build-result-p result)))
|
|
1213
|
+
(let* ((root (eliscript-project-build-result-root result))
|
|
1214
|
+
(out-dir (eliscript-project-build-result-out-dir result))
|
|
1215
|
+
(entries (eliscript-project-build-result-entries result))
|
|
1216
|
+
(entry-outputs (eliscript-project-build-result-entry-outputs result))
|
|
1217
|
+
(multi (> (length entries) 1)))
|
|
1218
|
+
`((format . "eliscript-build-report")
|
|
1219
|
+
(version
|
|
1220
|
+
. ,(if multi
|
|
1221
|
+
eliscript-project-build-report-multi-version
|
|
1222
|
+
eliscript-project-build-report-version))
|
|
1223
|
+
(mode . ,(eliscript-project-build-result-mode result))
|
|
1224
|
+
(root . ,(directory-file-name root))
|
|
1225
|
+
(outDir . ,(directory-file-name out-dir))
|
|
1226
|
+
,@(if multi
|
|
1227
|
+
`((entries
|
|
1228
|
+
. ,(vconcat
|
|
1229
|
+
(mapcar (lambda (entry)
|
|
1230
|
+
(file-relative-name entry root))
|
|
1231
|
+
entries)))
|
|
1232
|
+
(entryOutputs
|
|
1233
|
+
. ,(vconcat
|
|
1234
|
+
(mapcar (lambda (entry-output)
|
|
1235
|
+
(file-relative-name entry-output out-dir))
|
|
1236
|
+
entry-outputs))))
|
|
1237
|
+
`((entry
|
|
1238
|
+
. ,(file-relative-name
|
|
1239
|
+
(eliscript-project-build-result-entry result) root))
|
|
1240
|
+
(entryOutput
|
|
1241
|
+
. ,(file-relative-name
|
|
1242
|
+
(eliscript-project-build-result-entry-output result)
|
|
1243
|
+
out-dir))))
|
|
1244
|
+
(manifest
|
|
1245
|
+
. ,(file-relative-name
|
|
1246
|
+
(eliscript-project-build-result-manifest result) out-dir))
|
|
1247
|
+
(digest . ,(eliscript-project-build-result-digest result))
|
|
1248
|
+
(portableEntries
|
|
1249
|
+
. ,(vconcat
|
|
1250
|
+
(or (eliscript-project-build-result-portable-entries result) nil)))
|
|
1251
|
+
(cache
|
|
1252
|
+
. ((enabled
|
|
1253
|
+
. ,(if (eliscript-project-build-result-cache-enabled result)
|
|
1254
|
+
t :false))
|
|
1255
|
+
(status . ,(eliscript-project-build-result-cache-status result))
|
|
1256
|
+
(reason . ,(eliscript-project-build-result-cache-reason result))))
|
|
1257
|
+
(counts
|
|
1258
|
+
. ((modules
|
|
1259
|
+
. ,(length (eliscript-project-build-result-modules result)))
|
|
1260
|
+
(compiled . ,(eliscript-project-build-result-compiled-count result))
|
|
1261
|
+
(reused . ,(eliscript-project-build-result-reused-count result))))
|
|
1262
|
+
(timings
|
|
1263
|
+
. ((cacheReadMs
|
|
1264
|
+
. ,(eliscript-project--report-ms
|
|
1265
|
+
(eliscript-project-build-result-cache-read-ms result)))
|
|
1266
|
+
(workMs
|
|
1267
|
+
. ,(eliscript-project--report-ms
|
|
1268
|
+
(eliscript-project-build-result-work-ms result)))
|
|
1269
|
+
(manifestWriteMs
|
|
1270
|
+
. ,(eliscript-project--report-ms
|
|
1271
|
+
(eliscript-project-build-result-manifest-write-ms result)))
|
|
1272
|
+
(totalMs
|
|
1273
|
+
. ,(eliscript-project--report-ms
|
|
1274
|
+
(eliscript-project-build-result-total-ms result)))))
|
|
1275
|
+
(modules
|
|
1276
|
+
. ,(vconcat
|
|
1277
|
+
(mapcar
|
|
1278
|
+
(lambda (module)
|
|
1279
|
+
`((source
|
|
1280
|
+
. ,(file-relative-name
|
|
1281
|
+
(eliscript-project-module-source module) root))
|
|
1282
|
+
(output
|
|
1283
|
+
. ,(file-relative-name
|
|
1284
|
+
(eliscript-project-module-output module) out-dir))
|
|
1285
|
+
(sourceMap
|
|
1286
|
+
. ,(file-relative-name
|
|
1287
|
+
(eliscript-project-module-source-map module) out-dir))
|
|
1288
|
+
(status
|
|
1289
|
+
. ,(if (eliscript-project-module-reused module)
|
|
1290
|
+
"reused" "compiled"))
|
|
1291
|
+
(reason . ,(eliscript-project-module-reason module))
|
|
1292
|
+
(dependencies
|
|
1293
|
+
. ,(vconcat
|
|
1294
|
+
(mapcar
|
|
1295
|
+
(lambda (dependency)
|
|
1296
|
+
(file-relative-name dependency root))
|
|
1297
|
+
(or (eliscript-project-module-dependencies module)
|
|
1298
|
+
nil))))
|
|
1299
|
+
,@(when (eliscript-project-module-macro-dependencies module)
|
|
1300
|
+
`((macroDependencies
|
|
1301
|
+
. ,(eliscript-project--macro-dependency-records
|
|
1302
|
+
(eliscript-project-module-macro-dependencies module)
|
|
1303
|
+
root))))
|
|
1304
|
+
(portableEntries
|
|
1305
|
+
. ,(vconcat
|
|
1306
|
+
(or (eliscript-project-module-portable-entries module)
|
|
1307
|
+
nil)))))
|
|
1308
|
+
(eliscript-project-build-result-modules result)))))))
|
|
1309
|
+
|
|
1310
|
+
(defun eliscript-project-build (entry out-dir &optional root)
|
|
1311
|
+
"Compile the local Eliscript graph rooted at ENTRY into OUT-DIR."
|
|
1312
|
+
(eliscript-project--build-many (list entry) out-dir root))
|
|
1313
|
+
|
|
1314
|
+
(defun eliscript-project--build-many
|
|
1315
|
+
(entries out-dir &optional root macro-capabilities macro-file-dependencies)
|
|
1316
|
+
"Compile local Eliscript graphs rooted at ENTRIES into OUT-DIR.
|
|
1317
|
+
|
|
1318
|
+
ROOT defaults to the only entry's directory. Relative `.eli' imports are
|
|
1319
|
+
recursively compiled, remain within ROOT, preserve their source directory
|
|
1320
|
+
structure, and are rewritten to `.mjs'. Other import specifiers remain
|
|
1321
|
+
unchanged."
|
|
1322
|
+
(unless (and entries
|
|
1323
|
+
(cl-every
|
|
1324
|
+
(lambda (entry)
|
|
1325
|
+
(and (stringp entry) (not (string-empty-p entry))))
|
|
1326
|
+
entries))
|
|
1327
|
+
(eliscript-project--fail nil nil "project entries are invalid"))
|
|
1328
|
+
(when (and (> (length entries) 1) (null root))
|
|
1329
|
+
(eliscript-project--fail
|
|
1330
|
+
(car entries) nil
|
|
1331
|
+
"multi-entry project builds require an explicit project root"))
|
|
1332
|
+
(let* ((started-at (float-time))
|
|
1333
|
+
(entry-paths (mapcar #'expand-file-name entries))
|
|
1334
|
+
(root-path
|
|
1335
|
+
(eliscript-project--canonical-directory
|
|
1336
|
+
(or root (file-name-directory (car entry-paths))) "project root"))
|
|
1337
|
+
(canonical-entries
|
|
1338
|
+
(sort
|
|
1339
|
+
(mapcar
|
|
1340
|
+
(lambda (entry-path)
|
|
1341
|
+
(eliscript-project--canonical-source
|
|
1342
|
+
entry-path root-path entry-path nil))
|
|
1343
|
+
entry-paths)
|
|
1344
|
+
#'string-lessp))
|
|
1345
|
+
(macro-dependencies
|
|
1346
|
+
(eliscript-project--macro-dependencies
|
|
1347
|
+
macro-file-dependencies root-path (car canonical-entries)))
|
|
1348
|
+
(macro-context
|
|
1349
|
+
(eliscript-project--macro-context
|
|
1350
|
+
macro-capabilities macro-dependencies))
|
|
1351
|
+
(resolved-out-dir (file-truename (expand-file-name out-dir)))
|
|
1352
|
+
(output-directory
|
|
1353
|
+
(file-name-as-directory resolved-out-dir))
|
|
1354
|
+
(compiler-digest (eliscript-project--compiler-digest))
|
|
1355
|
+
(entry-outputs
|
|
1356
|
+
(mapcar
|
|
1357
|
+
(lambda (entry)
|
|
1358
|
+
(eliscript-project--source-output
|
|
1359
|
+
entry root-path output-directory))
|
|
1360
|
+
canonical-entries))
|
|
1361
|
+
(cache-started-at (float-time))
|
|
1362
|
+
(cache-lookup
|
|
1363
|
+
(eliscript-project--read-cache
|
|
1364
|
+
output-directory entry-outputs "standard" nil
|
|
1365
|
+
compiler-digest))
|
|
1366
|
+
(cache-read-ms
|
|
1367
|
+
(eliscript-project--elapsed-ms cache-started-at))
|
|
1368
|
+
(cache (eliscript-project-cache-lookup-cache cache-lookup))
|
|
1369
|
+
(states (make-hash-table :test #'equal))
|
|
1370
|
+
pending-writes
|
|
1371
|
+
modules)
|
|
1372
|
+
(unless (= (length canonical-entries)
|
|
1373
|
+
(length (delete-dups (copy-sequence canonical-entries))))
|
|
1374
|
+
(eliscript-project--fail
|
|
1375
|
+
(car canonical-entries) nil
|
|
1376
|
+
"project entries resolve to duplicate sources"))
|
|
1377
|
+
(dolist (entry canonical-entries)
|
|
1378
|
+
(unless (string-suffix-p ".eli" entry)
|
|
1379
|
+
(eliscript-project--fail
|
|
1380
|
+
entry nil "entry file must use the .eli extension")))
|
|
1381
|
+
(when (file-exists-p resolved-out-dir)
|
|
1382
|
+
(unless (file-directory-p resolved-out-dir)
|
|
1383
|
+
(eliscript-project--fail
|
|
1384
|
+
resolved-out-dir nil "output path is not a directory")))
|
|
1385
|
+
(cl-labels
|
|
1386
|
+
((visit
|
|
1387
|
+
(source)
|
|
1388
|
+
(pcase (gethash source states)
|
|
1389
|
+
('done nil)
|
|
1390
|
+
('visiting nil)
|
|
1391
|
+
(_
|
|
1392
|
+
(puthash source 'visiting states)
|
|
1393
|
+
(let* ((output-path
|
|
1394
|
+
(eliscript-project--source-output
|
|
1395
|
+
source root-path output-directory))
|
|
1396
|
+
(decision
|
|
1397
|
+
(eliscript-project--cache-decision
|
|
1398
|
+
source root-path output-directory cache nil
|
|
1399
|
+
macro-dependencies))
|
|
1400
|
+
(cached
|
|
1401
|
+
(eliscript-project-cache-decision-module decision)))
|
|
1402
|
+
(if cached
|
|
1403
|
+
(progn
|
|
1404
|
+
(dolist (dependency
|
|
1405
|
+
(eliscript-project-module-dependencies cached))
|
|
1406
|
+
(visit dependency))
|
|
1407
|
+
(push cached modules))
|
|
1408
|
+
(let* ((source-text
|
|
1409
|
+
(eliscript-project--read-source source))
|
|
1410
|
+
(program
|
|
1411
|
+
(eliscript-compile-ir-string
|
|
1412
|
+
source-text source macro-context))
|
|
1413
|
+
dependencies)
|
|
1414
|
+
(eliscript-ir-walk
|
|
1415
|
+
program
|
|
1416
|
+
(lambda (node)
|
|
1417
|
+
(when (eq (eliscript-ir-node-kind node)
|
|
1418
|
+
'import-declaration)
|
|
1419
|
+
(let ((specifier (eliscript-ir-node-value node)))
|
|
1420
|
+
(cond
|
|
1421
|
+
((eliscript-project--local-import-p specifier)
|
|
1422
|
+
(let* ((candidate
|
|
1423
|
+
(expand-file-name
|
|
1424
|
+
specifier
|
|
1425
|
+
(file-name-directory source)))
|
|
1426
|
+
(dependency
|
|
1427
|
+
(eliscript-project--canonical-source
|
|
1428
|
+
candidate root-path source
|
|
1429
|
+
(eliscript-ir-node-span node)))
|
|
1430
|
+
(dependency-output
|
|
1431
|
+
(eliscript-project--source-output
|
|
1432
|
+
dependency root-path output-directory)))
|
|
1433
|
+
(push dependency dependencies)
|
|
1434
|
+
(setf (eliscript-ir-node-value node)
|
|
1435
|
+
(eliscript-project--relative-import
|
|
1436
|
+
dependency-output output-path))))
|
|
1437
|
+
((string-suffix-p ".eli" specifier)
|
|
1438
|
+
(eliscript-project--fail
|
|
1439
|
+
source (eliscript-ir-node-span node)
|
|
1440
|
+
"Eliscript source import must be relative: %s"
|
|
1441
|
+
specifier)))))))
|
|
1442
|
+
(setq dependencies
|
|
1443
|
+
(sort (delete-dups dependencies) #'string-lessp))
|
|
1444
|
+
(dolist (dependency dependencies)
|
|
1445
|
+
(visit dependency))
|
|
1446
|
+
(push
|
|
1447
|
+
(list
|
|
1448
|
+
program source source-text output-path dependencies
|
|
1449
|
+
macro-dependencies nil
|
|
1450
|
+
(if cache
|
|
1451
|
+
(eliscript-project-cache-decision-reason decision)
|
|
1452
|
+
(eliscript-project-cache-lookup-reason cache-lookup)))
|
|
1453
|
+
pending-writes)))
|
|
1454
|
+
(puthash source 'done states))))))
|
|
1455
|
+
(dolist (entry canonical-entries)
|
|
1456
|
+
(visit entry)))
|
|
1457
|
+
(let (sources)
|
|
1458
|
+
(maphash (lambda (source _state) (push source sources)) states)
|
|
1459
|
+
(eliscript-project--validate-output-isolation
|
|
1460
|
+
sources macro-dependencies root-path output-directory))
|
|
1461
|
+
(dolist (pending (nreverse pending-writes))
|
|
1462
|
+
(push (apply #'eliscript-project--write-module pending) modules))
|
|
1463
|
+
(setq modules
|
|
1464
|
+
(sort modules
|
|
1465
|
+
(lambda (left right)
|
|
1466
|
+
(string-lessp
|
|
1467
|
+
(eliscript-project-module-source left)
|
|
1468
|
+
(eliscript-project-module-source right)))))
|
|
1469
|
+
(eliscript-project--build-result
|
|
1470
|
+
root-path output-directory canonical-entries modules "standard" nil
|
|
1471
|
+
compiler-digest cache-lookup started-at cache-read-ms)))
|
|
1472
|
+
|
|
1473
|
+
(defun eliscript-project--portable-imports (forms)
|
|
1474
|
+
"Return portable import descriptions from selected FORMS.
|
|
1475
|
+
|
|
1476
|
+
Each description has the shape (SPECIFIER NAMES SPAN)."
|
|
1477
|
+
(let (imports)
|
|
1478
|
+
(dolist (form forms)
|
|
1479
|
+
(let ((value (eliscript-form-value form)))
|
|
1480
|
+
(when (and (consp value)
|
|
1481
|
+
(eq (eliscript-form-value (car value)) 'import-portable))
|
|
1482
|
+
(push
|
|
1483
|
+
(list
|
|
1484
|
+
(eliscript-form-value (cadr value))
|
|
1485
|
+
(eliscript-portable--import-names (cdr value))
|
|
1486
|
+
(eliscript-form-span form))
|
|
1487
|
+
imports))))
|
|
1488
|
+
(nreverse imports)))
|
|
1489
|
+
|
|
1490
|
+
(defun eliscript-project-build-portable
|
|
1491
|
+
(entry entries out-dir
|
|
1492
|
+
&optional root macro-capabilities macro-file-dependencies)
|
|
1493
|
+
"Compile portable ENTRIES and their local module graph from ENTRY.
|
|
1494
|
+
|
|
1495
|
+
Every `import-portable' edge must name a relative `.eli' module below ROOT.
|
|
1496
|
+
The target binding must resolve to `defportable'; each generated module contains
|
|
1497
|
+
only the requested declarations, immutable constants, and portable imports."
|
|
1498
|
+
(unless entries
|
|
1499
|
+
(eliscript-project--fail entry nil "portable build requires an entry name"))
|
|
1500
|
+
(let* ((started-at (float-time))
|
|
1501
|
+
(entry-path (expand-file-name entry))
|
|
1502
|
+
(root-path
|
|
1503
|
+
(eliscript-project--canonical-directory
|
|
1504
|
+
(or root (file-name-directory entry-path)) "project root"))
|
|
1505
|
+
(canonical-entry
|
|
1506
|
+
(eliscript-project--canonical-source
|
|
1507
|
+
entry-path root-path entry-path nil))
|
|
1508
|
+
(macro-dependencies
|
|
1509
|
+
(eliscript-project--macro-dependencies
|
|
1510
|
+
macro-file-dependencies root-path canonical-entry))
|
|
1511
|
+
(macro-context
|
|
1512
|
+
(eliscript-project--macro-context
|
|
1513
|
+
macro-capabilities macro-dependencies))
|
|
1514
|
+
(resolved-out-dir (file-truename (expand-file-name out-dir)))
|
|
1515
|
+
(output-directory (file-name-as-directory resolved-out-dir))
|
|
1516
|
+
(portable-entry-names
|
|
1517
|
+
(eliscript-project--portable-entry-names entries))
|
|
1518
|
+
(compiler-digest (eliscript-project--compiler-digest))
|
|
1519
|
+
(entry-output
|
|
1520
|
+
(eliscript-project--source-output
|
|
1521
|
+
canonical-entry root-path output-directory))
|
|
1522
|
+
(cache-started-at (float-time))
|
|
1523
|
+
(cache-lookup
|
|
1524
|
+
(eliscript-project--read-cache
|
|
1525
|
+
output-directory (list entry-output) "portable"
|
|
1526
|
+
portable-entry-names compiler-digest))
|
|
1527
|
+
(cache-read-ms
|
|
1528
|
+
(eliscript-project--elapsed-ms cache-started-at))
|
|
1529
|
+
(cache (eliscript-project-cache-lookup-cache cache-lookup))
|
|
1530
|
+
(cached-result
|
|
1531
|
+
(eliscript-project--cached-build-result
|
|
1532
|
+
root-path output-directory (list canonical-entry) cache
|
|
1533
|
+
"portable" portable-entry-names macro-dependencies
|
|
1534
|
+
started-at cache-read-ms))
|
|
1535
|
+
(forms-by-source (make-hash-table :test #'equal))
|
|
1536
|
+
(texts-by-source (make-hash-table :test #'equal))
|
|
1537
|
+
(requests (make-hash-table :test #'equal))
|
|
1538
|
+
queue
|
|
1539
|
+
modules)
|
|
1540
|
+
(unless (string-suffix-p ".eli" canonical-entry)
|
|
1541
|
+
(eliscript-project--fail
|
|
1542
|
+
canonical-entry nil "entry file must use the .eli extension"))
|
|
1543
|
+
(when (file-exists-p resolved-out-dir)
|
|
1544
|
+
(unless (file-directory-p resolved-out-dir)
|
|
1545
|
+
(eliscript-project--fail
|
|
1546
|
+
resolved-out-dir nil "output path is not a directory")))
|
|
1547
|
+
(or
|
|
1548
|
+
cached-result
|
|
1549
|
+
(progn
|
|
1550
|
+
(cl-labels
|
|
1551
|
+
((load-forms
|
|
1552
|
+
(source)
|
|
1553
|
+
(or (gethash source forms-by-source)
|
|
1554
|
+
(let* ((text (eliscript-project--read-source source))
|
|
1555
|
+
(forms
|
|
1556
|
+
(eliscript--analyzed-string
|
|
1557
|
+
text source macro-context)))
|
|
1558
|
+
(puthash source text texts-by-source)
|
|
1559
|
+
(puthash source forms forms-by-source)
|
|
1560
|
+
forms)))
|
|
1561
|
+
(enqueue
|
|
1562
|
+
(source name)
|
|
1563
|
+
(push (cons source (if (symbolp name) name (intern name))) queue))
|
|
1564
|
+
(resolve-import
|
|
1565
|
+
(source specifier span)
|
|
1566
|
+
(unless (eliscript-project--local-import-p specifier)
|
|
1567
|
+
(eliscript-project--fail
|
|
1568
|
+
source span
|
|
1569
|
+
"portable import must be a relative .eli module: %s"
|
|
1570
|
+
specifier))
|
|
1571
|
+
(eliscript-project--canonical-source
|
|
1572
|
+
(expand-file-name specifier (file-name-directory source))
|
|
1573
|
+
root-path source span)))
|
|
1574
|
+
(dolist (name entries) (enqueue canonical-entry name))
|
|
1575
|
+
(while queue
|
|
1576
|
+
(pcase-let*
|
|
1577
|
+
((`(,source . ,name) (pop queue))
|
|
1578
|
+
(source-requests
|
|
1579
|
+
(or (gethash source requests)
|
|
1580
|
+
(let ((table (make-hash-table :test #'eq)))
|
|
1581
|
+
(puthash source table requests)
|
|
1582
|
+
table))))
|
|
1583
|
+
(unless (gethash name source-requests)
|
|
1584
|
+
(puthash name t source-requests)
|
|
1585
|
+
(let* ((forms (load-forms source))
|
|
1586
|
+
(selected
|
|
1587
|
+
(eliscript-portable-select-module
|
|
1588
|
+
forms
|
|
1589
|
+
(let (names)
|
|
1590
|
+
(maphash
|
|
1591
|
+
(lambda (requested _present)
|
|
1592
|
+
(push requested names))
|
|
1593
|
+
source-requests)
|
|
1594
|
+
(sort names
|
|
1595
|
+
(lambda (left right)
|
|
1596
|
+
(string-lessp
|
|
1597
|
+
(symbol-name left) (symbol-name right)))))
|
|
1598
|
+
source t)))
|
|
1599
|
+
(dolist (import
|
|
1600
|
+
(eliscript-project--portable-imports selected))
|
|
1601
|
+
(let ((dependency
|
|
1602
|
+
(resolve-import
|
|
1603
|
+
source (nth 0 import) (nth 2 import))))
|
|
1604
|
+
(dolist (imported-name (nth 1 import))
|
|
1605
|
+
(enqueue dependency imported-name))))))))
|
|
1606
|
+
(let (sources)
|
|
1607
|
+
(maphash (lambda (source _names) (push source sources)) requests)
|
|
1608
|
+
(eliscript-project--validate-output-isolation
|
|
1609
|
+
sources macro-dependencies root-path output-directory)
|
|
1610
|
+
(dolist (source (sort sources #'string-lessp))
|
|
1611
|
+
(let* ((source-requests (gethash source requests))
|
|
1612
|
+
names
|
|
1613
|
+
(forms (load-forms source))
|
|
1614
|
+
(output-path
|
|
1615
|
+
(eliscript-project--source-output
|
|
1616
|
+
source root-path output-directory)))
|
|
1617
|
+
(maphash (lambda (name _present) (push name names)) source-requests)
|
|
1618
|
+
(setq names
|
|
1619
|
+
(sort names
|
|
1620
|
+
(lambda (left right)
|
|
1621
|
+
(string-lessp
|
|
1622
|
+
(symbol-name left) (symbol-name right)))))
|
|
1623
|
+
(let* ((selected
|
|
1624
|
+
(eliscript-portable-select-module forms names source t))
|
|
1625
|
+
(dependencies
|
|
1626
|
+
(sort
|
|
1627
|
+
(delete-dups
|
|
1628
|
+
(mapcar
|
|
1629
|
+
(lambda (import)
|
|
1630
|
+
(resolve-import
|
|
1631
|
+
source (nth 0 import) (nth 2 import)))
|
|
1632
|
+
(eliscript-project--portable-imports selected)))
|
|
1633
|
+
#'string-lessp))
|
|
1634
|
+
(entry-names
|
|
1635
|
+
(mapcar #'symbol-name names))
|
|
1636
|
+
(decision
|
|
1637
|
+
(eliscript-project--cache-decision
|
|
1638
|
+
source root-path output-directory cache entry-names
|
|
1639
|
+
macro-dependencies))
|
|
1640
|
+
(cached
|
|
1641
|
+
(eliscript-project-cache-decision-module decision)))
|
|
1642
|
+
(if cached
|
|
1643
|
+
(push cached modules)
|
|
1644
|
+
(let ((program (eliscript-lower-module selected source)))
|
|
1645
|
+
(eliscript-ir-walk
|
|
1646
|
+
program
|
|
1647
|
+
(lambda (node)
|
|
1648
|
+
(when (eq (eliscript-ir-node-kind node)
|
|
1649
|
+
'import-declaration)
|
|
1650
|
+
(let* ((specifier (eliscript-ir-node-value node))
|
|
1651
|
+
(dependency
|
|
1652
|
+
(resolve-import
|
|
1653
|
+
source specifier
|
|
1654
|
+
(eliscript-ir-node-span node)))
|
|
1655
|
+
(dependency-output
|
|
1656
|
+
(eliscript-project--source-output
|
|
1657
|
+
dependency root-path output-directory)))
|
|
1658
|
+
(setf (eliscript-ir-node-value node)
|
|
1659
|
+
(eliscript-project--relative-import
|
|
1660
|
+
dependency-output output-path))))))
|
|
1661
|
+
(push
|
|
1662
|
+
(eliscript-project--write-module
|
|
1663
|
+
program source (gethash source texts-by-source)
|
|
1664
|
+
output-path dependencies macro-dependencies entry-names
|
|
1665
|
+
(if cache
|
|
1666
|
+
(eliscript-project-cache-decision-reason decision)
|
|
1667
|
+
(eliscript-project-cache-lookup-reason cache-lookup)))
|
|
1668
|
+
modules)))))))
|
|
1669
|
+
(eliscript-project--build-result
|
|
1670
|
+
root-path output-directory (list canonical-entry) (nreverse modules)
|
|
1671
|
+
"portable" portable-entry-names compiler-digest
|
|
1672
|
+
cache-lookup started-at cache-read-ms))))))
|
|
1673
|
+
|
|
1674
|
+
(provide 'eliscript-project)
|
|
1675
|
+
|
|
1676
|
+
;;; eliscript-project.el ends here
|