Skip to content

Commit aa48f6a

Browse files
author
José Valim
committed
Ensure priv/include are copied on Windows even if source did not change
Closes #2908 Signed-off-by: José Valim <[email protected]>
1 parent b5e2d45 commit aa48f6a

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/mix/lib/mix/tasks/deps.compile.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ defmodule Mix.Tasks.Deps.Compile do
6464
"(pass :compile as an option to customize compilation, set it to false to do nothing)"
6565
end
6666

67-
unless mix?(dep), do: build_structure(dep, config)
67+
# Always build the structure even for Mix projects
68+
# because if nothing was compiled, we need to re-copy
69+
# priv/include when symlinks are not available.
70+
build_structure(dep, config)
6871
touch_fetchable(scm, opts[:build])
6972
compiled
7073
end)
@@ -170,15 +173,15 @@ defmodule Mix.Tasks.Deps.Compile do
170173
build_path = Path.dirname(opts[:build])
171174
Enum.each Mix.Dep.source_paths(dep), fn source ->
172175
app = Path.join(build_path, Path.basename(source))
173-
build_structure(source, app, config)
176+
build_structure(dep, source, app, config)
174177
Code.prepend_path(Path.join(app, "ebin"))
175178
end
176179
end
177180

178-
defp build_structure(dest, build, config) do
181+
defp build_structure(dep, dest, build, config) do
179182
File.cd! dest, fn ->
180183
config = Keyword.put(config, :app_path, build)
181-
Mix.Project.build_structure(config, symlink_ebin: true)
184+
Mix.Project.build_structure(config, symlink_ebin: not mix?(dep))
182185
end
183186
end
184187

lib/mix/lib/mix/utils.ex

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,33 +300,31 @@ defmodule Mix.Utils do
300300
"""
301301
def symlink_or_copy(source, target) do
302302
if File.exists?(source) do
303-
source_list = String.to_char_list(source)
303+
# Relative symbolic links on windows are broken
304+
link = case :os.type do
305+
{:win32, _} -> source
306+
_ -> make_relative_path(source, target)
307+
end |> String.to_char_list
308+
304309
case :file.read_link(target) do
305-
{:ok, ^source_list} ->
310+
{:ok, ^link} ->
306311
:ok
307312
{:ok, _} ->
308313
File.rm!(target)
309-
do_symlink_or_copy(source, target)
314+
do_symlink_or_copy(source, target, link)
310315
{:error, :enoent} ->
311-
do_symlink_or_copy(source, target)
316+
do_symlink_or_copy(source, target, link)
312317
{:error, _} ->
313318
_ = File.rm_rf!(target)
314-
do_symlink_or_copy(source, target)
319+
do_symlink_or_copy(source, target, link)
315320
end
316321
else
317322
{:error, :enoent}
318323
end
319324
end
320325

321-
defp do_symlink_or_copy(source, target) do
322-
323-
# relative symbolic links on windows are broken
324-
source_path = case :os.type do
325-
{:win32, _} -> source
326-
_ -> make_relative_path(source, target)
327-
end
328-
329-
case :file.make_symlink(source_path, target) do
326+
defp do_symlink_or_copy(source, target, link) do
327+
case :file.make_symlink(link, target) do
330328
:ok -> :ok
331329
{:error, _} -> {:ok, File.cp_r!(source, target)}
332330
end

0 commit comments

Comments
 (0)