Skip to content

Commit b3abc04

Browse files
committed
Add an environment variable to optionally disable compilation locking
1 parent ed2ff6a commit b3abc04

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/mix/lib/mix.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ defmodule Mix do
352352
* `MIX_INSTALL_DIR` *(since v1.12.0)* - specifies directory where `Mix.install/2` keeps
353353
install cache
354354
355+
* `MIX_DISABLE_LOCK` - disables mix compilation locking. While not recommended, this may be
356+
necessary in cases where hard links or TCP sockets are not available. When opting for this
357+
behaviour, make sure to not start concurrent compilations of the same project.
358+
355359
* `MIX_PATH` - appends extra code paths
356360
357361
* `MIX_PROFILE` - a list of comma-separated Mix tasks to profile the time spent on

lib/mix/lib/mix/sync/lock.ex

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ defmodule Mix.Sync.Lock do
7979
This function can also be called if this process already has the
8080
lock. In such case the function is executed immediately.
8181
82+
When the `MIX_NO_LOCK` environment variable is set, the lock is
83+
ignored and the function is executed immediately.
84+
8285
## Options
8386
8487
* `:on_taken` - a one-arity function called if the lock is held
@@ -96,9 +99,9 @@ defmodule Mix.Sync.Lock do
9699
path = Path.join([System.tmp_dir!(), "mix_lock", hash])
97100

98101
pdict_key = {__MODULE__, path}
99-
has_lock? = Process.get(pdict_key)
102+
has_lock? = Process.get(pdict_key, false)
100103

101-
if has_lock? do
104+
if has_lock? or lock_disabled?() do
102105
fun.()
103106
else
104107
lock = lock(path, opts[:on_taken])
@@ -115,6 +118,8 @@ defmodule Mix.Sync.Lock do
115118
end
116119
end
117120

121+
defp lock_disabled?(), do: System.get_env("MIX_DISABLE_LOCK") in ~w(1 true)
122+
118123
defp lock(path, on_taken) do
119124
File.mkdir_p!(path)
120125

@@ -198,11 +203,12 @@ defmodule Mix.Sync.Lock do
198203
:invalidated
199204

200205
{:error, reason} ->
201-
raise File.LinkError,
202-
reason: reason,
203-
action: "create hard link",
204-
existing: port_path,
205-
new: lock_path
206+
Mix.raise("""
207+
could not create hard link from #{port_path} to "#{lock_path}: #{:file.format_error(reason)}.
208+
209+
Hard link support is required for Mix compilation locking. If your system \
210+
does not support hard links, set MIX_NO_LOCK=1\
211+
""")
206212
end
207213
end
208214

0 commit comments

Comments
 (0)