Skip to content

Instantly share code, notes, and snippets.

@edgurgel
Created June 16, 2013 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edgurgel/5792709 to your computer and use it in GitHub Desktop.
Save edgurgel/5792709 to your computer and use it in GitHub Desktop.
@rebarconfigscript "rebar.config.script"
@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, @rebarconfigscript)
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
File.cd!(dir, fn -> eval_script(@rebarconfigscript, config) end)
else
config
end
end
defp eval_script(script, config) do
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 #{Path.expand(script)}: #{reason}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment