From 5ba0de873063cb75ccd99ea53059035543932be8 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 15 Sep 2024 13:44:41 -0800 Subject: [PATCH] Print the rust version. --- docs/godot-sandbox.yaml | 3 +++ .../controllers/version_controller.ex | 17 ++++++++++++++--- test/support/conn_case.ex | 1 - test/web_compiler_version_controller_test.exs | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/godot-sandbox.yaml b/docs/godot-sandbox.yaml index dc65066..2cce515 100644 --- a/docs/godot-sandbox.yaml +++ b/docs/godot-sandbox.yaml @@ -92,6 +92,9 @@ paths: gccVersion: type: string example: "GCC 9.3.0" + rustVersion: + type: string + example: "rustc 1.58.0" /cache/{hash}: get: tags: diff --git a/lib/web_compiler_web/controllers/version_controller.ex b/lib/web_compiler_web/controllers/version_controller.ex index e6f0583..0492a37 100644 --- a/lib/web_compiler_web/controllers/version_controller.ex +++ b/lib/web_compiler_web/controllers/version_controller.ex @@ -5,17 +5,28 @@ defmodule WebCompilerWeb.VersionController do {gcc_version_output, 0} = System.cmd("gcc", ["--version"]) gcc_version = parse_gcc_version(gcc_version_output) + {rust_version_output, 0} = System.cmd("rustc", ["--version"]) + rust_version = parse_rust_version(rust_version_output) + version_info = %{ apiVersion: "1.0.0", - gccVersion: gcc_version + gccVersion: gcc_version, + rustVersion: rust_version } json(conn, version_info) end defp parse_gcc_version(output) do - # Extract the version number from the first line of the output + # Extract and trim the version number from the first line of the output [first_line | _] = String.split(output, "\n") - Regex.replace(~r/^gcc \(.*\) (\d+\.\d+\.\d+).*$/, first_line, "\\1") + version = Regex.replace(~r/^gcc \(.*\) (\d+\.\d+\.\d+).*$/, first_line, "\\1") + String.trim(version) + end + + defp parse_rust_version(output) do + # Extract and trim the version number from the output + version = Regex.replace(~r/^rustc (\d+\.\d+\.\d+).*$/, output, "\\1") + String.trim(version) end end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 2d973fc..49ee1e3 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -32,7 +32,6 @@ defmodule WebCompilerWeb.ConnCase do end setup tags do - WebCompiler.DataCase.setup_sandbox(tags) {:ok, conn: Phoenix.ConnTest.build_conn()} end end diff --git a/test/web_compiler_version_controller_test.exs b/test/web_compiler_version_controller_test.exs index c42f2ee..2278622 100644 --- a/test/web_compiler_version_controller_test.exs +++ b/test/web_compiler_version_controller_test.exs @@ -14,4 +14,19 @@ defmodule WebCompilerWeb.VersionControllerTest do assert major_version >= 13 end end + + test "returns Rust version 1.83 or higher", %{conn: conn} do + conn = get(conn, "/version") + assert json_response(conn, 200) + version_data = json_response(conn, 200) + rust_version = version_data["rustVersion"] + + version_struct = rust_version + |> Version.parse!() + + major_version = version_struct.major + minor_version = version_struct.minor + + assert major_version >= 1 and minor_version >= 83 + end end