Skip to content

hex: handle support files with macro in umbrellas#4213

Merged
jurre merged 2 commits intodependabot:mainfrom
nirev:hex-replace-dir-macro
Oct 11, 2021
Merged

hex: handle support files with macro in umbrellas#4213
jurre merged 2 commits intodependabot:mainfrom
nirev:hex-replace-dir-macro

Conversation

@nirev
Copy link
Copy Markdown
Contributor

@nirev nirev commented Sep 10, 2021

This PR adds support for handling required files when a __DIR__ macro is used.
It also handles required files in umbrellas

The test case added extends the umbrella context with the following change:
apps/bank_web/mix.exs

defmodule BankWeb.Mixfile do
  use Mix.Project
  @something Code.eval_file("../../evaled.exs", __DIR__)

  def project do
    ..

docs for __DIR__: https://hexdocs.pm/elixir/Kernel.SpecialForms.html#__DIR__/0

@nirev nirev requested a review from a team as a code owner September 10, 2021 00:36
path = Pathname.new(File.join(*support_file_args.compact.reverse)).
cleanpath.to_path
fetch_file_from_host(path).tap { |f| f.support_file = true }
mixfiles = [mixfile] + subapp_mixfiles
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

scans mix.exs files in umbrellas for support files too

mixfiles.flat_map do |mixfile|
mixfile_dir = mixfile.path.sub("/mix.exs", "").delete_prefix("/")

mixfile.content.gsub(/__DIR__/, "\"#{mixfile_dir}\"").scan(SUPPORT_FILE).map do |support_file_args|
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

replaces the __DIR__ macro with the file dirname, so that in /apps/my_app/mix.exs

Code.eval_file("../../script.exs", __DIR__)

becomes

Code.eval_file("../../script.exs", "/apps/my_app")

@nirev
Copy link
Copy Markdown
Contributor Author

nirev commented Oct 11, 2021

I haven't got any comments here, so wondering if this contribution is something that the maintainers think it's worth adding.

I had an issue with a client's repo that was using something like this and I've changed it not eval the file when running on dependabot, but I think it would be cleaner if dependabot handled it.

@jurre
Copy link
Copy Markdown
Member

jurre commented Oct 11, 2021

I haven't got any comments here, so wondering if this contribution is something that the maintainers think it's worth adding.

I had an issue with a client's repo that was using something like this and I've changed it not eval the file when running on dependabot, but I think it would be cleaner if dependabot handled it.

Yep it definitely looks useful to me, thanks @nirev

In some ecosystems we've started just performing a (shallow) clone vs this custom file fetching logic, and I contemplated suggesting that, but I think it might end up being a larger change that's a bit more involved to roll out, so this seems like a good fix to me 👍

@jurre jurre merged commit 6889b39 into dependabot:main Oct 11, 2021
@nirev
Copy link
Copy Markdown
Contributor Author

nirev commented Oct 11, 2021

Thank you, @jurre!

@nirev nirev deleted the hex-replace-dir-macro branch October 11, 2021 16:30
@jurre jurre mentioned this pull request Oct 14, 2021
@brrygrdn brrygrdn mentioned this pull request Oct 27, 2021
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