asdf-elixir icon indicating copy to clipboard operation
asdf-elixir copied to clipboard

Add auto install of hex and rebar including path of the freshly installed elixir

Open tverlaan opened this issue 5 years ago • 7 comments

The problem was that the newly installed elixir wasn't in the path. This is because reshim happens after installation of elixir. There is no default post-install which could take place after the reshim.

I tested this on a fresh install and it worked.

@dobs would you be so kind to confirm if this fix is proper and working in your environment? Sorry for the trouble :)

tverlaan avatar Sep 18 '20 09:09 tverlaan

@tverlaan can you rebase on master so the Travis build runs correctly now?

Stratus3D avatar Sep 18 '20 14:09 Stratus3D

Perfect! It fails. I was actually expecting this since the erlang that's part of the default Xenial doesn't seem to want to run elixir (and OSX doesn't have erl at all).

tverlaan avatar Sep 18 '20 14:09 tverlaan

Thanks for iterating on this @tverlaan.

Unfortunately there still appear to be some quirks, at least when testing locally:

$ asdf plugin-add elixir ../asdf-elixir

Cloning into '/Users/dobs/.asdf/plugins/elixir'...
done.

$ asdf install

erlang 22.1 is already installed
==> Checking whether specified Elixir release exists...
==> Downloading 1.9.4-otp-22 to /var/folders/8t/bcy9yfg90c56_4m_36wmtyrm0000gp/T//elixir-precompiled-1.9.4-otp-22.zip
** Resuming transfer from byte position 5274462
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
==> Copying release into place
** (CompileError) config/config.exs:10: module Config is not loaded and could not be found
    (elixir) lib/code.ex:232: Code.eval_string/3
    (mix) lib/mix/config.ex:220: Mix.Config.eval!/2
** (CompileError) config/config.exs:10: module Config is not loaded and could not be found
    (elixir) lib/code.ex:232: Code.eval_string/3
    (mix) lib/mix/config.ex:220: Mix.Config.eval!/2

I can whip up and share a quick bootstrap project and some commands to reproduce if necessary. I'm guessing this is another path issue?

It does make me somewhat cautious of this change more broadly -- ~~it assumes you're already inside of a valid Elixir project in order to install Elixir. It would also cause issues for anyone working on poncho-style projects.~~ EDIT: I'm wrong about installing outside of an existing project -- that appears to work. But project specifics look like they can trip this up.

dobs avatar Sep 18 '20 15:09 dobs

Thanks a lot @dobs for helping me test! I'm afraid you're right. I'll try to reproduce and fix it, if you can provide something that would speed me up.

On the first iteration I was considering making it configurable with an env var. Another option would be an additional file in ~/ similar to asdf-nodejs. I also found an option to do it with ~/.asdfrc, however that requires a bit more fiddling.

tverlaan avatar Sep 18 '20 15:09 tverlaan

@dobs & @Stratus3D , I found some time to work on this again. I took a different approach which is 1, a bit more flexible and 2, not changing the default behavior. In the end it's similar to the approach as in asdf-nodejs.

I tested it in existing projects & outside of any projects. ~~However if a project contains a bug in the mix.exs file or in the project config it will break. This is because mix always evaluates the project file and configuration in order to load any aliases (and probably other things). I'm not sure if I should cater for this as you can always remove the .default-mix-commands file or fix the bug in your project.~~

tverlaan avatar Nov 10 '20 17:11 tverlaan

Thanks @tverlaan ! I like this approach. Do any of the other Elixir version managers follow this pattern?

@danhper what do you think of this?

Stratus3D avatar Nov 10 '20 20:11 Stratus3D

This feature is not supported by any of the other version managers afaict.

tverlaan avatar Nov 10 '20 22:11 tverlaan

Hi! I just stumbled on this PR while looking to see if this feature existed. I was wondering if someone found a showstopper since the last post or whether everyone just got busy. If it's the latter and it's basically read to go, perhaps I can help test so that it could be merged?

fhunleth avatar Nov 16 '22 14:11 fhunleth

I've been running my version ever since and it works like a charm every single time. I even forget about it until I install a newer version of elixir.

❯ cat .default-mix-commands
local.rebar
local.hex
archive.install hex phx_new

tverlaan avatar Nov 16 '22 19:11 tverlaan

I'm working to get this merged this week. But first I need to finish getting this project setup on Github actions which will include adding some code quality checks. I want to make sure these changes pass the new checks before I merge.

Stratus3D avatar Nov 16 '22 20:11 Stratus3D

@Stratus3D Thank you! It's hard to convey how much time that asdf and this plugin have saved me. I really appreciate all of the work that you've put into this. Also, thanks @tverlaan for implementing this feature! I was on the verge of implementing it and super glad that I saw your PR.

fhunleth avatar Nov 16 '22 21:11 fhunleth

Thanks @fhunleth , glad it's been helpful!

@tverlaan I just merged the updated Github workflow. Can you rebase onto latest master and fix any linter warnings? Checks should run for every PR update now.

Stratus3D avatar Nov 17 '22 17:11 Stratus3D

Thanks for the PR @tverlaan ! And thanks for updating it to pass with the new CI process. Sorry for taking over 2 years to get this merged 😬

Stratus3D avatar Nov 18 '22 14:11 Stratus3D

Better late than never 😁 . Thanks!!

tverlaan avatar Nov 18 '22 14:11 tverlaan