shahryarjb
Is there a way put env in compile time and use it in runtime?
Hello. Based on a reporting bug (which was not bug
), @josevalim said I can not use Application.put_env inside compile time macro like this:
This makes it so Mix believes the build of your dependency stale because a compile env flag is changing.
quote do
[:validate_derive, :sanitize_derive]
|> Enum.each(fn item ->
if is_nil(Application.compile_env(:guarded_struct, item)) do
Application.put_env(:guarded_struct, item, Keyword.get(unquote(opts), item))
end
end)
But I have question. is there a way to put env in compile time and access it inside run-time?
Thank you in advance.
Refs:
- Add warning around runtime modification of compile env · elixir-lang/elixir@bd99dcc · GitHub
- Mix cannot build a macro library used in another library when macro is called more than once in project modules · Issue #13699 · elixir-lang/elixir · GitHub
- The dependency build is outdated error with getting lib from Github branch - #2 by shahryarjb
Most Liked
LostKobrakai
I don’t think so, but even if there would I’d argue this is abusing the system. Config is an input to code compilation and running its result. It’s not an output of compiling code.
D4no0
Stop torturing poor elixir and make your own language already
.
al2o3cr
I haven’t entirely traced how that env is being used, but this one looks like you need a different approach for getting metadata to ValidationDerive:
At an absolute minimum, you’d need to be able to distinguish “this module that said guardedstruct wants validation” from “this OTHER module that said guardedstruct doesn’t want validation” - a single boolean in the application env isn’t sufficient for that.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










