Skip to content

detect builder from prefetched github repos #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/deps_nix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule DepsNix do
:ok <- File.write("#{dir}/deps-nix-tarball", body),
{_, 0} <- System.cmd("tar", ["-xf", "#{dir}/deps-nix-tarball"], cd: dir),
{output, 0} <- System.cmd("nix", ["hash", "path", path]) do
String.trim_trailing(output)
{String.trim_trailing(output), find_builder_from_path(path)}
end
end

Expand Down Expand Up @@ -124,6 +124,14 @@ defmodule DepsNix do
end
end

defp find_builder_from_path(path) do
cond do
File.exists?(Path.join(path, "mix.exs")) -> "buildMix"
File.exists?(Path.join(path, "rebar.config")) -> "buildRebar3"
true -> :unknown
end
end

@spec to_opts({list(), any(), any()}) :: Options.t()
defp to_opts({[], _, _}) do
%Options{
Expand Down
15 changes: 11 additions & 4 deletions lib/deps_nix/derivation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,28 @@ defmodule DepsNix.Derivation do
def from(%Mix.Dep{scm: Mix.SCM.Git} = dep, options) do
{:git, url, rev, _} = dep.opts[:lock]

prefetcher = options.github_prefetcher

case parse_git_url(url) do
[owner: owner, repo: repo] ->
prefetcher = options.github_prefetcher

{hash, builder} =
if prefetcher do
prefetcher.(owner, repo, rev)
else
{"", "buildMix"}
end

fetcher = %FetchFromGitHub{
owner: owner,
repo: repo,
rev: rev,
hash: if(prefetcher, do: prefetcher.(owner, repo, rev), else: "")
hash: hash
}

new(dep,
version: rev,
src: fetcher,
builder: "buildMix",
builder: builder,
app_config_path: app_config_path(options)
)

Expand Down
2 changes: 1 addition & 1 deletion test/deps_nix/derivation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ defmodule DepsNix.DerivationTest do
Derivation.from(dep, %DepsNix.Options{
github_prefetcher: fn
"code-supply", "mudbrick", ^rev ->
generated_hash
{generated_hash, "buildMix"}
end
})
end
Expand Down
20 changes: 18 additions & 2 deletions test/deps_nix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ defmodule DepsNixTest do
"code-supply",
"deps_nix",
"8a6c3537c958fe3fd1810d56bdee6c13fb35d089"
) == "sha256-zJOkGOSBBA0Y9HPRmwPmBpqaqsoRa0oR7VjMMyukvX4="
) == {"sha256-zJOkGOSBBA0Y9HPRmwPmBpqaqsoRa0oR7VjMMyukvX4=", "buildMix"}
end

test "works for repos with ../ relative symlinks" do
assert DepsNix.github_prefetcher(
"Strech",
"avrora",
"a2df4d8f177dacc7be24aa3e6bc76b52c3f114a9"
) == "sha256-msktKtQGBhe2UrZr9uiKiRFCiXCkFa0+zbOy8KQIhc4="
) == {"sha256-msktKtQGBhe2UrZr9uiKiRFCiXCkFa0+zbOy8KQIhc4=", "buildMix"}
end

test "detects rebar3-only repositories" do
assert DepsNix.github_prefetcher(
"klarna",
"mnesia_eleveldb",
"af6d0556a78aec2918b3471f0c85121402a1f5b1"
) == {"sha256-+ZZ5Uyoe/HK0wL0ev1vn9Tuiaps4X88izETtuRszKYE=", "buildRebar3"}
end

test "prefers buildMix over buildRebar3 for repos that have both" do
assert DepsNix.github_prefetcher(
"erlef",
"oidcc",
"fdf45b06d79813c7110171c5c6d334394c2f1190"
) == {"sha256-QUwRH9GWMTrG2HsFqiPNNKm+K5+cwPigdtlx9OUNK58=", "buildMix"}
end

test "fails for nonsense repos" do
Expand Down