jacob-carlborg / dlp

Various tools to process the D programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to avoid "No valid config found." with snap?

linkrope opened this issue · comments

With snap, dmd is /snap/bin/dmd, but the config is /snap/dmd/current/bin/dmd.conf.
So, dlp is aborted with "No valid config found."

How does the compiler usually find the config with snap?

Must be "snap magic": just works!
Nearly everything in /snap/bin is linked to the same /usr/bin/snap.
Probably, args[0] is then used to invoke dmd.

It could help, if dlp has a -config option like dmd.

I'll check the code how it finds the config.

Is there a form of "source code" or similar for the snap package?

I found this issue, where the paths were confirmed:
dlang-snaps/dmd.snap#52

Otherwise, maybe @WebDrake can help?

What happens if you place the DLP binary in the same directory as the DMD binary. Will it find the config then?

First Google hit: https://askubuntu.com/questions/919091/why-can-snap-files-not-be-modified-in-any-way
So, placing dlp into the dmd bin directory is not easy, and while dmd.conf is finally found the import path is still wrong.

It works, however, if I add the internal snap directory /snap/dmd/current/bin to the PATH.
Even with dlp still in ~/bin.

Sorry to hear about the trouble, folks.

How does the compiler usually find the config with snap?

The compiler finds the snap-package config because it is in one of the default search locations -- the same directory as the dmd binary.

As @linkrope correctly notes, it's not possible to place extra binaries in the snap package's bin/ directory. Since I'm not familiar with dlp's codebase, how is it searching for the config file?

Absent any specific knowledge, I would recommend searching for the compiler's expected default config locations, but searching relative to the actual compiler binary location before hardcoded locations like /usr/bin/ or /etc/.

It works, however, if I add the internal snap directory /snap/dmd/current/bin to the PATH.

That's interesting. Is dlp using PATH to search for possible locations of the config file? That won't work with the snap package, because PATH contains /snap/bin (which exposes wrapper scripts to the underlying packaged binaries) rather than the full /snap/dmd/current/bin folder.

Since I'm not familiar with dlp's codebase, how is it searching for the config file?

It uses the same code as the compiler to find the config. But since the config is not located next to the DLP binary, it won't find it.

but searching relative to the actual compiler binary location before hardcoded locations like /usr/bin/ or /etc/

Hmm, that's an interesting idea. Not sure how easy that would be. DLP is trying to support having druntime/Phobos installed from both DMD and LDC. Perhaps DLP should ship with its own version of druntime/Phobos. Otherwise there's always the risk of breaking DLP.

That's interesting. Is dlp using PATH to search for possible locations of the config file?

DLP is using the same code as the compiler. Technically it's only on Windows the compiler is looking for looking for the config in the same directory as the binary. On Posix, it will look through PATH for the first argument to main [1].

[1] https://github.com/dlang/dmd/blob/6b6374296f6590d6f0207fac6754bdcc812ecb80/src/dmd/dinifile.d#L56-L57

On Posix, it will look through PATH for the first argument to main [1].

Unfortunately that's an issue for snap packages, because the stuff in PATH is just wrapper scripts. You can probably do a workaround of assuming that if the compiler exe in the PATH is

/snap/bin/{compiler-exe-name}

... then the underlying compiler binary will live in /snap/{compiler-exe-name}/current/bin/, and the config file will either be there or in /snap/{compiler-exe-name}/etc/.

But honestly this makes me think that really we need a way to be able to query the compiler for which config file it is using, otherwise apps like DLP will always be playing catch-up if the search rules change.

Unfortunately that's an issue for snap packages, because the stuff in PATH is just wrapper scripts

So how does it work for snap packages? I linked to the code the compiler is using.

But honestly this makes me think that really we need a way to be able to query the compiler for which config file it is using, otherwise apps like DLP will always be playing catch-up if the search rules change.

Then you need a way to find the compiler. Unless you just assume it's in the PATH.

It could help, if dlp has a -config option like dmd.

@linkrope I've added support for the --config flag in master now. Could you please give it a try?

It's still "No valid config found."

This looks somehow destructive:
https://github.com/jacob-carlborg/dlp/blob/master/source/dlp/driver/commands/dlp_command.d#L38

I also cannot combine --config with --print-config, but this was not intended?

./dlp --print-config infer-attributes --config /snap/dmd/current/bin/dmd.conf 
Unrecognized option --config

It's still "No valid config found."

I have not fixed automatically detecting the config file.

This looks somehow destructive:
https://github.com/jacob-carlborg/dlp/blob/master/source/dlp/driver/commands/dlp_command.d#L38

The above sets up the default value for the config file. beforeRun is called before the run method, where the CLI parsing occur:

auto result = parseCommandLine(rawArgs, arguments);

I also cannot combine --config with --print-config, but this was not intended?

Yeah, that was the intention. But I can probably fix that.

I'll take a look again at the issue.

I mean: your change does not seem to work

./dlp infer-attributes --config /snap/dmd/current/bin/dmd.conf
No valid config found.

(However, I was able to use infer-attributes after changing PATH to the internal snap directory. Nice tool!)

I mean: your change does not seem to work

Yeah, hence the "I'll take a look again at the issue." 😉.

(However, I was able to use infer-attributes after changing PATH to the internal snap directory. Nice tool!)

Cool, thanks.

./dlp infer-attributes --config /snap/dmd/current/bin/dmd.conf

Could you please check again? You need to remove DDC (the DLP dependency), usually in ~/.dub/packages/ddc-*.

Perhaps I should install the Snap package myself ...

Removing DDC did not help. Would be great if you could check the Snap package yourself.

There seems to be another (related?) issue with 32 vs. 64 bit. dlp infer-attributes shows errors for

auto foo(BitArray a)
{
    return a & a;
}

With explicit --target-architecture=x86, everything works. The help text, however, shows the wrong default:

--target-architecture=x86|x86_64      Set <arch> as the target architecture [default: x86].

@linkrope could you please give this a try: #10.

I've verified myself that it works when DMD and LDC are installed via Snap. The --config flag should work correctly now. It is also able to automatically detect the config now.

There seems to be another (related?) issue with 32 vs. 64 bit

I don't think it's related. I'll take a look at that as well. I've reported it as a separate issue: #11.

Works great!

To verify the --config option, I removed snap from the PATH. Works also.
The error messages, however, are not exactly user friendly:

dlp infer-attributes -h
No D compiler found. `Use parseImportsFromConfig` manually.

dlp infer-attributes --config /snap/dmd/current/bin test.d
Is a directory

I've reported these as two separate issues: #13 and #14.