@@ -161,10 +161,13 @@ defmodule Mix.Tasks.Compile.App do
161161 |> max ( Mix.Utils . last_modified ( compile_path ) )
162162
163163 current_properties = current_app_properties ( target )
164+ current_compile_env = Mix.ProjectStack . compile_env ( nil )
164165
165166 { changed? , modules } =
166167 cond do
167- opts [ :force ] || new_mtime > Mix.Utils . last_modified ( target ) ->
168+ opts [ :force ] || new_mtime > Mix.Utils . last_modified ( target ) ||
169+ ( current_compile_env != nil and
170+ current_compile_env != Keyword . get ( current_properties , :compile_env , [ ] ) ) ->
168171 { true , nil }
169172
170173 Keyword . get ( config , :reliable_dir_mtime , fn -> not match? ( { :win32 , _ } , :os . type ( ) ) end ) ->
@@ -184,7 +187,7 @@ defmodule Mix.Tasks.Compile.App do
184187 ]
185188 |> merge_project_application ( project )
186189 |> handle_extra_applications ( config )
187- |> add_compile_env ( current_properties )
190+ |> add_compile_env ( current_compile_env , current_properties )
188191 |> add_modules ( modules , compile_path )
189192
190193 contents =
@@ -389,12 +392,12 @@ defmodule Mix.Tasks.Compile.App do
389392 defp typed_app? ( { app , type } ) when is_atom ( app ) and type in [ :required , :optional ] , do: true
390393 defp typed_app? ( _ ) , do: false
391394
392- defp add_compile_env ( properties , current_properties ) do
395+ defp add_compile_env ( properties , current_compile_env , current_properties ) do
393396 # If someone calls compile.elixir and then compile.app across two
394397 # separate OS calls, then the compile_env won't be properly reflected.
395398 # This is ok because compile_env is not used for correctness. It is
396399 # simply to catch possible errors early.
397- case Mix.ProjectStack . compile_env ( nil ) do
400+ case current_compile_env do
398401 nil -> Keyword . take ( current_properties , [ :compile_env ] ) ++ properties
399402 [ ] -> properties
400403 compile_env -> Keyword . put ( properties , :compile_env , compile_env )
0 commit comments