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

Add support for new rebar3 output dir option #10018

Merged
merged 3 commits into from
May 13, 2020

Conversation

starbelly
Copy link
Contributor

@starbelly starbelly commented May 6, 2020

rebar3 as of 3.13.2 now supports a --output directory option which allows mix going forward to use said option and put build artifacts in _build which should result and less rebuilding of artifacts and/or better caching of artifacts. Details here: erlang/rebar3#2237

In order to make use of said feature we must put a variable in the system's environment that shall hold the desired output path. rebar3 will recognize said environment variable going forward starting at version 3.14 (yet to be released).

  • Updated Mix.Tasks.Deps.Compile to put REBAR_BARE_COMPILER_OUTPUT_DIR in system env with the dependency path as the value for use by rebar3.

lib/mix/lib/mix/rebar.ex Outdated Show resolved Hide resolved
@doc """
Returns the version of the available `rebar` command if any
"""
@rebar_vsn_regex ~r/^## Rebar3 (?<vsn>[\w\.\d]+)$/m
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix isn't always ##. That is only for the ones that are installed with rebar3 local install.

The escript will have %%. And I just realized only the non-escript has a space there. escript is %%Rebar3 <vsn>.

Copy link

@ferd ferd May 6, 2020

Choose a reason for hiding this comment

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

The escript is %% Rebar3 version; the actual escript generator thing inserts the space itself:

→ head -n2 rebar3
#!/usr/bin/env escript
%% Rebar3 3.14.0-rc1

Otherwise it is true that it sometimes is ## and sometimes is %%. Also if you use asdf, the shim spacing is different:

$ cat `which rebar3`
#!/usr/bin/env bash
# asdf-plugin: rebar 3.13.2
exec /usr/local/opt/asdf/bin/asdf exec "rebar3" "$@"

Also the thing to worry about is the semver-like pre-release flags:

%% Rebar3 3.14.0-rc1

So if you want to be sure, the regex likely looks like ^(##|%%).*[Rr]ebar3? (?<vsn>[\w\d.-]+)$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ferd Does the asdf shim have one or octothorps? Not sure if you typed that out or if it was copy/paste.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the asdf plugin should affect this though. Doesn't mix always use it's own copy of rebar and not the system one?

Copy link
Member

@michalmuskala michalmuskala May 6, 2020

Choose a reason for hiding this comment

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

Ah, sorry for the noise. I now see there's an option to use rebar from an env var. In that case could it make sense to always require new rebar when running the "local" one, but just call --version on the global one? How slow is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checked with someone using asdf, mix should not end up referring to a shim, just escript.

Copy link
Member

Choose a reason for hiding this comment

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

I am still worried about the implications of this version check. It means folks can be using the same Rebar version but installed in different ways and they won't get the same behaviour. :/ Whatever check we do it is impossible to guarantee it will work on all the different ways rebar can be installed.

Copy link

Choose a reason for hiding this comment

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

That is correct. But all of that is done as a nicety so mix doesn't have to call and cache the result of rebar3 version which successfully prints the full version since before the first alpha release, and which would be the true safest approach.

end

defp rebar_compile_cmd_for(vsn, rebar_path, build_path, lib_path) do
case Version.compare("3.12.2", vsn) do
Copy link

@ferd ferd May 6, 2020

Choose a reason for hiding this comment

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

3.13.2 is the first one to support to be version annotated; 3.13.1 the first one to support the -o option. The moment you got an annotation you got something newer.

Copy link
Contributor Author

@starbelly starbelly May 6, 2020

Choose a reason for hiding this comment

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

Yeah, I wondered if doing the Version comparison was overkill... sounds like it. Should probably still parse the Version to make sure it wasn't junk but that should happen in rebar_vsn/1. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to do a comparison, you just have to check if it is exists.

@starbelly
Copy link
Contributor Author

So, I booted up a VM with windows 10 and I could not replicate the problem I'm seeing in CI in that, I used a similar path with escapes and so forth and was able to File.stream!/1 successfully.

That said, I could not run the tests myself as I could not get elixir to compile per a unicode properties compilation error. I can't paste the error, but I took a screen shot. However, I don't think the compilation error I got is relevant at all, but can share here if desired.

My thought at the moment is that this problem is limited to the CI environment for windows or possibly the test setup itself (i.e., it may be the file isn't actually there).

@josevalim
Copy link
Member

Hi @starbelly, a quick heads up: we talked about this in the Build and Packaging WG and we agreed to go down the environment variable route. So first we will add the environment variable support to Rebar 3.14 and then pass it here in Mix.

Regarding the Windows problem, we had the same issue on another test in the past, and we just stopped running that particular test on Windows. Windows is a bit tricky when it comes to removing files: I believe it takes a while for Windows to notice the file is no longer being used, which leads to races.

@tsloughter
Copy link
Contributor

May as well add the env variable to mix now. Sooner it is in the better for users.

@starbelly
Copy link
Contributor Author

Right, so I'm synced up... Are we wanting to add said env var check in this PR?

@josevalim
Copy link
Member

We will set the variable from Mix but rebar3 needs to be patched to read from it.

@tsloughter
Copy link
Contributor

@josevalim right, but it doesn't need to be patched before mix starts setting the environment variable.

@josevalim
Copy link
Member

As long as we agree on the name. :)

@starbelly starbelly force-pushed the support-rebar-output-dir-opt branch from 80f7531 to d39a3d6 Compare May 12, 2020 00:54
rebar3 as of 3.13.2 now supports a --output directory option which
allows mix going forward to use said option and put build artifacts in
_build which should result and less rebuilding of artifacts and/or
better caching of artifacts. Details here: erlang/rebar3#2237

In order to make use of said feature we must put a variable in the system's environment that shall hold the
desired output path. rebar3 will recognize said environment variable going forward starting at version 3.14
(yet to be released).

- Updated Mix.Tasks.Deps.Compile to put REBAR_BARE_COMPILER_OUTPUT_DIR in system env with the dependency path as the
value for use by rebar3.
@starbelly starbelly force-pushed the support-rebar-output-dir-opt branch from d39a3d6 to ddc3e3f Compare May 12, 2020 00:56
@starbelly
Copy link
Contributor Author

@josevalim @tsloughter @ferd The PR has been updated to just putting the env var in place. Updated description of issue and commit message.

@starbelly starbelly marked this pull request as ready for review May 12, 2020 00:58
@@ -189,7 +189,10 @@ defmodule Mix.Tasks.Deps.Compile do
lib_path = Path.join(config[:env_path], "lib/*/ebin")

env = [{"REBAR_CONFIG", config_path}, {"TERM", "dumb"}]
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing it with System.put_env, you can define the environemnt variable here. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤣 Got it!

@josevalim josevalim merged commit fc9f769 into elixir-lang:master May 13, 2020
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

josevalim added a commit that referenced this pull request Dec 21, 2020
This option will be enabled on Elixir v1.12 instead.

This reverts commit fc9f769.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants