From 3e6d73b553929ddb0af326bdcb7e011ef285e43d Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 18 Jul 2025 13:59:03 -0500 Subject: [PATCH] format --- lib/aprsme/encoding_utils.ex | 2 +- lib/mix/tasks/gleam_compile.ex | 44 ++++++++++++++++++---------------- mix.exs | 1 - 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/aprsme/encoding_utils.ex b/lib/aprsme/encoding_utils.ex index 142d7bd..90b6187 100644 --- a/lib/aprsme/encoding_utils.ex +++ b/lib/aprsme/encoding_utils.ex @@ -8,7 +8,7 @@ defmodule Aprsme.EncodingUtils do # The Gleam module is compiled with @ separator in the beam name @gleam_module :aprsme@encoding - + # Optional compile-time check to suppress warnings @compile {:no_warn_undefined, {@gleam_module, :sanitize_string, 1}} @compile {:no_warn_undefined, {@gleam_module, :to_float_safe, 1}} diff --git a/lib/mix/tasks/gleam_compile.ex b/lib/mix/tasks/gleam_compile.ex index 170360c..ef4fe73 100644 --- a/lib/mix/tasks/gleam_compile.ex +++ b/lib/mix/tasks/gleam_compile.ex @@ -1,25 +1,26 @@ defmodule Mix.Tasks.GleamCompile do + @shortdoc "Compiles Gleam files and copies them to the correct location" + + @moduledoc false use Mix.Task - @shortdoc "Compiles Gleam files and copies them to the correct location" - def run(_args) do env = Mix.env() - + # Check if compile.gleam task exists task_exists = Code.ensure_loaded?(Mix.Tasks.Compile.Gleam) - + if task_exists do # First run the gleam compiler Mix.Task.run("compile.gleam") - + # Ensure output directory exists ebin_dir = "_build/#{env}/lib/aprsme/ebin" File.mkdir_p!(ebin_dir) - + # Copy beam files from Gleam build to Elixir build gleam_output = "build/#{env}/erlang/aprsme/_gleam_artefacts" - + if File.exists?(gleam_output) do gleam_output |> File.ls!() @@ -33,22 +34,23 @@ defmodule Mix.Tasks.GleamCompile do end else Mix.shell().info("Gleam compiler not available, compiling manually") - + # Compile Gleam files manually using gleam binary if available if System.find_executable("gleam") do Mix.shell().info("Found gleam binary, compiling...") {output, _exit_code} = System.cmd("gleam", ["build"], cd: File.cwd!()) Mix.shell().info(output) - + # Copy from gleam build to elixir build # Gleam always builds to dev directory regardless of MIX_ENV # The compiled files go to the project's ebin directory gleam_output = "build/dev/erlang/aprsme/ebin" ebin_dir = "_build/#{env}/lib/aprsme/ebin" File.mkdir_p!(ebin_dir) - + # First, check if compile.gleam already created the aprsme@encoding.beam dev_ebin = "_build/dev/lib/aprsme/ebin" + if File.exists?(Path.join(dev_ebin, "aprsme@encoding.beam")) do Mix.shell().info("Found pre-compiled aprsme@encoding.beam") src = Path.join(dev_ebin, "aprsme@encoding.beam") @@ -56,15 +58,17 @@ defmodule Mix.Tasks.GleamCompile do File.copy!(src, dest) Mix.shell().info("Copied aprsme@encoding.beam to test build") end - + if File.exists?(gleam_output) do Mix.shell().info("Checking #{gleam_output} for beam files...") - beam_files = gleam_output - |> File.ls!() - |> Enum.filter(&String.ends_with?(&1, ".beam")) - + + beam_files = + gleam_output + |> File.ls!() + |> Enum.filter(&String.ends_with?(&1, ".beam")) + Mix.shell().info("Found #{length(beam_files)} beam files") - + Enum.each(beam_files, fn beam_file -> src = Path.join(gleam_output, beam_file) dest = Path.join(ebin_dir, beam_file) @@ -78,10 +82,10 @@ defmodule Mix.Tasks.GleamCompile do # Last resort: try to copy from dev build if available dev_ebin = "_build/dev/lib/aprsme/ebin" test_ebin = "_build/#{env}/lib/aprsme/ebin" - + if File.exists?(dev_ebin) and env != :dev do File.mkdir_p!(test_ebin) - + dev_ebin |> File.ls!() |> Enum.filter(&String.starts_with?(&1, "aprs@")) @@ -93,7 +97,7 @@ defmodule Mix.Tasks.GleamCompile do end end end - + :ok end -end \ No newline at end of file +end diff --git a/mix.exs b/mix.exs index 1c06527..397b28e 100644 --- a/mix.exs +++ b/mix.exs @@ -142,5 +142,4 @@ defmodule Aprsme.MixProject do # {:aprs, github: "aprsme/aprs", branch: "main"} # end end - end