@@ -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_DISABLE_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_DISABLE_LOCK=1\
211+ """ )
206212 end
207213 end
208214
0 commit comments