Skip to content

Commit

Permalink
Reduce cyclomatic complexity of firmware mix task
Browse files Browse the repository at this point in the history
  • Loading branch information
lawik authored and fhunleth committed Jan 17, 2025
1 parent cf7dc9d commit 56c6f87
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/mix/tasks/firmware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,17 @@ defmodule Mix.Tasks.Firmware do

write_erlinit_config(build_rootfs_overlay)

project_rootfs_overlay =
case firmware_config[:rootfs_overlay] || firmware_config[:rootfs_additions] do
nil ->
[]

overlays when is_list(overlays) ->
overlays

overlay ->
[Path.expand(overlay)]
end

project_rootfs_overlay = config_arg(:rootfs_overlay, firmware_config)
prevent_overlay_overwrites!(project_rootfs_overlay)

rootfs_overlays =
[build_rootfs_overlay | project_rootfs_overlay]
|> Enum.map(&["-a", &1])
|> List.flatten()

fwup_conf =
case firmware_config[:fwup_conf] do
nil -> []
fwup_conf -> ["-c", Path.join(File.cwd!(), fwup_conf)]
end
fwup_conf = config_arg(:fwup_conf, firmware_config)

post_processing_script =
case firmware_config[:post_processing_script] do
nil -> []
script when is_binary(script) -> ["-s", script]
end
post_processing_script = config_arg(:post_processing_script, firmware_config)

fw = ["-f", fw_out]
release_path = Path.join(Mix.Project.build_path(), "rel/#{otp_app}")
Expand Down Expand Up @@ -307,4 +288,31 @@ defmodule Mix.Tasks.Firmware do
""")
end
end

defp config_arg(:rootfs_overlay, firmware_config) do
case firmware_config[:rootfs_overlay] || firmware_config[:rootfs_additions] do
nil ->
[]

overlays when is_list(overlays) ->
overlays

overlay ->
[Path.expand(overlay)]
end
end

defp config_arg(:fwup_conf, firmware_config) do
case firmware_config[:fwup_conf] do
nil -> []
fwup_conf -> ["-c", Path.join(File.cwd!(), fwup_conf)]
end
end

defp config_arg(:post_processing_script, firmware_config) do
case firmware_config[:post_processing_script] do
nil -> []
script when is_binary(script) -> ["-s", script]
end
end
end

0 comments on commit 56c6f87

Please sign in to comment.