Skip to content

Commit b3a70d9

Browse files
authored
chore(package-build): Obsolete package-build-expand-file-specs (#65)
* chore(package-build): Obsolete package-build-expand-file-specs * Allow error for files-spec * Follow create tar * update
1 parent d6bbc8c commit b3a70d9

File tree

4 files changed

+79
-54
lines changed

4 files changed

+79
-54
lines changed

lisp/_prepare.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ the `eask-start' execution.")
136136
(let ((len (if (numberp len-or-list) len-or-list (length len-or-list))))
137137
(if (= 1 len) form-1 form-2)))
138138

139+
;; This is used to creating the directory recipe!
140+
(defun eask-current-time ()
141+
"Return current time."
142+
(let ((now (current-time))) (logior (lsh (car now) 16) (cadr now))))
143+
139144
(defun eask-seq-str-max (sequence)
140145
"Return max length in list of strings."
141146
(let ((result 0))
@@ -1044,7 +1049,8 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
10441049
(defun eask-expand-file-specs (specs)
10451050
"Expand file SPECS."
10461051
(mapcar (lambda (elm) (expand-file-name (car elm) default-directory))
1047-
(package-build-expand-file-specs default-directory specs nil t)))
1052+
(ignore-errors ; The new files spec will trigger error, wrap it
1053+
(package-build-expand-files-spec nil nil default-directory specs))))
10481054

10491055
(defun eask-package-files ()
10501056
"Return package files in workspace."

lisp/core/package.el

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
(append eask-files (list eask-package-file)))
3232
package-build-default-files-spec))
3333

34-
(defun eask-package-dir-recipe ()
34+
(defun eask-package-dir-recipe (version)
3535
"Form a directory recipe."
3636
(eask-load "extern/package-recipe")
37-
(let ((name (eask-guess-package-name))
38-
(patterns (eask-package-dir--patterns))
39-
(path default-directory))
40-
(package-directory-recipe name :name name :files patterns :dir path)))
37+
(let* ((name (eask-guess-package-name))
38+
(patterns (eask-package-dir--patterns))
39+
(path default-directory)
40+
(rcp (package-directory-recipe name :name name :files patterns :dir path)))
41+
(setf (slot-value rcp 'version) version)
42+
(setf (slot-value rcp 'time) (eask-current-time))
43+
rcp))
4144

4245
(defun eask-packaged-name ()
4346
"Find a possible packaged name."
@@ -66,12 +69,12 @@
6669
(eask-load "extern/package-build") ; override
6770

6871
(let* ((version (eask-package-version))
69-
(rcp (eask-package-dir-recipe))
72+
(rcp (eask-package-dir-recipe version))
7073
(package-build-working-dir default-directory)
7174
(package-build-archive-dir eask-dist-path))
7275
(eask-with-progress
7376
(format "Building artifact %s (%s)... " (eask-package-name) version)
74-
(package-build--package rcp version)
77+
(package-build--package rcp)
7578
"done ✓"))
7679

7780
(setq packaged (eask-packaged-file)

lisp/extern/package-build.el

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
(require 'package-build nil t)
66

7-
(defun package-build--create-tar (name version directory mtime)
8-
"Create a tar file containing the contents of VERSION of package NAME.
7+
(defun package-build--create-tar (rcp directory)
8+
"Create a tar file containing the package version specified by RCP.
99
DIRECTORY is a temporary directory that contains the directory
10-
that is put in the tarball. MTIME is used as the modification
11-
time of all files, making the tarball reproducible."
12-
(let ((tar (expand-file-name (concat name "-" version ".tar")
13-
package-build-archive-dir))
14-
(dir (concat name "-" version)))
10+
that is put in the tarball."
11+
(let* ((name (oref rcp name))
12+
(version (oref rcp version))
13+
(time (oref rcp time))
14+
(tar (expand-file-name (concat name "-" version ".tar")
15+
package-build-archive-dir))
16+
(dir (concat name "-" version)))
1517
;; XXX: https://github.com/melpa/package-build/pull/34
1618
;;
1719
;; We definitely need to remove these two lines, or else it won't able to
@@ -29,7 +31,7 @@ time of all files, making the tarball reproducible."
2931
;; prevent a reproducable tarball as described at
3032
;; https://reproducible-builds.org/docs/archives.
3133
"--sort=name"
32-
(format "--mtime=@%d" mtime)
34+
(format "--mtime=@%d" time)
3335
"--owner=0" "--group=0" "--numeric-owner"
3436
"--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime"))
3537
(when (and package-build-verbose noninteractive)
@@ -40,7 +42,7 @@ time of all files, making the tarball reproducible."
4042
(message " %s" line)))))
4143

4244
;;
43-
;; NOTE: Following code are brought in cuz it's very useful, but we don't want
45+
;; NOTE: Following code are brought in cuz it's very useful, but we don't want
4446
;; to bring the whole `package-build' package unless it's needed.
4547
;;
4648

@@ -55,42 +57,49 @@ time of all files, making the tarball reproducible."
5557
"lisp/test.el" "lisp/tests.el" "lisp/*-test.el" "lisp/*-tests.el"))
5658
"Default value for :files attribute in recipes.")
5759

58-
(defun package-build-expand-file-specs (dir specs &optional subdir allow-empty)
59-
"In DIR, expand SPECS, optionally under SUBDIR.
60-
The result is a list of (SOURCE . DEST), where SOURCE is a source
61-
file path and DEST is the relative path to which it should be copied.
60+
(defun package-build-expand-files-spec (rcp &optional assert repo spec)
61+
"No documentation."
62+
(let ((default-directory (or repo (package-recipe--working-tree rcp)))
63+
(spec (or spec (oref rcp files))))
64+
(when (eq (car spec) :defaults)
65+
(setq spec (append package-build-default-files-spec (cdr spec))))
66+
(let ((files (package-build--expand-files-spec-1
67+
(or spec package-build-default-files-spec))))
68+
(when assert
69+
(when (and rcp spec
70+
(equal files (package-build--expand-files-spec-1
71+
package-build-default-files-spec)))
72+
(message "Warning: %s :files spec is equivalent to the default"
73+
(oref rcp name)))
74+
(unless files
75+
(error "No matching file(s) found in %s using %s"
76+
default-directory (or spec "default spec"))))
77+
files)))
6278

63-
If the resulting list is empty, an error will be reported. Pass t
64-
for ALLOW-EMPTY to prevent this error."
65-
(let ((default-directory dir)
66-
(prefix (if subdir (format "%s/" subdir) ""))
67-
(lst))
68-
(dolist (entry specs)
69-
(setq lst
70-
(if (consp entry)
71-
(if (eq :exclude (car entry))
72-
(cl-nset-difference lst
73-
(package-build-expand-file-specs
74-
dir (cdr entry) nil t)
75-
:key #'car
76-
:test #'equal)
77-
(nconc lst
78-
(package-build-expand-file-specs
79-
dir
80-
(cdr entry)
81-
(concat prefix (car entry))
82-
t)))
83-
(nconc
84-
lst (mapcar (lambda (f)
85-
(cons f
86-
(concat prefix
87-
(replace-regexp-in-string
88-
"\\.el\\.in\\'"
89-
".el"
90-
(file-name-nondirectory f)))))
91-
(file-expand-wildcards entry))))))
92-
(when (and (null lst) (not allow-empty))
93-
(error "No matching file(s) found in %s: %s" dir specs))
94-
lst))
79+
(defun package-build--expand-files-spec-1 (spec &optional subdir)
80+
(let ((files nil))
81+
(dolist (entry spec)
82+
(setq files
83+
(cond
84+
((stringp entry)
85+
(nconc files
86+
(mapcar (lambda (f)
87+
(cons f
88+
(concat subdir
89+
(replace-regexp-in-string
90+
"\\.el\\.in\\'" ".el"
91+
(file-name-nondirectory f)))))
92+
(file-expand-wildcards entry))))
93+
((eq (car entry) :exclude)
94+
(cl-nset-difference
95+
files
96+
(package-build--expand-files-spec-1 (cdr entry))
97+
:key #'car :test #'equal))
98+
(t
99+
(nconc files
100+
(package-build--expand-files-spec-1
101+
(cdr entry)
102+
(concat subdir (car entry) "/")))))))
103+
files))
95104

96105
;;; extern/package-build.el ends here

lisp/extern/package-recipe.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414

1515
(cl-defmethod package-build--get-commit ((_rcp package-directory-recipe)))
1616

17+
;; After https://github.com/melpa/package-build/commit/f032c806169b0fabbcac1eb44a4f1ae00674bfa8
1718
(cl-defmethod package-build--get-commit-time ((_rcp package-directory-recipe) _rev)
18-
(let ((now (current-time))) (logior (lsh (car now) 16) (cadr now))))
19+
(eask-current-time))
20+
21+
;; After https://github.com/melpa/package-build/pull/67
22+
(cl-defmethod package-build--checkout ((rcp package-directory-recipe)))
23+
24+
(cl-defmethod package-build--get-timestamp-version ((rcp package-directory-recipe))
25+
(package-build--get-commit-time rcp nil))
1926

2027
;;; extern/package-recipe.el ends here

0 commit comments

Comments
 (0)