gleam-lang / mix_gleam

⚗️ Build Gleam code with mix
Apache License 2.0
170 stars 20 forks source link

when gleam version is higher than v0.19.0, `File.CopyError` raised #23

Closed if1live closed 1 year ago

if1live commented 2 years ago

mix compile.gleam error message

** (File.CopyError) could not copy recursively from "build/dev/erlang/shiroko_web" to "d:/shiroko/shiroko_umbrella/_build/dev/lib/shiroko_web". build/dev/erlang/shiroko_web/priv: file already exists
    (elixir 1.13.4) lib/file.ex:902: File.cp_r!/3
    (mix_gleam 0.6.0) lib/mix/tasks/compile/gleam.ex:167: Mix.Tasks.Compile.Gleam.compile_package/2
    (mix_gleam 0.6.0) lib/mix/tasks/compile/gleam.ex:72: Mix.Tasks.Compile.Gleam.run/1
    (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
    (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1   

reason

gleam v0.20.0-rc1 release note

The priv directory is linked into the build directory for Gleam projects managed by the build tool.

  1. mix compile.gleam
  2. gleam make symbolic link, build/dev/erlang/<app>/priv if priv exists
  3. File.cp_r! invoked https://github.com/gleam-lang/mix_gleam/blob/v0.6.0/lib/mix/tasks/compile/gleam.ex
  4. File.CopyError raised. build/dev/erlang//priv: file already exists
lpil commented 2 years ago

@gleam-lang/elixir-team does this sound familiar to anyone?

tynanbe commented 2 years ago

I just made a fresh copy of basic_project from this repository, added rad (which has a priv dir) to mix.exs, then ran mix deps.get. After that, mix compile worked without issue.

Locally I have MixGleam v0.6.0 and gleam compiled from its main branch.

xhh commented 2 years ago

I have this issue too on a newly generated Phoenix project.

xhh commented 1 year ago

The issue seems to be that the link to priv directory has already been created by mix.

It works if skipping priv when copying files, e.g. changing this line from

File.cp_r!(out, Mix.Project.app_path())

to

app_path = Mix.Project.app_path()

for path <- File.ls!(out), path != "priv" do
  from = Path.join(out, path)
  to = Path.join(app_path, path)
  File.cp_r!(from, to)
end
lpil commented 1 year ago

Great find, thank you!

xhh commented 1 year ago

It seems File.cp_r! should just replace the priv link when it already exists in the dest dir, but in my case (on Windows 10) it fails and returns {:error, :eperm}. I'm not sure if it works fine on Linux though.

tynanbe commented 1 year ago

@xhh can you confirm that this issue is fixed? Much appreciated.

xhh commented 1 year ago

The path to check if is symlink should be the src path, not dest. I've made a pull request: #29, and then the bug is confirmed to be fixed with the changes.

tynanbe commented 1 year ago

@xhh, why check src? The problem occurs when priv already exists in dest; moreover, we want to ensure that priv actually does exist in dest, no? Why would it matter if priv is a symlink in src?

xhh commented 1 year ago

@tynanbe I tried with a newly created Phoenix project, there's already a priv directory in the dest, which I think was created by mix/phoenix. And in the src directory there's a priv symlink:

b

tynanbe commented 1 year ago

Thanks!