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

Fix #895, so that dub looks for a compiler next to itself first #1208

Merged
merged 1 commit into from
Dec 6, 2017
Merged

Fix #895, so that dub looks for a compiler next to itself first #1208

merged 1 commit into from
Dec 6, 2017

Conversation

joakim-noah
Copy link
Contributor

@joakim-noah joakim-noah commented Jul 27, 2017

Since I didn't get a response about how checking for a compiler next to dub should interact with the one specified in a DUB config file, I went ahead and implemented what I thought makes sense. I can add some tests once the behavior is approved.

Also puts some restrictions on the defaultCompiler specified in a DUB settings.json, such that it must be a compiler name or an absolute path, including a tilde-prefixed local path. Relative paths are no longer
allowed, as they make no sense for how dub invokes the compiler. You could argue that even a compiler name should be disallowed, as it's unlikely anyone will specify one that's not already on the default list that dub tries, but I suppose the sdc devs may want to try out dub some day. ;)

If a compiler name like sdc is specified in a DUB settings.json, I have dub check for other common compilers in the PATH only if sdc isn't found next to dub or on the PATH (Update: which is probably why the test for #895 now fails on Travis CI, though the test will be changed), though you could argue the user only wants sdc used. However, dub always says what compiler it's using and if the user hasn't provided an sdc, it's a convenience to search for another compiler. I could change it to only check the PATH for sdc in that case, if wanted, as I do when checking next to dub.

Finally, all this changes nothing about specifying a compiler with --compiler, where none of this is used and you can specify any D compiler you want, including one with a relative path.

@dlang-bot
Copy link
Collaborator

dlang-bot commented Jul 27, 2017

Thanks for your pull request, @joakim-noah!

@MartinNowak
Copy link
Member

Why not interpret relative paths in settings.json as relative to dir containing the dub executable?

@joakim-noah
Copy link
Contributor Author

Possible, but then inconsistent with --compiler, which I believe will invoke relative to getcwd. Could still do that, as we assume someone writing a config file is sane, ;) just as long as we document the difference.

@MartinNowak
Copy link
Member

Possible, but then inconsistent with --compiler, which I believe will invoke relative to getcwd. Could still do that, as we assume someone writing a config file is sane, ;) just as long as we document the difference.

I'd go for it, as it allows more flexibility for packaging (e.g. different bin folders).
We could use some $DUB_BIN_PATH variable instead of relative paths to make it more explicit.
Can the settings.json be located next to dub or somehow be part of the packaging?

@joakim-noah
Copy link
Contributor Author

We could use some $DUB_BIN_PATH variable instead of relative paths to make it more explicit.

Good idea, will add that.

Can the settings.json be located next to dub or somehow be part of the packaging?

dub looks for it first in the system (/var/lib/dub on Posix, scroll up a bit to see), then relative to the binary at ../etc/dub/settings.json, and finally in ~/.dub. ldc uses the second to change the default compiler name to ldc, but that's it.

@joakim-noah
Copy link
Contributor Author

Alright, modified this pull to check for %%dubbinarypath%% also, similar to the way ldc does it. I'll fix and write more tests once this behavior is approved.

@joakim-noah
Copy link
Contributor Author

@s-ludwig, let me know if this pull is okay, would be good to get this in before the next dmd/ldc releases.

@s-ludwig
Copy link
Member

Sorry for the late reply, this slipped past me. Two notes:

  • DUB_BIN_PATH or DUB_BINARY_PATH would be more consistent with the other variables that DUB defines
  • Is the changed lookup logic still needed with the new possibility to specify an executable-relative path in settings.json?

@joakim-noah
Copy link
Contributor Author

DUB_BIN_PATH or DUB_BINARY_PATH would be more consistent with the other variables that DUB defines

Those are all environment variables normally though, right? I thought this should be different because it's specific to the config file. Doesn't really matter to me though, just let me know what you want.

Is the changed lookup logic still needed with the new possibility to specify an executable-relative path in settings.json?

The only changed lookup logic is to first search for a compiler name specified in the config file in the PATH. The newly added lookup in the directory next to dub could just be replaced by specifying an executable-relative path in the config file instead, as you say, but it's a convenience to not have to provide a config file at all, ie it always looks next to dub.

@s-ludwig
Copy link
Member

Those are all environment variables normally though, right? I thought this should be different because it's specific to the config file. Doesn't really matter to me though, just let me know what you want.

My idea was that we could support real environment variables, too, at some point, and this special case could then just naturally merge with that.

The newly added lookup in the directory next to dub could just be replaced by specifying an executable-relative path in the config file instead, as you say, but it's a convenience to not have to provide a config file at all, ie it always looks next to dub.

Okay, it's mostly just a fuzzy concern on my side right now, because I haven't really thought through the possible implications/issues. One thing that gets a bit hairy is when one explicitly wants to select the compiler in PATH instead of the one in the local directory, but maybe that's a bit superficial. Generally I'd just try to avoid changes that serve no concrete need (i.e. if a config file in the compiler distribution already works for the initial use case).

@joakim-noah
Copy link
Contributor Author

joakim-noah commented Aug 31, 2017

My idea was that we could support real environment variables, too, at some point, and this special case could then just naturally merge with that.

OK, will change it.

One thing that gets a bit hairy is when one explicitly wants to select the compiler in PATH instead of the one in the local directory, but maybe that's a bit superficial.

Just specify --compiler=gdc then, as noted for rdmd with its equivalent pull. You're right that you couldn't do that from the config file anymore though, if dub had the same compiler next to it.

Generally I'd just try to avoid changes that serve no concrete need (i.e. if a config file in the compiler distribution already works for the initial use case).

It is true that adding that option to use a compiler relative to dub's path to the config file, which wasn't there before this pull, is potentially redundant with checking for a compiler next to dub automatically, but only if every compiler that ships dub adds a config file that explicitly says where dub is relative to the compiler.

Since most will stick dub right next to the compiler, this saves them that trouble. It's sufficiently common that I think it's worth having both.

@s-ludwig
Copy link
Member

s-ludwig commented Sep 5, 2017

Having rdmd now behave like this is a good argument. It makes sense to stay consistent within the tools ecosystem.

source/dub/dub.d Outdated
if (m_defaultCompiler.length && m_defaultCompiler.isAbsolute)
return;

auto dubPrefix = m_defaultCompiler.matchFirst(ctRegex!(`^DUB_BINARY_PATH`));
Copy link
Contributor Author

@joakim-noah joakim-noah Sep 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to DUB_BINARY_PATH like you asked.

@@ -14,9 +15,11 @@ if [ -e ~/.dub/settings.json ]; then
die $LINENO 'Found existing user wide DUB configuration. Aborting.'
fi

if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF 'Unknown compiler: foo'; then
if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF 'Unknown compiler: '; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should now pass, but removed the compiler name foo because my new code passes the full path of a compiler next to dub to the settings and this error output. I'm adding more tests for the new behavior and will update the patch soon.

@joakim-noah
Copy link
Contributor Author

Finally spent an hour and updated this pull to test all new code paths, should be ready to merge.

@joakim-noah
Copy link
Contributor Author

Ping, @s-ludwig or @MartinNowak, PR passes most CI, except for some scenarios because of the upstream druntime headers, which are broken unrelated to this pull.

@joakim-noah
Copy link
Contributor Author

Ping, would be good to get this in for the next release, so dub works out of the box with dmd.

@s-ludwig
Copy link
Member

s-ludwig commented Dec 4, 2017

The only issue I can see is that the "$" is missing before "DUB_BINARY_PATH". Otherwise it looks good to merge, the Windows failure is unrelated (we should really clean this up at some point, so that AppVeyor can also be marked as a required check).

@joakim-noah
Copy link
Contributor Author

OK, do you want me to add the $ prefix for the path setting? I just followed what you wrote above.

@s-ludwig
Copy link
Member

s-ludwig commented Dec 4, 2017

Yeah, sorry for that, I was indeed writing ambiguously there. So in the path, it should be written as "$DUB_BINARY_PATH/../foo", so that it looks like an sh style environment variable basically.

@joakim-noah
Copy link
Contributor Author

joakim-noah commented Dec 4, 2017

Will do, in the meantime, I rebased to get the CI to run again.

Update: Added the $ prefix.

put some restrictions on the defaultCompiler specified in a DUB
settings.json, such that it must be a compiler name, a path relative
to dub, or an absolute path, including a tilde-prefixed local path.
Unqualified relative paths are no longer allowed from the settings file,
as they make no sense for how dub invokes the compiler.
@joakim-noah
Copy link
Contributor Author

Is codecov broken, @wilzbach? It says I only cover 45% of my patch with the tests, when I tried to hit all of it.

@joakim-noah joakim-noah merged commit bf095d8 into dlang:master Dec 6, 2017
@joakim-noah joakim-noah deleted the next branch December 13, 2017 06:11
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

Successfully merging this pull request may close these issues.

4 participants