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

Fixing 'nim' binary could not be found in PATH on OS X #52

Merged
merged 2 commits into from
Jun 5, 2017
Merged

Fixing 'nim' binary could not be found in PATH on OS X #52

merged 2 commits into from
Jun 5, 2017

Conversation

claudiiii
Copy link
Contributor

The output of readlink without the -f flag is a non absolute path. As a result, if you used brew to install nim, the correct binary can't be detected and the error message is shown.

See https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac#4031502 on the readlink problem and a solution.

My solution is a bit hacky but should work on all OS X versions.

src/nimUtils.ts Outdated
if (process.platform === 'darwin') {
// dirty hack because the version of readlink that ships with osx doesn't support the -f flag
// from https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac#4031502
buff = cp.execFileSync('python', ['-c', 'import os,sys;print(os.path.realpath(sys.argv[1]))', _pathesCache[tool]]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think that use python here is a good idea may be it will enough construct full path from _pathesCache[tool] + cp.execFileSync('readlink', [_pathesCache[tool]]) in case of relative symlink

Copy link
Contributor Author

@claudiiii claudiiii Jun 4, 2017

Choose a reason for hiding this comment

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

You are totally right, depending on python is not a good idea.
I fixed it as you suggested, by appending the relative path to the symlink path in 1d328ad.

src/nimUtils.ts Outdated
// dirty hack because the version of readlink that ships with osx doesn't support the -f flag
// from https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac#4031502
buff = cp.execFileSync('python', ['-c', 'import os,sys;print(os.path.realpath(sys.argv[1]))', _pathesCache[tool]]);
nimPath = _pathesCache[tool].slice(0, _pathesCache[tool].length - 3) + cp.execFileSync('readlink', [_pathesCache[tool]]).toString().trim();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it will not work for all cases becasue link can be relative or absolute and you need prepend _pathesCache[tool].slice(0, _pathesCache[tool].length - 3) only in case of relative path (not start with / )

Copy link
Contributor Author

@claudiiii claudiiii Jun 5, 2017

Choose a reason for hiding this comment

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

As far as I can tell, readlink always returns a path relative to the parent of the symlink and thus will never have a / in front.
But as a general question, why do you need to resolve the symlink for nim anyway? It works totally fine for me if I use the path to nim thats in my PATH.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It need locate nimsuggest executable that are placed together with nim executable

@kosz78 kosz78 merged commit ac262ee into pragmagic:master Jun 5, 2017
@nonylene
Copy link

I'm sorry, but when will this feature be released?

@kosz78
Copy link
Collaborator

kosz78 commented Jun 26, 2017

Sorry for delay, it was released recently in 0.5.24 version

@nonylene
Copy link

Thank you very much!

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.

3 participants