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.
Hi there,
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:
/app/_build/prod/lib/avatarex/priv/sets/birdy/body/body_1.png
but are different from the paths that are used at runtime:
/app/lib/avatarex-0.2.0/priv/sets/birdy/body/body_1.png
I do need to be able to File.ls
the /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 /app/lib/...
.
I thought this may also be related to me not understanding how /app/_build/prod/lib
becomes /app/lib
upon release.
Thanks,
David
Resources I’ve Reviewed:
- Using static files in a library
- build embedded plataformatec blog post
- Wrong path in Elixir after release with distillery
:code.priv_dir(:my_app)
points topriv
directory in_build
- Google Groups: What is
priv
- 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