@@ -104,15 +104,34 @@ defmodule Mix.Tasks.Deps.Compile do
104
104
end
105
105
end
106
106
107
+ defp do_rebar ( app , root_path ) do
108
+ do_command app , rebar_cmd ( app ) , "compile skip_deps=true deps_dir=#{ inspect root_path } "
109
+ end
110
+
111
+ @ rebar_cmds [ :cwd_rebar_cmd , :local_rebar_cmd , :global_rebar_cmd ]
112
+
113
+ defp rebar_cmd ( app ) do
114
+ Enum . find_value ( @ rebar_cmds , apply ( Mix.Rebar , & 1 , [ ] ) ) || handle_rebar_not_found ( app )
115
+ end
116
+
117
+ defp handle_rebar_not_found ( app ) do
118
+ shell = Mix . shell
119
+ shell . info "Could not find rebar, which is needed to build #{ app } "
120
+ shell . info "I can install a local copy which is just used by mix"
121
+
122
+ unless shell . yes? ( "Shall I install this local copy?" ) do
123
+ raise Mix.Error , message: "could not find rebar to compile " <>
124
+ "dependency #{ app } , please ensure rebar is available"
125
+ end
126
+
127
+ Mix.Task . run "local.rebar" , [ ]
128
+ Mix.Rebar . local_rebar_cmd || raise Mix.Error , message: "Rebar instalation failed"
129
+ end
130
+
107
131
defp do_command ( app , command , extra // "" ) do
108
- if System . find_executable ( command ) do
109
- if Mix . shell . cmd ( "#{ command } #{ extra } " ) != 0 do
110
- raise Mix.Error , message: "could not compile dependency #{ app } , #{ command } command failed. " <>
111
- "In case you want to recompile this dependency, please run: mix deps.compile #{ app } "
112
- end
113
- else
114
- raise Mix.Error , message: "could not find executable #{ command } to compile " <>
115
- "dependency #{ app } , please ensure #{ command } is available"
132
+ if Mix . shell . cmd ( "#{ command } #{ extra } " ) != 0 do
133
+ raise Mix.Error , message: "could not compile dependency #{ app } , #{ command } command failed. " <>
134
+ "In case you want to recompile this dependency, please run: mix deps.compile #{ app } "
116
135
end
117
136
end
118
137
@@ -127,32 +146,4 @@ defmodule Mix.Tasks.Deps.Compile do
127
146
"In case you want to recompile this dependency, please run: mix deps.compile #{ app } "
128
147
end
129
148
end
130
-
131
- defp do_rebar ( app , root_path ) do
132
- do_command app , find_rebar ( app ) , "compile skip_deps=true deps_dir=#{ inspect root_path } "
133
- end
134
-
135
- defp find_rebar ( app ) do
136
- cond do
137
- File . regular? ( "./rebar" ) ->
138
- Path . join ( File . cwd! , "rebar" )
139
-
140
- File . regular? ( Mix.Rebar . local_rebar_path ) ->
141
- Mix.Rebar . local_rebar_path
142
-
143
- System . find_executable ( "rebar" ) ->
144
- "rebar"
145
-
146
- true ->
147
- shell = Mix . shell
148
- shell . info "Could not find rebar, which is needed to build #{ app } "
149
- shell . info "I can install a local copy which is just used by mix"
150
- unless shell . yes? ( "Shall I install this local copy?" ) do
151
- raise Mix.Error , message: "could not find rebar to compile " <>
152
- "dependency #{ app } , please ensure rebar is available"
153
- end
154
- Mix.Task . run "local.rebar" , [ ]
155
- Mix.Tasks . local_rebar_path
156
- end
157
- end
158
149
end
0 commit comments