Skip to content

Store embed_templates root relative to cwd for __mix_recompile__? - #17

Closed
onnimonni wants to merge 1 commit into
phoenixframework:mainfrom
onnimonni:relocatable-recompile-check
Closed

onnimonni wants to merge 1 commit into
phoenixframework:mainfrom
onnimonni:relocatable-recompile-check

Conversation

@onnimonni

@onnimonni onnimonni commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #16. The hash is now relocatable, but __mix_recompile__? still globs the absolute root captured at compile time. In a copy of the project that reuses _build (git worktree or copy-on-write clone, compiled with check_cwd: false / --no-check-cwd, Elixir 1.19.2+), it looks for templates in the original checkout, so a template added in the copy is silently never compiled.

Fix: store the root with Path.relative_to_cwd/1. __mix_recompile__? runs in the project directory, so it resolves against the copy. Roots outside the project stay absolute, and a relative root hashes the same as an absolute one.

Test: compile in directory A, copy it to B, add a template in B, then __mix_recompile__?/0 must return true. It fails on main. The test changes the cwd, so the test module is now async: false. Also adds /tmp/ to .gitignore for the @tag :tmp_dir fixtures.

Context: phoenixframework/phoenix#6855

Second commit: @external_resource is persisted in the module's attributes, and it embedded the absolute template path. Elixir documents @external_resource paths as relative to the project directory, and Mix already resolves them that way, so they are now stored relative. The test asserts they are relative; it fails without the change.

In a copy of the project (git worktree, copy-on-write clone) compiled with
check_cwd: false, __mix_recompile__? looked for new templates in the original
directory, so a template added in the copy was silently not compiled.
@josevalim

Copy link
Copy Markdown
Member

Thanks, I pushed the cwd fix directly!

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