Skip to content

Commit

Permalink
Fix a bug caused by commit 8803491 in packaged local dependency setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
doublep committed May 11, 2024
1 parent f4fafc3 commit eac557c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
55 changes: 30 additions & 25 deletions eldev.el
Original file line number Diff line number Diff line change
Expand Up @@ -3279,31 +3279,36 @@ Returns nil if it is neither a project nor a local dependency."
(eldev-verbose "Preparing to load local dependency `%s' in mode `%s'" dependency-name loading-mode))
(let ((default-directory dependency-dir))
(dolist (command commands)
(when eldev-display-indirect-build-stdout
(setf command `("--setup" "(setf eldev--skip-nothing-to-do-messages t)" ,@command)))
(eldev-call-process (eldev-shell-command) command
:forward-output (if eldev-display-indirect-build-stdout t 'stderr)
:destination (if eldev-display-indirect-build-stdout t '(t nil))
:trace-command-line (eldev-format-message "Full command line (in directory `%s')" default-directory)
:die-on-error (if project-itself
"child Eldev process"
(eldev-format-message "child Eldev process for local dependency `%s'" dependency-name))
(unless eldev-display-indirect-build-stdout
(if (= (point-min) (point-max))
(eldev-verbose "Child Eldev process produced no output (other than maybe on stderr)")
(eldev-verbose "(Non-stderr) output of the child Eldev process:")
(eldev-verbose (buffer-string))))
(when (string= (car command) "package")
(eldev-discard-ansi-control-sequences)
(goto-char (point-max))
(forward-line -2)
(let ((point (point)))
(end-of-line)
(let ((file (buffer-substring-no-properties point (point))))
(forward-line)
(unless (looking-at (rx bol (or "up-to-date" "generated") eol))
(error "Unable to parse child Eldev process output:\n%s" (buffer-string)))
(push `(,dependency-name ,file ,(string= (match-string 0) "up-to-date")) eldev--local-dependency-packages))))))))
(let* ((packaging (string= (car command) "package"))
;; When packaging, we request the nested Eldev to produce some output
;; meant for internal purposes, so stdout forwarding is suppressed.
;; FIXME: Not good enough if packaging results in some other build steps...
(display-stdout (and eldev-display-indirect-build-stdout (not packaging))))
(when display-stdout
(setf command `("--setup" "(setf eldev--skip-nothing-to-do-messages t)" ,@command)))
(eldev-call-process (eldev-shell-command) command
:forward-output (if display-stdout t 'stderr)
:destination (if display-stdout t '(t nil))
:trace-command-line (eldev-format-message "Full command line (in directory `%s')" default-directory)
:die-on-error (if project-itself
"child Eldev process"
(eldev-format-message "child Eldev process for local dependency `%s'" dependency-name))
(unless display-stdout
(if (= (point-min) (point-max))
(eldev-verbose "Child Eldev process produced no output (other than maybe on stderr)")
(eldev-verbose "(Non-stderr) output of the child Eldev process:")
(eldev-verbose (buffer-string))))
(when packaging
(eldev-discard-ansi-control-sequences)
(goto-char (point-max))
(forward-line -2)
(let ((point (point)))
(end-of-line)
(let ((file (buffer-substring-no-properties point (point))))
(forward-line)
(unless (looking-at (rx bol (or "up-to-date" "generated") eol))
(error "Unable to parse child Eldev process output:\n%s" (buffer-string)))
(push `(,dependency-name ,file ,(string= (match-string 0) "up-to-date")) eldev--local-dependency-packages)))))))))
(push `(,dependency-name . (,dependency)) package-alist))))

;; This is a hackish function only working for packages loaded in `as-is' and similar
Expand Down
16 changes: 11 additions & 5 deletions test/local-dependencies.el
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
(should (string= stdout ""))
(should (= exit-code 1)))))

(ert-deftest eldev-local-dependency-fixes-missing-dependency-2 ()
(eldev-ert-defargtest eldev-local-dependency-fixes-missing-dependency-2 (display-stdout)
(nil t)
(eldev--test-run "dependency-a" ("clean")
(should (= exit-code 0)))
(let ((eldev--test-project "missing-dependency-a"))
Expand All @@ -108,16 +109,18 @@
;; In `byte-compiled' loading mode `byte-code-function-p' must
;; always return t, i.e. dependency must be compiled implicitly.
(eldev--test-run nil ("--setup" `(eldev-use-local-dependency "../dependency-a" 'byte-compiled)
"--setup" `(setf eldev-display-indirect-build-stdout ,display-stdout)
"eval" `(dependency-a-stable) `(byte-code-function-p (symbol-function 'dependency-a-stable))
`(package-desc-version (eldev-find-package-descriptor 'dependency-a)))
(should (string= stdout (eldev--test-lines "nil" "t" "(1 0 99)")))
(should (string= stdout (eldev--test-lines (when display-stdout '("ELC dependency-a.el")) "nil" "t" "(1 0 99)")))
(should (= exit-code 0)))
(eldev--test-run nil ("eval" `(dependency-a-stable))
(should (string-match-p "dependency-a" stderr))
(should (string= stdout ""))
(should (= exit-code 1)))))

(ert-deftest eldev-local-dependency-fixes-missing-dependency-3 ()
(eldev-ert-defargtest eldev-local-dependency-fixes-missing-dependency-3 (display-stdout)
(nil t)
(eldev--test-run "dependency-a" ("compile")
(should (= exit-code 0)))
(let ((eldev--test-project "missing-dependency-a"))
Expand All @@ -130,16 +133,18 @@
;; return nil, i.e. dependency must be cleaned even if compiled
;; before.
(eldev--test-run nil ("--setup" `(eldev-use-local-dependency "../dependency-a" 'source)
"--setup" `(setf eldev-display-indirect-build-stdout ,display-stdout)
"eval" `(dependency-a-stable) `(byte-code-function-p (symbol-function 'dependency-a-stable))
`(package-desc-version (eldev-find-package-descriptor 'dependency-a)))
(should (string= stdout (eldev--test-lines "nil" "nil" "(1 0 99)")))
(should (string= stdout (eldev--test-lines (when display-stdout '("Deleted 1 file")) "nil" "nil" "(1 0 99)")))
(should (= exit-code 0)))
(eldev--test-run nil ("eval" `(dependency-a-stable))
(should (string-match-p "dependency-a" stderr))
(should (string= stdout ""))
(should (= exit-code 1)))))

(ert-deftest eldev-local-dependency-fixes-missing-dependency-4 ()
(eldev-ert-defargtest eldev-local-dependency-fixes-missing-dependency-4 (display-stdout)
(nil t)
(eldev--test-run "dependency-a" ("clean")
(should (= exit-code 0)))
(let ((eldev--test-project "missing-dependency-a"))
Expand All @@ -152,6 +157,7 @@
;; return t, i.e. dependency must be compiled when installed as a
;; package. FIXME: Probably could use a better check.
(eldev--test-run nil ("--setup" `(eldev-use-local-dependency "../dependency-a" 'packaged)
"--setup" `(setf eldev-display-indirect-build-stdout ,display-stdout)
"eval" `(dependency-a-stable) `(byte-code-function-p (symbol-function 'dependency-a-stable))
`(package-desc-version (eldev-find-package-descriptor 'dependency-a)))
(should (string= stdout (eldev--test-lines "nil" "t" "(1 0 99)")))
Expand Down

0 comments on commit eac557c

Please sign in to comment.