Created
June 16, 2013 17:25
-
-
Save edgurgel/5792741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@doc """ | |
Loads the rebar.config and evaluates rebar.config.script if it | |
exists in the given directory. | |
""" | |
def load_config(dir) do | |
config_path = Path.join(dir, "rebar.config") | |
script_path = Path.join(dir, "rebar.config.script") | |
config = case :file.consult(config_path) do | |
{ :ok, config } -> | |
config | |
{ :error, :enoent } -> | |
[] | |
{ :error, error } -> | |
reason = :file.format_error(error) | |
raise Mix.Error, message: "Error consulting rebar config #{config_path}: #{reason}" | |
end | |
if File.exists?(script_path) do | |
eval_script(script_path, config) | |
else | |
config | |
end | |
end | |
defp eval_script(script_path, config) do | |
script = Path.basename(script_path) |> binary_to_list | |
File.cd!(Path.dirname(script_path), fn -> | |
case :file.script(script, eval_binds(CONFIG: config, SCRIPT: script)) do | |
{ :ok, config } -> | |
config | |
{ :error, error } -> | |
reason = :file.format_error(error) | |
raise Mix.Error, message: "Error evaluating rebar config script #{script_path}: #{reason}" | |
end | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment