Skip to content
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

Be explicit of behaviours used rather than use macro #1045

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions lib/nerves/package/platform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ defmodule Nerves.Package.Platform do
is useful for constructing host tools to be used during the elixir compile
phase.

You can implement both `Nerves.Package.Platform` and `Nerves.Artifact.BuildRunner`
in the same module with the using macro.

Here is a simple example that touches a file in the `Artifact.build_path`

```elixir
defmodule SystemPlatform do
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

def bootstrap(_pkg) do
System.put_env("NERVES_BOOTSTRAP_SYSTEM", "1")
Expand Down Expand Up @@ -68,11 +66,4 @@ defmodule Nerves.Package.Platform do
artifact to the local build_path location.
"""
@callback build_path_link(package :: Nerves.Package.t()) :: build_path_link :: String.t()

defmacro __using__(_) do
quote do
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform
end
end
end
3 changes: 2 additions & 1 deletion lib/nerves/system/br.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ defmodule Nerves.System.BR do
@moduledoc """
Package builder for Buildroot-based Nerves systems
"""
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

import Mix.Nerves.Utils
alias Nerves.Artifact
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/host_tool/lib/host_tool/platform.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule HostTool.Platform do
@moduledoc false
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

alias Nerves.Artifact

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/system_platform/lib/system_platform.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule SystemPlatform do
@moduledoc false
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

alias Nerves.Artifact

@impl Nerves.Package.Platform
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/toolchain_platform/lib/toolchain_platform.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule ToolchainPlatform do
@moduledoc false
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

alias Nerves.Artifact

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule ToolchainPlatform do
@moduledoc false
use Nerves.Package.Platform
@behaviour Nerves.Artifact.BuildRunner
@behaviour Nerves.Package.Platform

alias Nerves.Artifact

Expand Down