Skip to content

Commit

Permalink
Update for Gleam v0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
tynanbe authored and lpil committed Jan 12, 2022
1 parent 5f8c729 commit 9d45081
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ jobs:
with:
otp-version: "24.2"
elixir-version: "1.13.1"
gleam-version: "0.18.2"
gleam-version: "0.19.0-rc3"
- run: mix do archive.build, archive.install --force

- run: mix deps.get
working-directory: test_projects/basic_project

- run: mix test
working-directory: test_projects/basic_project

- run: mix gleam.test
working-directory: test_projects/basic_project
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.4.0 - 2021-01-10

- Updated to work with the `gleam compile-package` v0.19 API.

## v0.3.0 - 2021-12-26

- Updated to work with the `gleam compile-package` API for incremental builds
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ compiler and Gleam dependencies:
[
app: @app,
# ...
archives: [mix_gleam: "~> 0.3.0"],
archives: [mix_gleam: "~> 0.4.0"],
aliases: MixGleam.add_aliases(),
erlc_paths: ["build/dev/erlang/#{@app}/build"],
erlc_include_path: "build/dev/erlang/#{@app}/include",
Expand Down
54 changes: 22 additions & 32 deletions lib/mix/tasks/gleam/compile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,16 @@ defmodule Mix.Tasks.Gleam.Compile do

proceed? = fn -> not has_own_gleam_manager?.() and not cmd?.() end

if gleam?.() do
if force?.() or proceed?.() do
app =
try do
Keyword.get_lazy(options, :app, fn -> elem(options[:lock], 1) end)
rescue
_ -> raise MixGleam.Error, message: "Unable to find app name"
end
compile_package(app)
end
if gleam?.() and (force?.() or proceed?.()) do
app =
try do
Keyword.get_lazy(options, :app, fn -> elem(options[:lock], 1) end)
rescue
_ -> raise MixGleam.Error, message: "Unable to find app name"
end
compile_package(app)
end

:ok
end

Expand All @@ -136,37 +135,28 @@ defmodule Mix.Tasks.Gleam.Compile do
|> Enum.count

if 0 < files do
out = "build/dev/erlang/#{app}/build"
lib = Path.join(Mix.Project.build_path(), "lib")
out = "build/dev/erlang/#{app}"

# TODO remove when `gleam` handles this
File.mkdir_p(out)
Path.join(search_paths ++ ["**/*.{e,h}rl"])
|> Path.wildcard
|> Enum.each(&File.cp(&1, Path.join(out, Path.basename(&1))))
File.mkdir_p!(lib)

cmd = "gleam compile-package --target erlang --name #{app} --src #{MixGleam.find_paths([""], search_paths) |> hd} --out #{out} #{if tests?, do: "--lib #{out}"} #{MixGleam.find_libs()}"
cmd = "gleam compile-package --target erlang --no-beam --package . --out #{out} --lib #{lib}"
@shell.info("Compiling #{files} #{if tests?, do: "test "}file#{if 1 != files, do: "s"} (.gleam)")
MixGleam.IO.debug_info("Compiler Command", cmd)
compiled? =
@shell.cmd(cmd)
|> Kernel.===(0)
compiled? = @shell.cmd(cmd) === 0

if compiled? do
# TODO remove when `gleam` handles this
include =
Path.dirname(out)
|> Path.join("include")
File.mkdir_p(include)
Path.join(out, "**/*.hrl")
|> Path.wildcard
|> Enum.each(&File.cp(&1, Path.join(include, Path.basename(&1))))

if not tests? and Mix.env() in [:dev, :test] do
compile_package(app, true)
end
File.cp_r!(out, Mix.Project.app_path())

# TODO reuse when `gleam` conditionally compiles tests
#if not tests? and Mix.env() in [:dev, :test] do
#compile_package(app, true)
#end
else
raise MixGleam.Error, message: "Compilation failed"
end
end

:ok
end
end
2 changes: 1 addition & 1 deletion lib/mix_gleam/config.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MixGleam.Config do
@version "0.3.0"
@version "0.4.0"
@deps [
{:gleam_stdlib, "~> 0.18"},
{:gleeunit, "~> 0.5", only: [:dev, :test], runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule MixGleam.MixProject do
def project do
[
app: :mix_gleam,
version: "0.3.0",
version: "0.4.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
name: "mix_gleam",
Expand Down
2 changes: 1 addition & 1 deletion test_projects/basic_project/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule BasicProject.MixProject do

# New items added for Gleam compilation
# compilers: [:gleam | Mix.compilers()],
archives: [mix_gleam: "~> 0.3.0"],
archives: [mix_gleam: "~> 0.4.0"],
aliases: MixGleam.add_aliases(),
erlc_paths: ["build/dev/erlang/#{@app}/build"],
erlc_include_path: "build/dev/erlang/#{@app}/include"
Expand Down

0 comments on commit 9d45081

Please sign in to comment.