Skip to content

Commit

Permalink
Include source of applications from current project
Browse files Browse the repository at this point in the history
The option `include_src: true` now includes the source code of
applications which are built from this project. That means:

  - the top-level app
  - umbrella apps
  - dependencies

Fix #683
  • Loading branch information
hrubi committed Jun 21, 2019
1 parent ce5b329 commit 593f2fe
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions lib/distillery/releases/assembler.ex
Expand Up @@ -136,7 +136,7 @@ defmodule Distillery.Releases.Assembler do

case include_erts? do
true ->
copy_app(app_dir, target_dir, dev_mode?, include_src?)
copy_app(app_name, app_dir, target_dir, dev_mode?, include_src?)

p when is_binary(p) ->
app_dir =
Expand All @@ -146,20 +146,20 @@ defmodule Distillery.Releases.Assembler do
app_dir
end

copy_app(app_dir, target_dir, dev_mode?, include_src?)
copy_app(app_name, app_dir, target_dir, dev_mode?, include_src?)

_ ->
case Utils.is_erts_lib?(app_dir) do
true ->
:ok

false ->
copy_app(app_dir, target_dir, dev_mode?, include_src?)
copy_app(app_name, app_dir, target_dir, dev_mode?, include_src?)
end
end
end

defp copy_app(app_dir, target_dir, true, _include_src?) do
defp copy_app(_app_name, app_dir, target_dir, true, _include_src?) do
case File.ln_s(app_dir, target_dir) do
:ok ->
:ok
Expand All @@ -169,7 +169,7 @@ defmodule Distillery.Releases.Assembler do
end
end

defp copy_app(app_dir, target_dir, false, include_src?) do
defp copy_app(app_name, app_dir, target_dir, false, include_src?) do
case File.mkdir_p(target_dir) do
{:error, reason} ->
{:error, {:assembler, :file, {:copy_app, target_dir, reason}}}
Expand All @@ -184,7 +184,9 @@ defmodule Distillery.Releases.Assembler do
["ebin", "include", "priv"]
end

Path.wildcard(Path.join(app_dir, "*"))
extra_source_dirs = project_app_src_dirs(app_name)

(Path.wildcard(Path.join(app_dir, "*")) ++ extra_source_dirs)
|> Enum.filter(fn p -> Path.basename(p) in valid_dirs end)
|> Enum.each(fn p ->
t = Path.join(target_dir, Path.basename(p))
Expand Down Expand Up @@ -224,6 +226,31 @@ defmodule Distillery.Releases.Assembler do
{:error, err}
end

# Finds sources for `app_name`. This is used for applications built from
# this project, where the source code lies in a different location than the
# compiled files.
defp project_app_src_dirs(app_name) do
case project_app_src_root(app_name) do
nil -> []
path -> Path.wildcard(Path.join(path, "{lib,src}"))
end
end

# Returns a path of the source code directory for application built
# from this project. That includes:
# - top-level application
# - umbrella application
# - dependencies
#
# Returns `nil` otherwise.
defp project_app_src_root(app_name) do
if not Mix.Project.umbrella?() && Mix.Project.get().project[:app] == app_name do
File.cwd!()
else
Map.get(Mix.Project.deps_paths(), app_name)
end
end

# Creates release metadata files
defp write_release_metadata(%Release{name: name} = release) do
resource_path =
Expand Down

0 comments on commit 593f2fe

Please sign in to comment.