TL;DR: How to ensure that file paths specified in a library when compiled in a macro reflect correct paths at release.
/app/_build/prod/lib/library_name/priv/ when compiled vs
/app/lib/library_name-version/priv/ when released.
Working on an avatar generation library:
Avatarex - Generate unique, reproducible avatars from hashed strings (*hat tip to @Eiji for help in the rewrite)
I’m a bit confused as to how to ensure that the image asset paths which are being generated at compile time, as part of a using macro, reflect where they’ll actually be at runtime.
So paths that are generated at compile time:
:avatarex |> :code.priv_dir() |> Path.join("sets") |> ...
corresponds to locations that exist during compilation:
but are different from the paths that are used at runtime:
I do need to be able to
/app/_build/prod/lib/avatarex/priv/sets/birdy/body/ path at compile time to then generate the list of available images in that directory, but then again at runtime they need to look in
I thought this may also be related to me not understanding how
/app/lib upon release.
Resources I’ve Reviewed:
- Using static files in a library
- build embedded plataformatec blog post
- Wrong path in Elixir after release with distillery
- Google Groups: What is
- SO: Elixir httpserver : priv_dir returns something in _build directory, thus I can’t send static files that are in source directory
- How to include static assets in an Elixir application
- Accessing the priv folder from mix release