Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
linkrope opened this issue Dec 21, 2020 · 23 comments
Closed

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

linkrope opened this issue Dec 21, 2020 · 23 comments

Comments

@linkrope
Copy link

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."

@jacob-carlborg
Copy link
Owner

How does the compiler usually find the config with snap?

@linkrope
Copy link
Author

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.

@jacob-carlborg
Copy link
Owner

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

@jacob-carlborg
Copy link
Owner

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

@linkrope
Copy link
Author

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

Otherwise, maybe @WebDrake can help?

@jacob-carlborg
Copy link
Owner

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

@linkrope
Copy link
Author

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.

@WebDrake
Copy link

WebDrake commented Jan 3, 2021

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.

@jacob-carlborg
Copy link
Owner

jacob-carlborg commented Jan 4, 2021

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

@WebDrake
Copy link

WebDrake commented Jan 4, 2021

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.

@jacob-carlborg
Copy link
Owner

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.

@jacob-carlborg
Copy link
Owner

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?

@linkrope
Copy link
Author

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

@jacob-carlborg
Copy link
Owner

jacob-carlborg commented Jan 10, 2021

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.

@linkrope
Copy link
Author

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!)

@jacob-carlborg
Copy link
Owner

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.

@jacob-carlborg
Copy link
Owner

./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-*.

@jacob-carlborg
Copy link
Owner

Perhaps I should install the Snap package myself ...

@linkrope
Copy link
Author

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].

@jacob-carlborg
Copy link
Owner

@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.

@jacob-carlborg
Copy link
Owner

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.

@linkrope
Copy link
Author

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

@jacob-carlborg
Copy link
Owner

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

jacob-carlborg added a commit that referenced this issue Jan 23, 2021
Fix #8: How to avoid "No valid config found." with snap?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants