Debug Adapter Protocol (DAP)

Very exciting to see how quickly this is coming along!

I’m having an issue installing the debug_adapter as a pack though, since it tries to install to /usr/local/bin; is there any way to have it install to ~/.local/bin or something like that when building as a pack? (I tried PREFIX=$HOME/.local EPREFIX=$HOME/.local swipl -g 'pack_install(debug_adapter)' -t halt but that didn’t seem to work)

1 Like

Hi James,
Your attempt with PREFIX etc. would be my initial guess as well, but examining the autotools-generated Makefile and configure script reveals that this approach is bound to fail.
./configure doesn’t use the PREFIX environment variable at all, the only use of this uppercase string is in the help message as a placeholder for the value of the --prefix flag.
If the flag is not specified, the default value of /usr/local/bin comes from a “packaging-time” definition, so changing it would require changing the default installation directory for everybody that tries to pack_install the package.

There is one immediate but partial solution - define the environment variable DESTDIR rather than PREFIX. DESTDIR is consulted by the generated Makefile and is used as the root directory for everything. That’s why it’s only a partial solution - setting DESTDIR to e.g. ~/.local/bin will cause the server to be installed at ~/.local/bin/usr/local/bin, which is not quite what you’ve asked for :expressionless:
Anyway to make DESTDIR actually set in the environment in which make install is ran, I suspect it’s not enough to simply set it in your shell before running swipl, because pack_install/1 only inherits selected variables from the execution environment. Fortunately there appears to be a hook in place that exactly allows you to inject environment variables for the build process - see environment/2.

For a full solution though, I think that pack_install/2 may need to be extended to optionally pass a command line argument such as --prefix=$HOME/.local to execution of ./configure.
Then you could run something like:

swipl -g 'pack_install(debug_adapter, [configure([prefix("/some/path")])])' -t halt

If @jan doesn’t find it unreasonable, I can open a PR to add such an extra option to pack_install/2, seems like it wouldn’t be too hard as the options are already propagated down to configure_foreign/2, which could be extended to recognized these configure specific options.

2 Likes

First of all, I’m impressed how quickly this all comes around!

I’m not sure. It is not nice if packages require their one set of flags to get installed and we can’t just call ?- pack_install(Pack). without thinking. The problem is installing an executable script, no? While I haven’t studied the details, it looks like automake might be a little too abstract and hard to tweak to conform to the SWI-Prolog pack install conventions. Right?

Thank you!

Just to be clear, it is possible to simply pack_install(debug_adapter), it’s actually verified in the CI :slight_smile:
If I understand @jamesnvc correctly, his setup does not permit installing the script to /usr/local/bin and he would like to specify a custom installation directory. For most users I think /usr/local/bin is as good of a default as any.

So the only limitation that comes from autotools AFAICT is that ./configure doesn’t consult environment variables but only command line arguments. Also I can (hopefully) tweak the Makefile.am to inject consulting of some environment variable for determining the desired installation location, but what I thought was that anyway if the user wants to specify a custom installation target, they’d better use pack_install/2 and specify some custom option. WDYT?

It mostly boils down to where we install executables. I guess there are three sensible places, the ~/.local, ~/bin and /usr/local/bin. What about figuring out where Prolog is installed and pass that as --prefix= to configure by default? Should work fine for installing as user. Maybe if Prolog comes from /usr/bin one still would like to use /usr/local/bin?

I’m looking for some sensible default rules and provide a hook/flag to allow overriding.

1 Like

I like that idea, that was sort of what I was expecting to happen, I think.

Please take a look at ADDED: pack_install/1 and friends: pass a _prefix_ flag to CMake or · SWI-Prolog/swipl-devel@b9519db · GitHub

2 Likes

Works perfectly with 8.5.0 – thanks Jan!