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

Add MIX_COMPILE_CWD_CACHE environment variable #13266

Closed
wants to merge 2 commits into from
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
6 changes: 6 additions & 0 deletions lib/mix/lib/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ defmodule Mix do
written to. For example, "_build". If `MIX_BUILD_PATH` is set, this option
is ignored.

* `MIX_COMPILE_CWD_CACHE` - Invalidates the compilation cache when the current
directory gets changed. This is the recommended behavior to avoid potential issues,
but can trigger undesired recompilations in some workflows where files are relocated
between compilation and mix task execution.
True by default, set to `0` or `false` to disable.

* `MIX_DEBUG` - outputs debug information about each task before running it

* `MIX_DEPS_PATH` - sets the project `Mix.Project.deps_path/0` config for the
Expand Down
13 changes: 11 additions & 2 deletions lib/mix/lib/mix/compilers/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule Mix.Compilers.Elixir do
do: [Mix.Project | stale],
else: stale

# If the lock has changed or a local dependency was added ore removed,
# If the lock has changed or a local dependency was added or removed,
# we need to traverse lock/config files.
deps_changed? =
Mix.Utils.stale?([Mix.Project.config_mtime()], [modified]) or
Expand All @@ -81,7 +81,8 @@ defmodule Mix.Compilers.Elixir do

{force?, stale, new_deps_config} =
cond do
!!opts[:force] or is_nil(old_deps_config) or old_cache_key != new_cache_key ->
!!opts[:force] or is_nil(old_deps_config) or
not cache_key_matches?(old_cache_key, new_cache_key) ->
{true, stale, deps_config(local_deps)}

deps_changed? or compile_env_apps != [] ->
Expand Down Expand Up @@ -267,6 +268,14 @@ defmodule Mix.Compilers.Elixir do
end
end

defp cache_key_matches?(same, same), do: true

defp cache_key_matches?({base, srcs, left_cwd, opt}, {base, srcs, right_cwd, opt})
when is_nil(left_cwd) or is_nil(right_cwd),
do: true

defp cache_key_matches?(_left_key, _right_key), do: false

@doc """
Removes compiled files for the given `manifest`.
"""
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/lib/mix/tasks/compile.elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ defmodule Mix.Tasks.Compile.Elixir do

manifest = manifest()
base = xref_exclude_opts(project[:elixirc_options] || [], project)
cache_key = {base, srcs, File.cwd!(), "--no-optional-deps" in args}
maybe_cwd = if System.get_env("MIX_COMPILE_CWD_CACHE") not in ["0", "false"], do: File.cwd!()
cache_key = {base, srcs, maybe_cwd, "--no-optional-deps" in args}

opts =
base
Expand Down
Loading