Skip to content
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

Deep clean the .erl files generated by yecc/leex. #10153

Closed
Closed
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
13 changes: 10 additions & 3 deletions lib/mix/lib/mix/tasks/clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ defmodule Mix.Tasks.Clean do
|> Path.join("*#{opts[:only]}")

if opts[:deps] do
build
|> Path.wildcard()
|> Enum.each(&File.rm_rf/1)
deps_paths =
Mix.Project.deps_paths()
|> Map.values()
|> Enum.map(&Path.join(&1, "**/*.erl"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we cannot simply remove all .erl files because we will remove source files for many erlang projects, that have .erl files in their deps. The implementation of this functionality needs to be tied to the Mix.Task.Compiler behaviour and it is likely quite more complex than this. :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative could be to modify the compilers that output the .erl files either not to do that at all, our output them inside _build.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing .erl files that have their uncompiled version?

If the only way that you saw is going through the Mix.Task.Compiler I can try to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalmuskala I tried that back then but unfortunately I ran into major issues, I don't recall them right now. Modifying the compilers to not output the .erl files actually sounds great. It solves the problem altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will also be a fair bit of work, unfortunately. There are some limitations of the yecc and leex compilers themselves to work around to do this


for path <- [build] ++ deps_paths do
path
|> Path.wildcard()
|> Enum.each(&File.rm_rf/1)
end
else
build
|> Path.join("lib/#{Mix.Project.config()[:app]}")
Expand Down
4 changes: 4 additions & 0 deletions lib/mix/test/mix/tasks/clean_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ defmodule Mix.Tasks.CleanTest do
File.mkdir_p!("_build/dev/lib/sample")
File.mkdir_p!("_build/test/lib/sample")
File.mkdir_p!("_build/dev/lib/ok")
File.touch!("deps/ok/priv/compiled.erl")

Mix.Tasks.Clean.run([])
refute File.exists?("_build/dev/lib/sample/consolidated")
refute File.exists?("_build/dev/lib/sample")
refute File.exists?("_build/test/lib/sample")
assert File.exists?("_build/dev/lib/ok")
assert File.exists?("deps/ok/priv/compiled.erl")
end)
end

Expand All @@ -43,10 +45,12 @@ defmodule Mix.Tasks.CleanTest do

Mix.Tasks.Clean.run(["--deps", "--only", "dev"])
refute File.exists?("_build/dev")
refute File.exists?("deps/ok/priv/compiled.erl")
assert File.exists?("_build/test")

Mix.Tasks.Clean.run(["--deps"])
refute File.exists?("_build/test")
refute File.exists?("deps/ok/priv/compiled.erl")
end)
end
end