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

Env for providers #1706

Merged
merged 4 commits into from
Feb 27, 2018
Merged

Env for providers #1706

merged 4 commits into from
Feb 27, 2018

Conversation

cjkjellander
Copy link
Contributor

This adds and exports the necessary parts to use env variables like REBAR_DEPS_DIR inside provider hooks. It addresses this issue in port_compiler: blt/port_compiler#30

There will be a separate pull request in that repo as well.

This branch is based off of #1698 and should not be merged before that one. But in order to use env variables in port_specs of deps, you actually have to run the port_hooks for the deps. So this depends on the mentioned pull request.

@cjkjellander
Copy link
Contributor Author

oops, messed up the tests, gotta fix that.

@ferd
Copy link
Collaborator

ferd commented Feb 22, 2018

@cjkjellander sorry for the long delay. Do you think you could rebase this PR off master so the review is simpler to track through?

@cjkjellander
Copy link
Contributor Author

of course!

Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

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

So I've given it a read and checked the issues, and I think there's a possible alternative implementation that should be safer over time, and require a bit less memory usage.

Please check through my comments and let me know what you think.

@@ -453,6 +453,24 @@ reread_config(ConfigList) ->
"and will be ignored.", [])
end.

%% @doc Given env. variable `FOO' we want to expand all references to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has this function just been moved from internal to non-internal code sections without having been exported?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nevermind, just saw it was already exported without having previously been moved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that confused me as well, that was the reason for the failing tests above. I exported it but it already was exported it turns out.

Env = create_env(State, Opts),
State2 = rebar_state:env(State1, Env),
run_provider_hooks_(Dir, Type, Command, Providers,
TypeHooks, State2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what this provides here. So we create the ENV and store it in the provider? The bug as illustrated at blt/port_compiler#30 seems to be that https://github.com/blt/port_compiler/pull/38/files#diff-190510d6d34e2aff57877104e5ec0246R152 uses the ENV values to just expand the ENV themselves.

Is there a reason why we couldn't just expose create_env as a function instead (maybe stick it in a rebar_env module or something like that) and let the plugin call it and expand it however it wants based on the current opts and config? It sounds like it would be far less risky than having to track and update the env value in the state record along with everything else if we make it so whoever needs it generates it on-demand.

@cjkjellander
Copy link
Contributor Author

ok, fixed it according to review.

@cjkjellander
Copy link
Contributor Author

cjkjellander commented Feb 26, 2018

I'm not so sure about this solution. Does the providers have access to Opts? I'm trying to reimplement the fix blt/port_compiler#30 and the Opts in there isn't even a dict.

Gotta read some code....

The two ENVs that need Opts is
{"REBAR_GLOBAL_CACHE_DIR", filename:absname(rebar_dir:global_cache_dir(Opts))}, {"REBAR_SRC_DIRS", join_dirs(BaseDir, rebar_dir:all_src_dirs(Opts))},

@ferd
Copy link
Collaborator

ferd commented Feb 26, 2018

Opts can be two possible structures depending on who calls it (legacy leftovers!) but usually rebar_opts module allows transparent usage there.

@cjkjellander
Copy link
Contributor Author

I'm doing some cleaning up. I'll be done in 10 minutes.

@cjkjellander
Copy link
Contributor Author

There. I've completed the port_compile part to use this new interface and it seems to work both as a top level app and a dependency so now providers should be able to get the env and use them in specs and when using external programs.

@cjkjellander
Copy link
Contributor Author

btw, this is the original repo that we were having trouble converting to rebar3: https://github.com/campanja/csv/tree/rebar3-build

@ferd
Copy link
Collaborator

ferd commented Feb 27, 2018

Yeah that sounds like a much more manageable change from the rebar3 perspective. Merging.

@ferd ferd merged commit 2917ede into erlang:master Feb 27, 2018
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.

2 participants