Current section
Files
Jump to
Current section
Files
lib/tasks/lcov/load_and_run_task.exs
# Script to load a mix task and related dependency modules from beam files on runtime if necessary,
# and then run the task
beam_path = System.argv() |> Enum.at(0)
task_module = System.argv() |> Enum.at(1) |> String.to_atom()
# Ensure that task module is loaded
unless Code.ensure_loaded?(task_module) do
# Get dependency beam files data
beam_dir = Path.dirname(beam_path)
beam_extension = Path.extname(beam_path)
# Load all dependency modules
for filename <- File.ls!(beam_dir) |> Enum.filter(&String.ends_with?(&1, beam_extension)) do
binary = File.read!(Path.join(beam_dir, filename))
:code.load_binary(Path.rootname(filename) |> String.to_atom(), to_charlist(filename), binary)
end
# Load dependency tasks
Mix.Task.load_tasks([beam_dir])
end
# Run given task
{task, args} = System.argv() |> Enum.at(-1) |> String.split() |> List.pop_at(0)
Mix.Task.run(task, args)