bivouac_system_rpi4/mix.exs
James Harton 5ade272880
Some checks failed
continuous-integration/drone Build is failing
chore: empty mix app and copy files from x86_64 template.
2023-10-13 13:36:01 +13:00

180 lines
4.8 KiB
Elixir

defmodule BivouacSystemRpi4.MixProject do
use Mix.Project
@app :bivouac_system_rpi4
@source_url "https://code.harton.nz/james/bivouac_system_rpi4"
@version "0.1.0"
@description """
A customised Raspberry Pi 4 buildroot for the Bivouac project.
"""
@upstream_globs [
"{fwup*,post*sh}",
"rootfs_overlay/**/*",
"fwup_include/**/*",
"linux/**/*",
"*.dts",
"*.txt"
]
def project do
[
app: @app,
version: @version,
elixir: "~> 1.6",
compilers: Mix.compilers() ++ [:nerves_package],
nerves_package: nerves_package(),
description: @description,
package: package(),
deps: deps(),
aliases: [
loadconfig: [&bootstrap/1],
compile: [&upstream_wrap("compile", "nerves_system_rpi4", &1)],
"nerves.artifact": [&upstream_wrap("nerves.artifact", "nerves_system_rpi4", &1)],
"nerves.system.lint": [&upstream_wrap("nerves.system.lint", "nerves_system_rpi4", &1)],
clean: [&upstream_wrap("clean", "nerves_system_rpi4", &1)]
],
docs: docs(),
preferred_cli_env: %{
docs: :docs,
"hex.build": :docs,
"hex.publish": :docs,
"git_ops.release": :docs
}
]
end
def application do
[extra_applications: [:eex]]
end
defp bootstrap(args) do
set_target()
Application.start(:nerves_bootstrap)
Mix.Task.run("loadconfig", args)
end
defp nerves_package do
[
type: :system,
artifact_sites: [
{:gitea_releases, "code.harton.nz/bivouac/bivouac_system_rpi4"}
],
build_runner_opts: build_runner_opts(),
platform: Nerves.System.BR,
platform_config: [
defconfig: "bivouac_defconfig"
],
# The :env key is an optional experimental feature for adding environment
# variables to the crosscompile environment. These are intended for
# llvm-based tooling that may need more precise processor information.
env: [
{"TARGET_ARCH", "aarch64"},
{"TARGET_OS", "linux"},
{"TARGET_ABI", "gnu"},
{"TARGET_GCC_FLAGS",
"-mabi=lp64 -fstack-protector-strong -mcpu=cortex-a72 -fPIE -pie -Wl,-z,now -Wl,-z,relro"}
],
checksum: package_files()
]
end
defp deps do
[
# {:nerves, "~> 1.5.4 or ~> 1.6.0 or ~> 1.7.15 or ~> 1.8", runtime: false},
{:nerves,
github: "jimsynz/nerves", branch: "add-gitea-artifacts", override: true, runtime: false},
{:nerves_system_br, "1.24.1", runtime: false},
{:nerves_toolchain_aarch64_nerves_linux_gnu, "~> 1.8.0", runtime: false},
{:nerves_system_linter, "~> 0.4", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.22", only: :docs, runtime: false},
{:git_ops, "~> 2.6", only: :docs, runtime: false}
]
end
defp docs do
[
extras: ["README.md", "CHANGELOG.md"],
main: "readme",
source_ref: "v#{@version}",
source_url: @source_url,
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
]
end
defp package do
[
files: package_files(),
licenses: ["HL3-FULL"],
links: %{"Code" => @source_url}
]
end
defp package_files do
[
"bivouac_defconfig",
"CHANGELOG.md",
"Config.in",
"LICENSE.md",
"linux-6.1.defconfig",
"mix.exs",
"README.md"
]
end
defp build_runner_opts() do
# Download source files first to get download errors right away.
[make_args: primary_site() ++ ["source", "all", "legal-info"]]
end
defp primary_site() do
case System.get_env("BR2_PRIMARY_SITE") do
nil -> []
primary_site -> ["BR2_PRIMARY_SITE=#{primary_site}"]
end
end
defp set_target() do
if function_exported?(Mix, :target, 1) do
apply(Mix, :target, [:target])
else
System.put_env("MIX_TARGET", "target")
end
end
defp upstream_wrap(task, upstream_path, args) do
upstream_files =
__DIR__
|> Path.join(upstream_path)
|> then(fn path ->
Enum.map(@upstream_globs, &Path.join(path, &1))
end)
|> Enum.flat_map(&Path.wildcard/1)
|> Enum.reject(&File.dir?/1)
{:ok, created_files} =
Enum.reduce_while(upstream_files, {:ok, []}, fn source_path, {:ok, created_files} ->
target_path = String.replace(source_path, "/#{upstream_path}", "")
with :ok <- File.mkdir_p(Path.dirname(target_path)),
false <- File.exists?(target_path),
:ok <- File.cp(source_path, target_path) do
{:cont, {:ok, [target_path | created_files]}}
else
true -> {:cont, {:ok, created_files}}
error -> {:halt, error}
end
end)
version_path =
__DIR__
|> Path.join("VERSION")
:ok = File.write(version_path, @version)
Mix.Task.run(task, args)
File.rm(version_path)
Enum.each(created_files, &File.rm/1)
end
end