Skip to content

Commit

Permalink
run the http provider before attempting to compile if the package was…
Browse files Browse the repository at this point in the history
… pulled from hex
  • Loading branch information
mobileoverlord committed Dec 14, 2016
1 parent ac6be5a commit 4077d37
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
15 changes: 13 additions & 2 deletions lib/mix/tasks/firmware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@ defmodule Mix.Tasks.Firmware do

firmware_config = Application.get_env(:nerves, :firmware)

system_path = System.get_env("NERVES_SYSTEM") || raise """
system_path = System.get_env("NERVES_SYSTEM") || Mix.raise """
Environment variable $NERVES_SYSTEM is not set
"""

System.get_env("NERVES_TOOLCHAIN") || raise """
System.get_env("NERVES_TOOLCHAIN") || Mix.raise """
Environment variable $NERVES_TOOLCHAIN is not set
"""

rel_config =
File.cwd!
|> Path.join("rel/config.exs")

unless File.exists?(rel_config) do
Mix.raise """
You are missing a release config file. Run nerves.release.init task first
"""
end

Mix.Task.run "compile", []
Mix.Task.run "release", ["--verbosity=#{verbosity}"]

Expand Down
2 changes: 1 addition & 1 deletion lib/nerves/env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Nerves.Env do
"""
@spec start() :: Agent.on_start
def start do
Agent.start_link fn -> load_packages() end, name: __MODULE__
Agent.start_link(fn -> load_packages() end, name: __MODULE__)
end

@doc """
Expand Down
20 changes: 15 additions & 5 deletions lib/nerves/package.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,19 @@ defmodule Nerves.Package do
"""
@spec artifact(Nerves.Package.t, Nerves.Package.t) :: :ok
def artifact(pkg, toolchain) do
{mod, opts} = pkg.provider
if mod.artifact(pkg, toolchain, opts) == :ok do
ret =
case pkg.provider do
{mod, opts} -> mod.artifact(pkg, toolchain, opts)
providers when is_list(providers) ->
Enum.reduce(providers, nil, fn ({mod, opts}, ret) ->
if ret != :ok do
mod.artifact(pkg, toolchain, opts)
else
ret
end
end)
end
if ret == :ok do
Path.join(Artifact.dir(pkg, toolchain), @checksum)
|> File.write!(checksum(pkg))
end
Expand Down Expand Up @@ -216,7 +227,7 @@ defmodule Nerves.Package do
config = Mix.Project.config[:artifacts] || []

case Keyword.get(config, app) do
nil -> {provider_mod(type), []}
nil -> [{Providers.HTTP, []}, {provider_mod(type), []}]
opts -> provider_opts(opts)
end
end
Expand Down Expand Up @@ -254,15 +265,14 @@ defmodule Nerves.Package do
end

defp dep_type(pkg) do
deps_paths = Mix.Project.deps_paths
deps_paths = Mix.Project.deps_paths()
case Map.get(deps_paths, pkg) do
nil ->
:project
path ->
deps_path =
File.cwd!
|> Path.join(Mix.Project.config[:deps_path])
|> Path.expand
if String.starts_with?(path, deps_path) do
:hex
else
Expand Down
5 changes: 4 additions & 1 deletion lib/nerves/package/providers/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ defmodule Nerves.Package.Providers.HTTP do

defp unpack({:error, _} = error, _, _), do: error
defp unpack({:ok, tar}, artifact, destination) do
shell_info "Unpacking #{artifact}"
shell_info """
Unpacking #{artifact}
To #{destination}
"""
tmp_path = Path.join(destination, ".tmp")
File.mkdir_p!(tmp_path)
tar_file = Path.join(tmp_path, artifact)
Expand Down

0 comments on commit 4077d37

Please sign in to comment.