Skip to content

Commit

Permalink
unifies os_info between zig_get and zigler
Browse files Browse the repository at this point in the history
  • Loading branch information
ityonemo committed Aug 5, 2024
1 parent 5da5c1f commit 656d832
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
- name: Run Tests
env:
RUNNING_CI: "true"
CI_LOG_LEVEL: "info"
CI_LOG_LEVEL: warning
run: mix test --exclude no_ci
26 changes: 14 additions & 12 deletions installer/mix.tasks/zig.get.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
defmodule Zig.Get do
def os_info do
:system_architecture
|> :erlang.system_info()
|> to_string
|> String.split("-")
|> decode_os_info()
end

defp decode_os_info([arch, "apple" | _]), do: {"macos", arch}
defp decode_os_info([arch, _vendor, os | _]), do: {os, arch}
end

defmodule Mix.Tasks.Zig.Get do
use Mix.Task

Expand Down Expand Up @@ -88,7 +101,7 @@ defmodule Mix.Tasks.Zig.Get do
@default_version Zig.Get.MixProject.project()[:version]

defp defaults do
{os, arch} = os_info()
{os, arch} = Zig.Get.os_info()

%__MODULE__{
version: @default_version,
Expand All @@ -98,17 +111,6 @@ defmodule Mix.Tasks.Zig.Get do
}
end

defp os_info do
:system_architecture
|> :erlang.system_info()
|> to_string
|> String.split("-")
|> decode_os_info()
end

defp decode_os_info([arch, "apple" | _]), do: {"macos", arch}
defp decode_os_info([arch, _vendor, os | _]), do: {os, arch}

defp ensure_tar(%{os: "windows"} = opts), do: opts

defp ensure_tar(opts) do
Expand Down
12 changes: 1 addition & 11 deletions lib/zig/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ defmodule Zig.Command do
end

defp versioned_path(path) do
{os, arch} = os_info()
{os, arch} = Zig.Get.os_info()

zig_executable = Path.join(path, "zig-#{os}-#{arch}-#{@default_version}/zig")

Expand All @@ -174,16 +174,6 @@ defmodule Zig.Command do
if File.exists?(zig_executable), do: zig_executable
end

defp os_info do
:system_architecture
|> :erlang.system_info()
|> to_string
|> String.split("-")
|> decode_os_info()
end

defp decode_os_info([arch, _vendor, os | _]), do: {os, arch}

defp src_lib_name(module) do
case {Target.resolve(), :os.type()} do
{nil, {:unix, :darwin}} ->
Expand Down

0 comments on commit 656d832

Please sign in to comment.