-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add gleam support to Mix #14262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Papipo
wants to merge
42
commits into
elixir-lang:main
Choose a base branch
from
Papipo:add-gleam-compiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add gleam support to Mix #14262
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c5bd684
Add fixture for gleam support
Papipo 3fcf897
Add Gleam integration with Mix
Papipo 85ba7b2
Add support for git dependencies in gleam packages
Papipo 96a1c0b
Exclude gleam tests if gleam is missing
Papipo 7e21ba0
Fix deps.compile for gleam
Papipo e3c18a5
Add support for application_start_module
Papipo 3ca3c6f
Handle gleam extra_applications
Papipo b142e94
Remove redundant quotes
Papipo ec9e597
Do not force `app: false` in gleam deps
Papipo 08b2a54
Generate app file for gleam deps on compilation
Papipo 26203af
Proper beam compilation and .app file generation
Papipo 5ff6bc9
Apply suggestions from code review
Papipo d7f4558
Add support for :application option in Compile.App
Papipo 449c45e
Proper handling of deeply nested and dev gleam deps
Papipo c7693b2
Install gleam 1.11.1 on CI
Papipo 8d800f8
Apply code review suggestions
Papipo 7ffa8c8
Pinpoint gleam deps to avoid brittle tests
Papipo 46aa2d6
Fix typo
Papipo 7e51726
Apply suggestions from code review
Papipo 47f3b66
Fix typo in docs
Papipo 2f0efe4
Update copyright comments
Papipo 8f75b1b
Merge branch 'main' into add-gleam-compiler
Papipo 00f852d
Merge branch 'main' into add-gleam-compiler
Papipo d8bd1ff
Refactor `Mix.Gleam`
eksperimental cff76d0
Update lib/mix/lib/mix/gleam.ex
Papipo 6762814
Merge remote-tracking branch 'eks/Papipo/add-gleam-compiler+' into ad…
Papipo 356afbe
Couple of tiny fixes
Papipo 0152025
Add support for gleam dev_dependencies
Papipo c5bafdc
Merge branch 'main' into add-gleam-compiler
Papipo d6670ee
Fix bad merge artifact
Papipo e35e0c8
Format test_helper
Papipo e631277
Merge branch 'elixir-lang:main' into add-gleam-compiler
Papipo e91cb8f
fix: remove unneeded gleam stuff
Papipo 65d7ad7
add --prod flag to gleam compile-package
Papipo 871e32b
fix: dev deps are no longer required
Papipo 0b10bc4
update gleam tests
Papipo 9aeaacd
fix: tures. Yes, fixed the fixtures.
Papipo 33380fd
rely on gleam command errors for package requirements
Papipo 3ca2f5d
remove application option
Papipo 6cbae73
fix stranded tests
Papipo 847d27d
adjust package-information command to latest version
Papipo 28dfeb0
switch gleam compile-package flag to --src-only
Papipo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: 2021 The Elixir Team | ||
|
|
||
| defmodule Mix.Gleam do | ||
| # Version that introduced generating an .app file | ||
| @gleam_version_requirement ">= 1.19.0" | ||
|
|
||
| @spec load_config(Path.t()) :: config :: map() | ||
| def load_config(dir) do | ||
| File.cd!(dir, fn -> | ||
| with {:ok, output} <- | ||
| gleam(~W(export package-information)), | ||
| json <- JSON.decode!(output), | ||
| {:ok, gleam_toml} <- Map.fetch(json, "gleam.toml") do | ||
| parse_config(gleam_toml) | ||
| else | ||
| :error -> | ||
| {:error, "\"gleam.toml\" key not found in \"gleam export package-information\" output"} | ||
|
|
||
| {:error, message} -> | ||
| {:error, message} | ||
| end | ||
| |> assert_ok_value!() | ||
| end) | ||
| end | ||
|
|
||
| @spec parse_config(map()) :: {:ok, config :: map()} | {:error, message :: binary()} | ||
| def parse_config(json) when is_map(json) do | ||
| deps = | ||
| Map.get(json, "dependencies", %{}) | ||
| |> Enum.map(&parse_dep!/1) | ||
|
|
||
| with {:ok, name} <- Map.fetch(json, "name"), | ||
| {:ok, version} <- Map.fetch(json, "version") do | ||
| config = | ||
| %{ | ||
| name: name, | ||
| version: version, | ||
| deps: deps | ||
| } | ||
|
|
||
| {:ok, config} | ||
| else | ||
| :error -> | ||
| {:error, | ||
| "Command \"gleam export package-information\" unexpected format: \n" <> | ||
| inspect(json, pretty: true, limit: :infinity)} | ||
| end | ||
| end | ||
|
|
||
| defp parse_dep!({dep, requirement}, opts \\ []) do | ||
| String.to_atom(dep) | ||
| |> build_dep_spec(requirement, opts) | ||
| |> assert_ok_value!() | ||
| end | ||
|
|
||
| defp build_dep_spec(dep, %{"version" => version}, []), | ||
| do: {:ok, {dep, version}} | ||
|
|
||
| defp build_dep_spec(dep, %{"version" => version}, opts), | ||
| do: {:ok, {dep, version, opts}} | ||
|
|
||
| defp build_dep_spec(dep, %{"path" => path}, opts), | ||
| do: {:ok, {dep, Keyword.merge(opts, path: Path.expand(path))}} | ||
|
|
||
| defp build_dep_spec(dep, %{"git" => git, "ref" => ref}, _opts), | ||
| do: {:ok, {dep, git: git, ref: ref}} | ||
|
|
||
| defp build_dep_spec(dep, requirement, _opts), | ||
| do: {:error, "Gleam package #{dep} has unsupported requirement: #{inspect(requirement)}"} | ||
|
|
||
| @spec requirements!() :: :ok | ||
| def requirements!() do | ||
| case fetch_gleam_version() do | ||
| {:ok, gleam_version} -> | ||
| if Version.match?(gleam_version, @gleam_version_requirement) do | ||
| :ok | ||
| else | ||
| {:error, | ||
| "Current Gleam version does not meet minimum requirements " <> | ||
| "#{@gleam_version_requirement}, got: #{gleam_version}"} | ||
| end | ||
|
|
||
| {:error, message} -> | ||
| {:error, message} | ||
| end | ||
| |> assert_ok_value!() | ||
| end | ||
|
|
||
| defp fetch_gleam_version() do | ||
| case gleam(["--version"]) do | ||
| {:ok, "gleam " <> version} -> | ||
| case Version.parse(version) do | ||
| {:ok, parsed_version} -> | ||
| {:ok, Version.to_string(parsed_version)} | ||
|
|
||
| :error -> | ||
| {:error, "Command \"gleam --version\" invalid version format: #{version}"} | ||
| end | ||
|
|
||
| {:error, output} -> | ||
| {:error, "Command \"gleam --version\" unexpected format: #{output}"} | ||
| end | ||
| end | ||
|
|
||
| defp gleam(args) do | ||
| System.cmd("gleam", args, stderr_to_stdout: true) | ||
| catch | ||
| :error, :enoent -> | ||
| {:error, | ||
| "The \"gleam\" executable is not available in your PATH. " <> | ||
| "Please install it, as one of your dependencies requires it"} | ||
| else | ||
| {response, 0} -> | ||
| {:ok, String.trim(response)} | ||
|
|
||
| {response, _} when is_binary(response) -> | ||
| {:error, "Command \"gleam #{Enum.join(args, " ")}\" failed with reason: #{response}"} | ||
|
|
||
| {_, _} -> | ||
| {:error, "Command \"gleam #{Enum.join(args, " ")}\" failed"} | ||
| end | ||
|
|
||
| defp assert_ok_value!(:ok), do: :ok | ||
| defp assert_ok_value!({:ok, term}), do: term | ||
| defp assert_ok_value!({:error, message}) when is_binary(message), do: Mix.raise(message) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # The directory Mix will write compiled artifacts to. | ||
| /_build/ | ||
|
|
||
| # The directory Gleam will write compiled artifacts to. | ||
| /build/ | ||
|
|
||
| # If the VM crashes, it generates a dump, let's ignore it too. | ||
| erl_crash.dump | ||
|
|
||
| # BEAM bytecode files. | ||
| *.beam | ||
|
|
||
| # Also ignore archive artifacts (built via "mix archive.build"). | ||
| *.ez |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name = "gleam_dep" | ||
| version = "1.0.0" | ||
| description = "GleamDep description" | ||
| # Fill out these fields if you intend to generate HTML documentation or publish | ||
| # your project to the Hex package manager. | ||
| # | ||
| # description = "" | ||
| # licences = ["Apache-2.0"] | ||
| # repository = { type = "github", user = "", repo = "" } | ||
| # links = [{ title = "Website", href = "" }] | ||
| # | ||
| # For a full reference of all the available options, you can have a look at | ||
| # https://gleam.run/writing-gleam/gleam-toml/. | ||
|
|
||
| [dependencies] | ||
| gleam_stdlib = "0.59.0" | ||
| gleam_otp = "0.16.1" | ||
|
|
||
| [dev-dependencies] | ||
| gleeunit = ">= 1.0.0 and < 2.0.0" | ||
|
|
||
| [erlang] | ||
| extra_applications = ["ssl"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # This file was generated by Gleam | ||
| # You typically do not need to edit this file | ||
|
|
||
| packages = [ | ||
| { name = "gleam_erlang", version = "0.34.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "0C38F2A128BAA0CEF17C3000BD2097EB80634E239CE31A86400C4416A5D0FDCC" }, | ||
| { name = "gleam_otp", version = "0.16.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "50DA1539FC8E8FA09924EB36A67A2BBB0AD6B27BCDED5A7EF627057CF69D035E" }, | ||
| { name = "gleam_stdlib", version = "0.54.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "723BA61A2BAE8D67406E59DD88CEA1B3C3F266FC8D70F64BE9FEC81B4505B927" }, | ||
| { name = "gleeunit", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "0E6C83834BA65EDCAAF4FE4FB94AC697D9262D83E6F58A750D63C9F6C8A9D9FF" }, | ||
| ] | ||
|
|
||
| [requirements] | ||
| gleam_otp = { version = ">= 0.16.1 and < 1.0.0" } | ||
| gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } | ||
| gleeunit = { version = ">= 1.0.0 and < 2.0.0" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Papipo this could be increased now or whenever there is movement on the PR again, @lpil which version would we chose here? how would we keep this updated? And to what version (latest major stable minus one plus patches?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing all versions seems to much. I guess it would make sense to just keep it up to date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to keep this up to date!