Skip to content

Instantly share code, notes, and snippets.

@edgurgel
Created June 16, 2013 17:25
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/5792741 to your computer and use it in GitHub Desktop.
Save edgurgel/5792741 to your computer and use it in GitHub Desktop.
@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