tidalcycles / Tidal

Pattern language
http://tidalcycles.org/
GNU General Public License v3.0
2.23k stars 254 forks source link

get location of BootTidal.hs #743

Closed jwaldmann closed 3 years ago

jwaldmann commented 3 years ago

Hi.

This is another way of finding BootTidal.hs, avoiding gymnastics with ghc-pkg field and ghc --numeric-version. Might help with #583 #615. Worksforme, and I can make a PR.

Put this in tidal.cabal

...
  autogen-modules: Paths_tidal

  Exposed-modules:     Paths_tidal
                       Sound.Tidal.Bjorklund
...

then after installing (cabal install --lib)

ghc -e "import Paths_tidal" -e "getDataDir"

==> "/home/waldmann/.cabal/store/ghc-8.10.2/tidal-1.6.2-7f2a9abbae25afcc64d0a7d96ffe51eb55482b087b15e927fbaba2cc55015df2/share"

So put these lines in tidal.el:

          ((or (string-equal system-type "darwin") (string-equal system-type "gnu/linux"))
           '(("path" . "echo -n data-dir: && ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr'")
             ("separator" . "/")
             ))

where I need to add "data-dir:" artifically but the next part of the code expects it.

I like this because it is just calling ghc, and ghci is needed anyway for running tidal. (Current solution calls ghc-pkg and runs into its inconsistent (with ghc(i)) handling of env files.)

Features used:

One could probably avoid the extra call of ghc and instead load the boot file as the very first command of Tidal's ghci session. This would require some contraption - does ghci allow bash-like "HERE scripts"? [EDIT] not HERE scripts but "command substitution" https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html#Command-Substitution

yaxu commented 3 years ago

Looks good! I only know about :script for loading scripts and :{ and :} for denoting blocks of code in ghci.

jwaldmann commented 3 years ago

I can make a PR.

It should be tested for other ways of installing tidal (and ghc) -- I am only doing cabal (user) install from source.

(note to self: cabal install --lib --allow-newer tidal hosc. Hosc also needed since BootTidal.hs wants it.)

About avoiding the extra call to ghc in tidal.el, see https://mail.haskell.org/pipermail/haskell-cafe/2021-January/133291.html

yaxu commented 3 years ago

This isn't working for me. The shell command looks fine:

alex@olga:~/.cabal$ echo -n data-dir: && ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr'
data-dir:/home/alex/.cabal/share/x86_64-linux-ghc-8.6.5/tidal-1.7.1alex@olga:~/.cabal$ 

However when I try to start tidal:

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> syntax:  :script <filename>
Prelude> 
<interactive>:2:1: error: parse error on input ‘/’

Sorry I'm not sure how to debug elisp..

jwaldmann commented 3 years ago

Argh. Confirm that I am seeing the same error with ghc-8.6.5 (which I normally don't use).

One guess is:

with ghc-8.10:

ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr'

/home/waldmann/.cabal/store/ghc-8.10.3/tidal-1.6.2-6d47fb8d7a858c825ee58ca869fc2c9f7b20f4d009fb4f4d2883608472ade267/share

with ghc-8.6.5:

ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr'

Loaded package environment from /home/waldmann/.ghc/x86_64-linux-8.6.5/environments/default
/home/waldmann/.cabal/store/ghc-8.6.5/tidal-1.7.1-415583b1d5b261ccff892c702f2432479edb8562bafff8b3e97a6ed2cc0e55a1/share

note: two lines

This extra line can be toggled with ghc -v0 -e 0 (the last 0 here is just a simple expression to evaluate, as a test case) in ghc-8.10.3 (see also https://club.tidalcycles.org/t/learning-tidal-course-week-zero-installation-and-exploration/37/93) but not in ghc-8.8 or ghc-8.6.

I think this helps (re-direct stderr)

diff .emacs.d/lisp/tidal.el .emacs.d/lisp/tidal.el~
69c69
<            '(("path" . "echo -n data-dir: && ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr' 2>/dev/null")
---
>            '(("path" . "echo -n data-dir: && ghc -e 'import Paths_tidal' -e 'getDataDir>>=putStr'")

perhaps elisp has a better way of ignoring stderr.

jwaldmann commented 3 years ago

perhaps elisp has a better way of ignoring stderr.

apparently, it does not: https://emacs.stackexchange.com/questions/21422/how-to-discard-stderr-when-running-a-shell-function

primary source: https://www.gnu.org/software/emacs/manual/html_node/elisp/Synchronous-Processes.html#Synchronous-Processes

then 2>/dev/null seems easier.

How to proceed? I can make a PR, perhaps someone can test and confirm?

yaxu commented 3 years ago

Yes that sounds like a good plan, thanks!