Skip to content

Remove yecc/leex generated .erl files on deps.clean, closes #8262#15318

Open
Ch4s3 wants to merge 1 commit intoelixir-lang:mainfrom
Ch4s3:clean-yecc-lexx-erl-files
Open

Remove yecc/leex generated .erl files on deps.clean, closes #8262#15318
Ch4s3 wants to merge 1 commit intoelixir-lang:mainfrom
Ch4s3:clean-yecc-lexx-erl-files

Conversation

@Ch4s3
Copy link
Copy Markdown

@Ch4s3 Ch4s3 commented Apr 28, 2026

Fixes #8262. mix deps.clean and mix clean --deps remove _build artifacts but never clean the .erl files that yecc/leex write back into deps//src/. Unlike every other compiler, yecc and leex use the same directory for input and output, so generated files accumulate across clean/compile cycles and survive deps.clean --all.

Solution
Mix-compiled deps: Before deleting _build, read .mix/compile.{yecc,leex} manifests (which store output paths relative to the dep's source root), expand each path against dep.opts[:dest], and delete it. A starts_with?(expanded, dest <> "/") guard prevents path traversal.

Rebar3 deps: Rebar3 never writes Mix manifests. When no manifests are found, fall back to scanning the dep source tree for .yrl/.xrl files and deleting the co-located .erl with the same basename. Hand-written .erl files with no grammar counterpart are never touched.

Lock ordering: mix clean --deps now wraps the source-file cleanup in with_deps_lock (nested inside the existing with_build_lock), matching what mix deps.clean already does and closing a race with concurrent mix deps.get.

Files changed"

  • deps.clean.ex — adds clean_generated_sources/4, wired in before clean_build; File.rm failures now reported via maybe_warn_failed_file_deletion
  • clean.ex— calls clean_generated_sources under with_deps_lock in the --deps branch
  • test/fixtures/clean_with_yecc/ — new fixture with a Mix dep (yecc + leex + hand-written .erl), and a rebar3 dep
  • deps.clean_test.exs — 13 new tests: both compilers, hand-written preservation, non-standard erlc_paths, --build/--all, multi-env deduplication, --only scoping, rebar3 scan fallback, idempotency, path traversal
  • clean_test.exs — 2 new tests: --deps removes generated files; --deps --only dev scopes to dev environment only

@Ch4s3 Ch4s3 force-pushed the clean-yecc-lexx-erl-files branch from b806483 to eccb15d Compare April 28, 2026 14:24
…ng#8262

mix deps.clean and mix clean --deps now delete .erl files that were
generated by yecc/leex compilers into a dep's source tree. For Mix-
compiled deps, generated paths are read from .mix/compile.{yecc,leex}
manifests before the build directory is removed. For rebar3 deps (which
never write Mix manifests), generated files are inferred by scanning the
dep source tree for .yrl/.xrl files and deleting the co-located .erl
with the same basename. mix clean --deps now also acquires the deps lock
when modifying dep source files.

Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Chase Gilliam <chase.gilliam@gmail.com>
@Ch4s3 Ch4s3 force-pushed the clean-yecc-lexx-erl-files branch from eccb15d to 5555028 Compare April 28, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

mix clean --deps does not clean out .erl files generated by yecc/leex

1 participant