1

For context I am looking at a remote file; for example: /ssh:desktop:/home/user/project/src/file.cpp.

I then issue the interactive command compile like so:
cd /ssh:desktop:/home/user/project/Release && make
And get the following output:

-*- mode: compilation; default-directory: "/ssh:desktop:/home/user/project/Release/" -*-
Compilation started at Wed May 20 22:42:42

cd /ssh:desktop:/home/user/project/Release && make
/bin/sh: 2: cd: can't cd to /ssh:desktop:/home/user/project/Release

Compilation exited abnormally with code 2 at Wed May 20 22:42:43


Then I tried issuing the interactive command compile differently (without the remote prefix):
cd /home/user/project/Release && make
And get the following error:
No such directory found via CDPATH environment variable


I can't quite figure it out, but I suspect that the function cd (in site-lisp file emacs/lisp/files.el) has something to do with it:
(defun cd (dir)
  "Make DIR become the current buffer's default directory.
If your environment includes a `CDPATH' variable, try each one of
that list of directories (separated by occurrences of
`path-separator') when resolving a relative directory name.
The path separator is colon in GNU and GNU-like systems."
  (interactive
   (list
    ;; FIXME: There's a subtle bug in the completion below.  Seems linked
    ;; to a fundamental difficulty of implementing `predicate' correctly.
    ;; The manifestation is that TAB may list non-directories in the case where
    ;; those files also correspond to valid directories (if your cd-path is (A/
    ;; B/) and you have A/a a file and B/a a directory, then both `a' and `a/'
    ;; will be listed as valid completions).
    ;; This is because `a' (listed because of A/a) is indeed a valid choice
    ;; (which will lead to the use of B/a).
    (minibuffer-with-setup-hook
        (lambda ()
          (setq-local minibuffer-completion-table
              (apply-partially #'locate-file-completion-table
                       cd-path nil))
          (setq-local minibuffer-completion-predicate
              (lambda (dir)
            (locate-file dir cd-path nil
                     (lambda (f) (and (file-directory-p f) 'dir-ok))))))
      (unless cd-path
        (setq cd-path (or (parse-colon-path (getenv "CDPATH"))
                          (list "./"))))
      (read-directory-name "Change default directory: "
                           default-directory default-directory
                           t))))
  (unless cd-path
    (setq cd-path (or (parse-colon-path (getenv "CDPATH"))
                      (list "./"))))
  (cd-absolute
   (or
    ;; locate-file doesn't support remote file names, so detect them
    ;; and support them here by hand.
    (and (file-remote-p (expand-file-name dir))
         (file-accessible-directory-p (expand-file-name dir))
         (expand-file-name dir))
    (locate-file dir cd-path nil
                 (lambda (f) (and (file-directory-p f) 'dir-ok)))
    (error "No such directory found via CDPATH environment variable"))))
John DeBord
  • 550
  • 3
  • 13
  • 1
    You can work around the error if your compile command doesn’t start with ‘cd’ so I do a ‘source env.sh && cd dir && make’. If you don’t have a file to source, you could do something innocuous like ‘echo “Starting compile” && CD dir && make’ – InHarmsWay May 21 '20 at 04:07
  • Nice. Found another workaround `/bin/bash -c ''` – John DeBord May 21 '20 at 15:44

1 Answers1

3

Your command cd /ssh:desktop:/home/user/project/Release && make will be given to a shell on the remote machine. This doesn't know any Tramp syntax, and it runs already on the proper host. So you shall use the command cd /home/user/project/Release && make instead.

Michael Albinus
  • 6,647
  • 14
  • 20
  • 1
    Or indeed use a relative path `cd .. && make` – alls0rts May 31 '20 at 18:05
  • I already tried that, and I receive the following error: `No such directory found via CDPATH environment variable` (using relative paths works, though. But not absolute paths). – John DeBord May 31 '20 at 19:31
  • 1
    Ahh, you're right. I've overlooked this in your message. Just checked with current Emacs, and there is indeed an error in compile.el. It extracts the directory from the `cd /path/to/dir`, and sets `default-directory` to that string, w/o respecting whether `default-directory` is already remote. Using relative file names will work. I recommend that you file a bug report towards Emacs, via `M-x report-emacs-bug`. – Michael Albinus Jun 01 '20 at 07:53