-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy patheldev.el
6986 lines (6108 loc) · 365 KB
/
eldev.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; eldev.el --- Elisp development tool -*- lexical-binding: t -*-
;;; Copyright (C) 2019-2024 Paul Pogonyshev
;; Author: Paul Pogonyshev <[email protected]>
;; Maintainer: Paul Pogonyshev <[email protected]>
;; Version: 1.11.1snapshot
;; Keywords: maint, tools
;; Homepage: https://github.com/emacs-eldev/eldev
;; Package-Requires: ((emacs "24.4"))
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of
;; the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see https://www.gnu.org/licenses.
;;; Commentary:
;; Eldev (Elisp development tool) is an Emacs-based build system,
;; targeted solely at Elisp projects. It is an alternative to Cask.
;; Unlike Cask, Eldev itself is fully written in Elisp and its
;; configuration files are also Elisp programs. If you are familiar
;; with Java world, Cask can be seen as a parallel to Maven — it uses
;; project description, while Eldev is sort of a parallel to Gradle —
;; its configuration is a program on its own.
;; Eldev is a command-line utility that runs Emacs in batch mode.
;; Therefore, you should not (or at least need not) install it in your
;; Emacs. Instead, use one of the following ways.
;; If you have a catch-all directory for executables.
;;
;; 1. From this directory (e.g. `~/bin') execute:
;;
;; $ curl -fsSL https://raw.github.com/emacs-eldev/eldev/master/bin/eldev > eldev && chmod a+x eldev
;;
;; No further steps necessary — Eldev will bootstrap itself as needed
;; on first invocation.
;; If you don't have such a directory and don't care where `eldev'
;; executable is placed.
;;
;; 1. Run:
;;
;; $ curl -fsSL https://raw.github.com/emacs-eldev/eldev/master/webinstall/eldev | sh
;;
;; This will install eldev script to ~/.local/bin.
;;
;; 2. If not yet there, add the directory to your $PATH; e.g. in ~/.profile add this:
;;
;; export PATH="$HOME/.local/bin:$PATH"
;;
;; Afterwards Eldev will bootstrap itself as needed on first
;; invocation.
;; For further help and more ways to install, please see the homepage:
;;
;; https://github.com/emacs-eldev/eldev
;;; Code:
(require 'eldev-util)
;; To silence byte-compilation warnings on Emacs 24-25.
(defvar inhibit-message)
(defvar package-archive-priorities)
;; Using `autoload' function directly instead of ;;;###autoload cookies since the latter
;; won't work with ELDEV_LOCAL. This must be at the top _and_ in `eval-and-compile', else
;; byte-compilation gives warnings...
(eval-and-compile
(dolist (autoloads '(("eldev-build" eldev-build-find-targets eldev-get-target-dependencies eldev-set-target-dependencies eldev-build-target-status eldev-build-target)
("eldev-plugins" eldev-active-plugins eldev-use-plugin
;; Maintainer plugin is often configured in Eldev even if not activated there.
eldev-release-next-major-version eldev-release-next-minor-version eldev-release-next-patch-version eldev-release-next-snapshot-version
eldev-release-next-snapshot-version-unless-already-snapshot eldev-release-next-pos-version eldev-release-default-tag
eldev-release-validate-version eldev-release-validate-vcs eldev-release-only-from-main-branch eldev-release-validate-files
eldev-release-test-project eldev-release-maybe-fail)
("eldev-vc" eldev-vc-root-dir eldev-vc-executable eldev-vc-full-name eldev-with-vc eldev-with-vc-buffer eldev--vc-set-up-buffer eldev-vc-synchronize-dir
eldev-vc-detect eldev-vc-commit-id eldev-vc-branch-name
eldev--vc-repository-package eldev--vc-fetch-repository eldev--vc-install-as-package)
("eldev-doctor" eldev-defdoctest)))
(dolist (function (cdr autoloads))
(autoload function (car autoloads)))))
(defvar eldev-shell-command (or (eldev-getenv "ELDEV_CMD") "eldev")
"Command used to launch Eldev, in raw form.
You should use function `eldev-shell-command' in most cases
instead.")
(defvar eldev-emacs-executable (or (eldev-getenv "ELDEV_EMACS") (eldev-getenv "EMACS") "emacs")
"Emacs executable used for Eldev.")
(defconst eldev-dir (or (eldev-getenv "ELDEV_DIR")
(when (file-directory-p "~/.eldev") "~/.eldev")
(expand-file-name "eldev" (eldev-xdg-cache-home)))
"User's Eldev cache directory, usually `~/.cache/eldev'.
This directory is global, i.e. not project-specific. Since 1.4
function `eldev-global-cache-dir' can be used to access this
value.")
(defconst eldev-user-config-file (expand-file-name "config"
(or (eldev-getenv "ELDEV_DIR")
(when (file-directory-p "~/.eldev") "~/.eldev")
(expand-file-name "eldev" (eldev-xdg-config-home))))
"User's Eldev configuration file, usually `~/.config/eldev/config'.
This file is global, i.e. not project-specific.")
(defconst eldev-file "Eldev"
"Project's Eldev configuration file, `Eldev'.")
(defconst eldev-local-file "Eldev-local"
"Working directory Eldev configuration file, `Eldev-local'.")
(defconst eldev-cache-dir ".eldev"
"Name of Eldev cache subdirectory, `.eldev'.
See also function `eldev-cache-dir'.")
(defconst eldev-global-cache-dir "global-cache"
"Name of the global package cache directory (a subdirectory of `eldev-dir').
Since 1.4 function `eldev-global-package-archive-cache-dir' can
be used instead.")
(defvar eldev--internal-pseudoarchive "--eldev--")
(defvar eldev--internal-vc-pseudoarchive "--eldev-vc--")
(defvar eldev--loading-modes
'((as-is
. "Do not alter the project or dependency working directory: add the
directory to `load-path' as-is.")
(packaged
. "Generate a Elisp package out of the project/dependency and load it.
This is the recommended mode for continuous integration and other ways
of automated testing, because it loads in exactly the same manner most
users will use the project.")
(source
. "Clean project's or dependency's working directory first. As a result,
Elisp functions in it are not byte-compiled.")
(byte-compiled
. "Compile all `.el' files first. This will make Elisp functions faster,
but backtraces less informative.")
(compiled-on-demand
. "Compile `.el' files only when they are being `require'd. For larger
projects this allows to avoid recompiling everything just to test some
core functionality. Even more important if higher-level files do not
even compile at the moment, but you still want to run tests on the
byte-compiled core.")
(noisy-compiled-on-demand
. "Like `compiled-on-demand', but additionally prints standard
information about compilations it performs. The “normal” mode only
prints warnings and errors, as output “in the middle” can potentially
break the compiled project or whatever uses it.")
(built
. "Build project or dependency first. Only important for those projects
that define custom rules, i.e. where target `:default' is not empty.")
(built-and-compiled
. "Build and byte-compile first. Exactly as `built' and `compiled'
combined.")
(built-source
. "Clean the project or dependency, then build target `:default'. See
`source' and `built' modes for more explanations.")))
(defvar eldev-formatted-project-name nil
"User-level project name, e.g. with proper capitalization.
If left to `nil', will default to Emacs package name. Since 1.2.")
(defvar eldev--formatted-project-names nil
"Cache for `eldev-formatted-project-name' function.")
(defvar eldev-main-fileset '(:not (eldev-standard-filesets :or :no-excludes :except 'main))
"Fileset used to find main project targets.
Default value means “everything that doesn't match any non-main
filesets”. E.g. if no additional filesets are defined, this
matches everything that is not included in `test' fileset.")
(defvar eldev-test-fileset '("./test.el" "./tests.el" "./*-test.el" "./*-tests.el" "./test/" "./tests/" "./features/") ; the last is for Ecukes
"Fileset used to find test targets.
Default value is files `test.el', `tests.el', `*-test.el' or
`*-tests.el' in the project directory and everything within
`test' or `tests' subdirectories.")
(defvar eldev-standard-excludes '(:or ".*"
"./features/step-definitions/" "./features/support/" ; for Ecukes
(let ((dist-dir (file-relative-name (eldev-dist-dir) eldev-project-dir)))
(unless (eldev-external-or-absolute-filename dist-dir)
(concat "/" dist-dir))))
"Fileset of targets that should be excluded from all sets.
Default value excludes all files and directories with name
starting with dot (i.e. hidden files by UNIX conventions). Most
importantly, this excludes `.eldev' and `.git' directories.
Additionally, `eldev-dist-dir' is excluded.")
(defvar eldev-filesets '((main . eldev-main-fileset)
(test . eldev-test-fileset))
"Alist of target filesets.
The two default filesets `main' and `test' are enough for most
purposes, but you can define more if you need. Special name
`all' is reserved for union (i.e. as with `:or') of all other
standar filesets and must not be mapped here.
Additionally, whenever any of these filesets is resolved,
`eldev-standard-excludes' is always “subtracted” from the
result.")
(defvar eldev-files-to-package
'(:and ("*.el" "./*.info" "./dir" "./doc/*.info" "./doc/dir")
;; Since 1.2 we exclude the autoloads file specifically. Pre-29 Emacs versions
;; seemed to cope with it fine, 29 does not. However, text "Do not include any
;; file named ‘NAME-autoloads.el’" has been in the documentations since years, so
;; this change in behavior cannot be considered an Emacs 29 bug.
(concat "!./" (eldev-package-autoloads-file-name)))
"Files that are copied to built packages.")
(defvar eldev-makeinfo-sources '("./*.texi" "./*.texinfo" "./doc/*.texi" "./doc/*.texinfo")
"Files used as `makeinfo' sources.")
(defvar eldev-info-sources '("./*.info" "./*.info")
"Files used as `install-info' sources to generate target `dir'.")
(defvar eldev-dist-dir "dist"
"Directory where to generate package tarballs.
This directory can even be located outside the project directory,
which is useful in certain special cases.
See also function `eldev-dist-dir'.")
(defvar eldev-clean-external-dist nil
"Whether to allow `eldev clean dist' to delete `dist' directory
even if it is outside of the project. Normally it doesn't do
that as a precaution.")
(defvar eldev-project-loading-mode nil
"Project loading mode, `as-is' if not specified.")
(defvar eldev-normal-dependency-management t
"Use standard package-based dependency management.
Can be disabled in special cases. When disabled, Eldev won't
operate with packages, but instead rely on variable `load-path'
to be set as appropriate, e.g. using environment variable
`EMACSLOADPATH'.
Since 1.9.")
(defvar eldev-external-package-dir nil
"Use given directory instead of managing dependencies separately.
If this value is nil (default), Eldev will manage and install
dependencies as needed. If a directory is specified, Eldev never
installs anything and will fail if a dependency is missing.
Local-source packages will still be loaded from the specified
directories.
If value of this variable is t, load from the standard Emacs
location, i.e. `~/.emacs.d/elpa'.
Since 0.8.")
(defvar eldev-prefer-stable-archives t
"Prefer stable archives (e.g. MELPA Stable) whenever possible.
Since 0.5.")
(defvar eldev-print-backtrace-on-abort nil
"If Eldev is aborted with C-c, print a backtrace.")
(defvar eldev-setup-first-forms nil
"Forms executed as the first step of Eldev setup.
In particular, these forms are evaluated before reading `Eldev'
or `Eldev-local'.
Since 0.5")
(defvar eldev-setup-forms nil
"Forms executed as the last step of Eldev setup.
Should normally be specified only via command line.")
(defvar eldev-robust-mode 'auto
"Whether to retry on certain errors instead of giving up.
Special symbol \\='auto means that Eldev should retry if executed
on a continuous integration server, i.e. where sleeping and
retrying later generally makes sense.
Since 1.5.")
(defvar eldev-robust-mode-retry-delays '(30 60 120 180 300)
"Delays before robust-mode-retrials, in seconds.
This is not controllable from the command line, but can be
changed directly.
Since 1.5.")
(defvar eldev-skip-global-config nil
"Whether to skip file `~/.config/eldev/config'.
Occasionally useful to some external tools. Not exposed through
normal interface, but can be set in a `--setup-first' form.
Since 0.8")
(defvar eldev-skip-project-config nil
"Whether to skip both files `Eldev' and `Eldev-local'.
Occasionally useful to some external tools. Not exposed through
normal interface, but can be set in a `--setup-first' form.
Since 0.5")
(defvar eldev-skip-local-project-config nil
"Whether to skip file `Eldev-local'.
Occasionally useful to some external tools. Not exposed through
normal interface, but can be set in a `--setup-first' form.
Since 0.5")
(defvar eldev-known-tool-packages
'((buttercup :version "1.24" :archive melpa)
(doctest :archive melpa)
(ecukes :version "0.6.18" :archive melpa)
;; Need GNU ELPA for `let-alist' on older Emacs versions.
(package-lint :version "0.14" :archives (melpa gnu-elpa))
(relint :version "2.0" :archive gnu-elpa)
;; Need GNU ELPA for `let-alist' on older Emacs versions.
(elisp-lint :archives (melpa gnu-elpa))
;; This is for a plugin, but probably no reason not to have it unconditionally.
(undercover :version "0.8" :archive melpa))
"Alist of known external tool packages.
Packages listed here can be referred to as `(:tool PACKAGE-NAME)'
in places where package alists are understood. Users can
customize this variable to influence how Eldev picks up external
tools.
Since 0.9.")
(defvar eldev-display-indirect-build-stdout nil
"Whether to display standard output of indirect builds.
For example, if the loading mode is `compiled', such output might
contain “ELC ...” lines. This affects the project itself and all
its dependencies coming from local sources (see function
`eldev-use-local-source'). Display of directly-ordered builds
(e.g. using commands `build', `compile') is always displayed.
Default value is nil since such output might be confused with
output of the “main” command that triggered the build,
e.g. `test', especially when it is parsed programmatically.
However, if this is not a concern in your case, you may want to
set the variable to t. It is not controllable from command line.
Since 1.10.")
(defvar eldev-force-override nil
"Set to non-nil to disable all command and option duplicate checks.")
(defvar eldev--commands nil)
(defvar eldev--command-aliases nil)
(defvar eldev--options nil)
(dolist (var '(eldev-main-fileset eldev-test-fileset eldev-standard-excludes eldev-files-to-package eldev-makeinfo-sources eldev-info-sources))
(eldev-watch-fileset-for-suspicious-modifications var))
(eldev-define-error 'eldev-error "Unhandled Eldev error")
(eldev-define-error 'eldev-missing-dependency "Dependency is missing" 'eldev-error)
(eldev-define-error 'eldev-too-old "Eldev is too old" 'eldev-error)
(eldev-define-error 'eldev-wrong-command-usage "Wrong command usage" 'eldev-error)
(eldev-define-error 'eldev-wrong-option-usage "Wrong option usage" 'eldev-error)
(eldev-define-error 'eldev-build-failed "Build failed" 'eldev-error)
(eldev-define-error 'eldev-build-abort-branch "Build failed" 'eldev-error)
(eldev-define-error 'eldev-quit nil)
;; Internal helper for `eldev-defcommand'.
(defun eldev--register-command (function command keywords)
(let (override)
(while keywords
(eldev-pcase-exhaustive (pop keywords)
(:aliases
(eldev-register-command-aliases command (pop keywords)))
((and (or :category :command-hook :briefdoc :parameters :custom-parsing :hidden-if :works-on-old-eldev :profiling-self) keyword)
(eldev-put function keyword (pop keywords)))
(:override
(setf override (pop keywords)))))
(unless (or override eldev-force-override (not (assq command eldev--commands)) (eq (cdr (assq command eldev--commands)) function))
(error "Duplicate command `%s'; use `:override' keyword if this is intentional" command))
(eldev--assq-set command function eldev--commands)))
(defun eldev-register-command-aliases (command aliases)
"Register additional ALIASES for given COMMAND."
(dolist (alias (eldev-listify aliases))
(eldev--assq-set alias command eldev--command-aliases)))
(defmacro eldev-defcommand (name arguments &rest body)
"Define an Eldev command.
BODY can contain the following keywords:
:command COMMAND
Command name (a symbol) for the command line. Default
value is derived from function name by removing `eldev-'
prefix (or a prefix for any other project).
:category CATEGORY
Generic category of the command. Should be one of
`testing', `running', `dependencies', `building' or
`information'; all other commands are treated as
miscellaneous. Since 1.3.
:aliases ALIASES
One (a symbol) or several (list of symbols) aliases for
the command.
:hook HOOK
Run hook (a symbol) before executing this command.
Default value is derived from function name by appending
`-hook' to it.
:briefdoc STRING
Use STRING as brief (one-line) documentation for the
command. By default it is derived from the function
docstring.
:parameters STRING
One-line string for describing command parameters in its
usage documentation.
:profiling-self FLAG
If true, command `profile' will leave it up to the nested
command to start/stop profiling where suitable,
presumably using `eldev-profile-body'.
Result of BODY is ignored. If you want Eldev to exit with an
error status, signal an error, probably a `eldev-error'."
(declare (doc-string 3) (indent 2))
(let ((parsed-body (eldev-macroexp-parse-body body))
(command (intern (replace-regexp-in-string (rx bol (1+ (not (any "-"))) (1+ "-")) "" (symbol-name name))))
(hook (intern (concat (symbol-name name) "-hook")))
keywords)
(setf body (cdr parsed-body))
(while (keywordp (car body))
(pcase (pop body)
(:command (setf command (pop body)))
(:hook (setf hook (pop body)))
(keyword (push keyword keywords) (push (pop body) keywords))))
`(progn (defun ,name ,arguments
,@(car parsed-body)
,@body)
(defvar ,hook nil ,(format "Hook to be executed before command `%s'." command))
(eldev--register-command ',name ',command ',`(:command-hook ,hook ,@(nreverse keywords))))))
;; Internal helper for `eldev-defoption'.
(defun eldev--register-option (handler options for-command keywords)
(let (override)
(while keywords
(eldev-pcase-exhaustive (pop keywords)
((and (or :value :optional-value) keyword)
(eldev-put handler :option-value `(,(pop keywords) . ,(eq keyword :value))))
((and (or :briefdoc :if-default :hidden-if) keyword)
(eldev-put handler keyword (pop keywords)))
(:default-value
(eldev-put handler :default-value (or (pop keywords) 'nil)))
(:override
(setf override (pop keywords)))))
(dolist (command (if for-command (eldev-listify for-command) '(nil)))
(let ((command-options (or (assq command eldev--options) (car (push `(,command . nil) eldev--options)))))
(dolist (option (eldev-listify options))
(unless (or (eq override t) eldev-force-override (not (assq option (cdr command-options))) (eq (cdr (assq option (cdr command-options))) handler)
(memq command override) (memq option override) (member `(,command ,option) override))
(error "Duplicate option `%s' for command `%s'; use `:override' keyword if this is intentional" option command))
(eldev--assq-set option handler (cdr command-options)))))))
(defmacro eldev-defoption (name arguments &rest body)
"Define an Eldev option (for a command or a global one).
Option's handler function is visible to Elisp under given NAME.
It will be invoked each time the option is specified on the
command line, but not otherwise. Therefore, you may need to take
additional steps to ensure that affected variables etc. are
properly initialized for the default state.
BODY can contain the following keywords:
:options OPTIONS (required)
Invokable from command line using any of listed strings.
OPTIONS can be either a string or a list of strings.
Each must be either in form \"-X\" (one-letter short option)
or \"--long-option\".
:value DESCRIPTION or :optional-value DESCRIPTION
Make the option accept a value that is described with
DESCRIPTION (string or symbol) in the documentation.
:for-command COMMAND
Declare an option for the specified COMMAND or a list of
those. COMMAND must be a symbol or a list of symbols.
Each command must be defined with `eldev-defcommand'
prior to defining an option for it.
:briefdoc STRING
Use STRING as brief (one-line) documentation for the
option. By default it is derived from the function
docstring.
:if-default FORM
Evaluate given FORM to determine if the option is the
default (for the help screen). Since in Eldev everything
is customizable in different ways, result should not be
hardcoded.
:default-value FORM
Evaluate given FORM to determine the default value of the
option for displaying on the help screen. Special case:
if the form evaluates to symbol `:no-default', don't
print anything.
:hidden-if FORM or :hidden-if :default
Certain options are not interesting, unless someone sets
a really unconvential default value. Typical examples
are negation of `--dry-run' options."
(declare (doc-string 3) (indent 2))
(let* ((parsed-body (eldev-macroexp-parse-body body))
options
for-command
keywords)
(setf body (cdr parsed-body))
(while (keywordp (car body))
(pcase (pop body)
(:options (setf options (pop body)))
(:for-command (setf for-command (pop body)))
(keyword (push keyword keywords) (push (pop body) keywords))))
(unless options
(error "`:options' is required for `eldev-defoption'"))
`(progn (defun ,name ,arguments
,@(car parsed-body)
,@body)
(eldev--register-option ',name ',options ',for-command ',(nreverse keywords)))))
(defun eldev-inherit-options (to-command from-command &optional filter)
"Make options of FROM-COMMAND also available for TO-COMMAND.
By default all options of FROM-COMMAND are taken.
However, you can optionally specify a FILTER. It should be a
function accepting two arguments: option name as a symbol and
option handler function. The filter must return t or nil (other
values are reserved for future functionality) that specifies if
given option should be made available for TO-COMMAND. Filter is
called for all option variants; e.g. for command `exec' options
`-f' and `--file' would be considered separately.
Since 1.7."
(unless (assq from-command eldev--commands)
(error "Unknown command `%s'" from-command))
(dolist (entry (reverse (cdr (assq from-command eldev--options))))
(let ((option (car entry))
(handler (cdr entry)))
(when filter
(pcase (funcall filter option handler)
;; All other return values are reserved for future. Ideas: changing option
;; name, changing (wrapping) handler, providing keywords.
(`t)
(`nil (setf option nil))
(value (error "Filter function may only return t or nil currently (got `%S' instead)" value))))
(when option
(eldev--register-option handler option to-command nil)))))
(defmacro eldev-defbooloptions (t-name nil-name variable t-body nil-body &rest common-body)
"Define a yes/no (boolean) option.
This is only a wrapper over `eldev-defoption'."
(declare (indent 3))
`(progn (eldev-defoption ,t-name ()
,@(append t-body common-body `(:if-default ,variable (setf ,variable t))))
(eldev-defoption ,nil-name ()
,@(append nil-body common-body `(:if-default (not ,variable) (setf ,variable nil))))))
(eldev-defbooloptions eldev-enable-debug-mode eldev-disable-debug-mode debug-on-error
("Set `debug-on-error' to t"
:options (-d --debug))
("Set `debug-on-error' to nil"
:options (-D --no-debug)))
(eldev-defbooloptions eldev-print-backtrace-on-abort eldev-no-backtrace-on-abort eldev-print-backtrace-on-abort
("Print backtrace if aborted with C-c"
:options (-Q --backtrace-on-abort))
("Don't print backtrace if aborted with C-c"
:options --no-backtrace-on-abort
:hidden-if :default))
(eldev-defoption eldev-backtrace-style (&optional width)
"Print backtraces for given screen WIDTH; if omitted, don't
truncate backtrace lines"
:options (-b --backtrace --backtrace-style)
:optional-value WIDTH
:default-value (if (and (integerp eldev-backtrace-style) (> eldev-backtrace-style 1))
eldev-backtrace-style
"untruncated")
(setf eldev-backtrace-style (if width (eldev-with-errors-as 'eldev-wrong-option-usage (eldev-parse-number width :min 0)) t)))
(eldev-defoption eldev-cut-backtraces (&optional types)
"Cut backtraces; active notches can be limited to
comma/space-separated TYPES"
:options (-u --cut-backtraces)
:optional-value TYPES
:default-value (cond ((consp eldev-cut-backtraces)
(eldev-message-enumerate nil eldev-cut-backtraces #'symbol-name))
((eq eldev-cut-backtraces t)
"all")
(t
:no-default))
(setf eldev-cut-backtraces (cond ((member types '(nil "all")) t)
((string= types "none") nil)
(t (mapcar #'intern (split-string types "[ \t,]" t))))))
(eldev-defoption eldev-dont-cut-backtraces ()
"Never cut backtraces"
:options (-U --full-backtraces --dont-cut-backtraces)
:hidden-if (null eldev-cut-backtraces)
(setf eldev-cut-backtraces nil))
(eldev-defoption eldev-set-loading-mode (mode)
"Set the project's loading mode"
:options (-m --loading)
:value MODE
:default-value (or eldev-project-loading-mode 'as-is)
;; Accept both strings and symbols.
(when (stringp mode)
(setf mode (intern (downcase mode))))
(unless (assq mode eldev--loading-modes)
(signal 'eldev-wrong-option-usage `("unknown loading mode `%s'" ,mode)))
(setf eldev-project-loading-mode mode))
(eldev-defoption eldev-list-loading-modes ()
"List loading modes and exit"
:options --list-modes
(let ((modes eldev--loading-modes))
(while modes
(let ((mode (pop modes)))
(eldev-output "%s\n\n%s" (eldev-colorize (car mode) 'section) (eldev-format-message (cdr mode)))
(when modes
(eldev-output "\n")))))
(signal 'eldev-quit 0))
(eldev-defoption eldev-set-loading-mode-as-is ()
"Shorthand for `--loading=as-is'"
:options (-a --as-is)
:hidden-if (eq (or eldev-project-loading-mode 'as-is) 'as-is)
(eldev-set-loading-mode 'as-is))
(eldev-defoption eldev-set-loading-mode-packaged ()
"Shorthand for `--loading=packaged'"
:options (-p --packaged)
:hidden-if (eq eldev-project-loading-mode 'packaged)
(eldev-set-loading-mode 'packaged))
(eldev-defoption eldev-set-loading-mode-source ()
"Shorthand for `--loading=source'"
:options (-s --source)
:hidden-if (eq eldev-project-loading-mode 'source)
(eldev-set-loading-mode 'source))
(eldev-defoption eldev-set-loading-mode-byte-compiled ()
"Shorthand for `--loading=byte-compiled'"
:options (-c --byte-compiled)
:hidden-if (eq eldev-project-loading-mode 'byte-compiled)
(eldev-set-loading-mode 'byte-compiled))
(eldev-defoption eldev-set-loading-mode-compiled-on-demand ()
"Shorthand for `--loading=compiled-on-demand'"
:options (-o --compiled-on-demand)
:hidden-if (eq eldev-project-loading-mode 'compiled-on-demand)
(eldev-set-loading-mode 'compiled-on-demand))
(eldev-defoption eldev-set-loading-mode-noisy-compiled-on-demand ()
"Shorthand for `--loading=noisy-compiled-on-demand'"
:options (-O --noisy-compiled-on-demand)
:hidden-if (eq eldev-project-loading-mode 'compiled-on-demand)
(eldev-set-loading-mode 'noisy-compiled-on-demand))
(eldev-defbooloptions eldev-load-prefer-newer-mode eldev-load-first-mode load-prefer-newer
("Set `load-prefer-newer' to t"
:options (-N --load-newer)
:hidden-if (not (boundp 'load-prefer-newer)))
("Set `load-prefer-newer' to nil"
:options (-F --load-first)
:hidden-if (not (boundp 'load-prefer-newer))))
(eldev-defoption eldev-quiet-mode ()
"Restrict output to only essential information"
:options (-q --quiet)
:if-default (eq eldev-verbosity-level 'quiet)
(setf eldev-verbosity-level 'quiet))
(eldev-defoption eldev-normal-output-mode ()
"Output normal amount of information"
:options --normal-output
:if-default (not (memq eldev-verbosity-level '(verbose trace quiet)))
:hidden-if :default
(setf eldev-verbosity-level nil))
(eldev-defoption eldev-verbose-mode ()
"Be more verbose"
:options (-v --verbose)
:if-default (eq eldev-verbosity-level 'verbose)
(setf eldev-verbosity-level 'verbose))
(eldev-defoption eldev-trace-mode ()
"Be very verbose"
:options (-t --trace)
:if-default (eq eldev-verbosity-level 'trace)
(setf eldev-verbosity-level 'trace))
(eldev-defbooloptions eldev-output-time-diffs eldev-dont-output-time-diffs eldev-output-time-diffs
("Prepend elapsed time to every line of output"
:options (-T --time))
("Don't add time information to output"
:options --no-time
:hidden-if :default))
(eldev-defoption eldev-coloring-mode (&optional mode)
"Whether to colorize output; WHEN can be `always', `auto' or `never'"
:options (-C --color)
:optional-value WHEN
:default-value (if eldev-coloring-mode (if (eq eldev-coloring-mode 'auto) "auto" "always") "never")
(setf eldev-coloring-mode (eldev--auto-always-never-option mode)))
;; Not advertised, this is mostly for external tools.
(eldev-defoption eldev-setup-first-form (form)
"Evaluate FORM as the first step of the setup"
:options --setup-first
:value FORM
:hidden-if t
(dolist (form (eldev-read-wholly form "setup form(s)" t))
(push form eldev-setup-first-forms)))
(eldev-defoption eldev-setup-form (form)
"Evaluate FORM as the final step of the setup"
:options (-S --setup)
:value FORM
(dolist (form (eldev-read-wholly form "setup form(s)" t))
(push form eldev-setup-forms)))
(eldev-defbooloptions eldev-prefer-stable-archives eldev-prefer-unstable-archives eldev-prefer-stable-archives
("Prefer stable archives (e.g. MELPA Stable: stable.melpa.org)"
:options --stable
:hidden-if :default)
("Prefer bleeding-edge archives (e.g. MELPA [Unstable]: melpa.org)"
:options --unstable))
(eldev-defoption eldev-enable-project-isolation ()
"Manage and install project dependencies normally"
:options (-I --isolated)
:if-default (null eldev-external-package-dir)
:hidden-if :default
(setf eldev-external-package-dir nil))
(eldev-defoption eldev-use-external-package-dir (&optional dir)
"Use preinstalled dependencies from given directory"
:options (-X --external --external-deps)
:optional-value DIR
:default-value (let ((dir (abbreviate-file-name (eldev-external-package-dir t))))
(if eldev-external-package-dir
dir
`(:instead-of-default ,(eldev-format-message "(default would be `%s')" dir))))
(setf eldev-external-package-dir (or dir t)))
(eldev-defbooloptions eldev-manage-dependencies eldev-disable-dependencies eldev-normal-dependency-management
("Use standard dependency-as-package management"
:options --manage-dependencies
:hidden-if :default)
("Disable standard dependency-as-package management; depend on externally-set `EMACSLOADPATH'"
:options (--disable-dependencies --use-emacsloadpath)))
(eldev-defoption eldev-robust-mode (&optional mode)
"Whether to retry on certain errors; WHEN can be `always', `auto' or `never'"
:options (-R --robust-mode --ci-mode)
:optional-value WHEN
:default-value (if eldev-robust-mode (if (eq eldev-robust-mode 'auto) "auto" "always") "never")
(setf eldev-robust-mode (eldev--auto-always-never-option mode)))
(eldev-defbooloptions eldev-enable-xdebug-initially eldev-disable-xdebug-initially eldev-xdebug-output-enabled
("Enable `xdebug' output initially"
:options (-x --xdebug --enable-xdebug)
:hidden-if :default)
("Disable `xdebug' output initially"
:options (--no-xdebug --disable-xdebug)
:hidden-if :default))
(defun eldev--auto-always-never-option (mode)
(when mode
(setf mode (downcase mode)))
(cond ((or (null mode) (member mode '("always" "on"))) t)
((string= mode "auto") 'auto)
((member mode '("never" "off")) nil)
(t (signal 'eldev-wrong-option-usage `("argument must be `always', `auto' or `never'")))))
;; Filesets.
(defun eldev-standard-fileset (name &optional no-excludes without-generated)
"Return a computed fileset for target set with given NAME.
Unless NO-EXCLUDES is specified, all targets from
`eldev-standard-excludes' are ignored.
Since 1.3: when NO-GENERATED is specified, generated files are
ignored too."
(eldev-standard-filesets (if no-excludes :no-excludes :std-excludes) (if without-generated :without-generated :with-generated) name))
(defun eldev-standard-filesets (&rest arguments)
"Build a fileset from standard pieces.
ARGUMENTS should be either names of standard filesets
(i.e. usually `main' or `test', but see `eldev-filesets') or any
of the following keywords:
:and or :or
How to combine filesets; `:or' is the default.
:these or :except
Whether to use given filesets (default) or every standard
fileset except them.
:std-excludes or :no-excludes
Whether to use `eldev-standard-excludes' (default) or not.
:with-generated or :without-generated (since 1.3)
Whether to include generated files (default) or not; see
function `eldev-generated-files'."
(let ((combination-mode :or)
except
no-excludes
without-generated
names
result)
(dolist (argument arguments)
(pcase argument
((or :and :or)
(setf combination-mode argument))
((or :these :except)
(setf except (eq argument :except)))
((or :no-excludes :std-excludes)
(setf no-excludes (eq argument :no-excludes)))
((or :with-generated :without-generated)
(setf without-generated (eq argument :without-generated)))
((pred keywordp)
(error "Unhandled keyword `%s'" argument))
(_
(push argument names))))
(when (memq 'all names)
(if except
(error "Using special name `all' with `:except' makes no sense")
(if (eq combination-mode :or)
(setf names (mapcar #'car eldev-filesets))
(when (cdr names)
(setf names (delq 'all names))))))
(if except
(dolist (entry eldev-filesets)
(unless (memq (car entry) names)
(push (cdr entry) result)))
(dolist (name names)
(push (cdr (or (assq name eldev-filesets) (error "Unknown fileset `%s'" name))) result)))
(setf result (if (cdr result)
`(,combination-mode ,@(nreverse result))
(car result)))
(unless no-excludes
(setf result `(:and ,result (:not eldev-standard-excludes))))
(when without-generated
(let (generated)
(dolist (file (eldev-generated-files))
(push (format "/%s" file) generated))
(setf result `(:and ,result (:not ,generated)))))
result))
(defun eldev-validate-standard-fileset (name)
"Validate that NAME specifies a standard fileset.
See `eldev-filesets'."
(when (stringp name)
(setf name (intern name)))
(unless (or (eq name 'all) (assq name eldev-filesets))
(signal 'eldev-error `("Unknown standard fileset `%s'", name)))
name)
;; Command line interface.
(defconst eldev-real-user-emacs-directory user-emacs-directory
"Original value of variable `user-emacs-directory'.
During startup, Eldev changes `user-emacs-directory' to point
inside its cache directory. This is done to further isolate the
project being built from the “normal” Emacs, like is done with
e.g. dependency installation. However, original value is stored
in this variable and can be restored in file `Eldev' if certain
project needs it that way.
Since 0.2.1.")
(defvar eldev-executing-command-hook nil)
(defvar eldev-too-old nil)
(defvar eldev-ongoing-named-steps nil
"List (stack) of currently performed named steps.
Each entry has the form of (TYPE . NAME), where both values are
strings; TYPE can also be nil. If an error happens during one,
user will be hinted when exactly the error occurred. Don't
modify this directly, use macro `eldev-named-step' instead.
Since 1.0.")
(defvar eldev-preprocessed-command-line nil
"Non-options to be returned from `eldev-parse-command-line'.
The value is a reversed list of non-option parameters encountered
so far. Option handlers (i.e. bodies of `eldev-defoption') may
access it and modify freely. This is useful if precise order of
certain options relative to non-option parameters is important.
Since 0.11.")
(defvar eldev-preprocessed-command-line-options nil
"Options to be returned from `eldev-parse-command-line'.
See `eldev-preprocessed-command-line' for details.
Since 1.7.")
(defvar backtrace-line-length)
(defvar emacs-repository-branch)
(defvar eldev--vc-repositories nil
"Alist of package names to plists describing used VC repositories.")
(defun eldev-start-up ()
"Prepare Eldev.
Used by Eldev startup script."
(setf eldev--running-from-dir default-directory
package-user-dir (expand-file-name "packages" (eldev-cache-dir t))
package-archives nil
user-emacs-directory (eldev-user-emacs-dir))
;; The idea of postponing directory creation is to avoid littering random directories
;; with `.eldev' in case Eldev is executed there by error, for example.
(add-hook 'eldev--project-validated-hook (lambda () (eldev-user-emacs-dir t))))
(defmacro eldev--maybe-with-target-dependencies (do-set-up public &rest body)
"Execute BODY, possibly setting up `eldev--target-dependencies'."
(declare (indent 2) (debug (form form body)))
(let ((set-up-now (make-symbol "$set-up-now")))
`(let ((,set-up-now (when ,do-set-up (eldev--load-target-dependencies ,public))))
(unwind-protect
(progn ,@body)
(when ,set-up-now
(eldev--save-target-dependencies))))))
(defun eldev-cli (command-line)
"Eldev entry point."
;; We parse command line in a way separate from `command-line-args' and
;; `command-line-args-left', but whatever code we execute from here should believe there
;; are no arguments left.
(eldev--work-around-emacs-bug-65763)
(let (command-line-args-left
command
eldev-too-old
exit-code)
(unwind-protect
(condition-case-unless-debug error
(condition-case error
(eldev-output-reroute-messages
(eldev-advised (#'display-warning :around (lambda (original type message &optional level &rest args)
(let ((eldev-message-rerouting-wrapper (pcase level
(:error #'eldev-error)
(:debug #'eldev-verbose)
(_ #'eldev-warn))))
(apply original type message level args))))
(let ((eldev-project-dir (or eldev-project-dir (expand-file-name default-directory)))
;; Eldev uses a different default.