From 3afe31a9e67a3dc224b8518fc3f7127acfe075a0 Mon Sep 17 00:00:00 2001 From: Brian Callahan Date: Fri, 5 Jul 2024 06:56:25 -0400 Subject: [PATCH] Add OpenBSD support. (#1705) Co-authored-by: Alejandro R Mosteo --- README.md | 8 ++-- alire.gpr | 4 ++ alire.toml | 3 +- alire_common.gpr | 1 + alr.gpr | 1 + alr_env.gpr | 1 + dev/functions.sh | 6 +++ doc/catalog-format-spec.md | 4 +- src/alire/alire-directories.adb | 2 +- src/alire/alire-platforms.ads | 3 +- .../os_openbsd/alire-check_absolute_path.adb | 7 ++++ .../alire-platforms-current__openbsd.adb | 40 +++++++++++++++++++ .../alire-platforms-folders__openbsd.adb | 34 ++++++++++++++++ 13 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 src/alire/os_openbsd/alire-check_absolute_path.adb create mode 100644 src/alire/os_openbsd/alire-platforms-current__openbsd.adb create mode 100644 src/alire/os_openbsd/alire-platforms-folders__openbsd.adb diff --git a/README.md b/README.md index e4ca6a0c..d0e6223d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ https://alire.ada.dev/ ## TL;DR ## -Available for Linux/macOS/Windows/FreeBSD. +Available for Linux/macOS/Windows/FreeBSD/OpenBSD. Download the latest stable version from the [Releases](https://github.com/alire-project/alire/releases) page. See the [Getting Started](doc/getting-started.md) guide for binary downloads. @@ -35,7 +35,7 @@ See the [Getting Started](doc/getting-started.md) guide. The build process of `alr` is straighforward and depends only on a recent GNAT Ada 2012 compiler. All dependencies are included as submodules. A project file (`alr_env.gpr`) is provided to drive the build with all necessary configuration (which is also valid for editing with GNAT Studio). -The ALIRE_OS environment variable must be set to the OS for which `alr` is being build, taking one of the values in `freebsd`, `linux`, `macos`, `windows`. +The ALIRE_OS environment variable must be set to the OS for which `alr` is being build, taking one of the values in `freebsd`, `openbsd`, `linux`, `macos`, `windows`. Follow these steps: @@ -43,7 +43,7 @@ Follow these steps: 1. Enter the cloned repository folder. 1. Build the executable: * if you have Bash on your system: `dev/build.sh` - * if you don't have Bash on your system: `ALIRE_OS= gprbuild -j0 -p -P alr_env` + * if you don't have Bash on your system: `ALIRE_OS= gprbuild -j0 -p -P alr_env` The binary will be found at `bin/alr`. You can run `alr version` to see version and diagnostics information. @@ -81,7 +81,7 @@ environment `alr` is using with `alr printenv`. ## Supported platforms ## -Alire can be built on Linux, macOS, Windows, and FreeBSD. +Alire can be built on Linux, macOS, Windows, FreeBSD, and OpenBSD. Alire requires a recent Ada 2012 compiler. In practice, this currently means the latest [GNAT Community](https://www.adacore.com/download) or a somewhat diff --git a/alire.gpr b/alire.gpr index 3490e92d..c15a633c 100644 --- a/alire.gpr +++ b/alire.gpr @@ -28,6 +28,7 @@ library project Alire is case Alire_Common.Host_Os is when "freebsd" => Src_Dirs := Src_Dirs & ("src/alire/os_freebsd"); + when "openbsd" => Src_Dirs := Src_Dirs & ("src/alire/os_openbsd"); when "linux" => Src_Dirs := Src_Dirs & ("src/alire/os_linux"); when "macos" => Src_Dirs := Src_Dirs & ("src/alire/os_macos"); when "windows" => Src_Dirs := Src_Dirs & ("src/alire/os_windows"); @@ -38,6 +39,9 @@ library project Alire is when "freebsd" => for body ("Alire.Platforms.Current") use "alire-platforms-current__freebsd.adb"; for body ("Alire.Platforms.Folders") use "alire-platforms-folders__freebsd.adb"; + when "openbsd" => + for body ("Alire.Platforms.Current") use "alire-platforms-current__openbsd.adb"; + for body ("Alire.Platforms.Folders") use "alire-platforms-folders__openbsd.adb"; when "linux" => for body ("Alire.Platforms.Current") use "alire-platforms-current__linux.adb"; for body ("Alire.Platforms.Folders") use "alire-platforms-folders__linux.adb"; diff --git a/alire.toml b/alire.toml index 8821dc68..7fb33a2c 100644 --- a/alire.toml +++ b/alire.toml @@ -40,6 +40,7 @@ CLIC_LIBRARY_TYPE="static" # Building alr requires the explicit setting of this variable [gpr-set-externals."case(os)"] freebsd = { ALIRE_OS = "freebsd" } +openbsd = { ALIRE_OS = "openbsd" } linux = { ALIRE_OS = "linux" } macos = { ALIRE_OS = "macos" } windows = { ALIRE_OS = "windows" } @@ -116,4 +117,4 @@ command = ["pwsh", "scripts/version-patcher.ps1", "_or_later"] [actions.'case(os)'.'...'] type = "post-build" -command = ["scripts/version-patcher.sh", "_or_later"] \ No newline at end of file +command = ["scripts/version-patcher.sh", "_or_later"] diff --git a/alire_common.gpr b/alire_common.gpr index 39dabb98..fe88657b 100644 --- a/alire_common.gpr +++ b/alire_common.gpr @@ -4,6 +4,7 @@ abstract project Alire_Common is type Host_OSes is ("linux", "freebsd", + "openbsd", "macos", "windows"); diff --git a/alr.gpr b/alr.gpr index f821cd13..00620f5d 100644 --- a/alr.gpr +++ b/alr.gpr @@ -14,6 +14,7 @@ project Alr is case Alire_Common.Host_Os is when "freebsd" => Src_Dirs := Src_Dirs & ("src/alr/os_linux"); + when "openbsd" => Src_Dirs := Src_Dirs & ("src/alr/os_linux"); when "linux" => Src_Dirs := Src_Dirs & ("src/alr/os_linux"); when "macos" => Src_Dirs := Src_Dirs & ("src/alr/os_macos"); when "windows" => Src_Dirs := Src_Dirs & ("src/alr/os_windows"); diff --git a/alr_env.gpr b/alr_env.gpr index 0fbb9ba1..b391c975 100644 --- a/alr_env.gpr +++ b/alr_env.gpr @@ -36,6 +36,7 @@ aggregate project Alr_Env is case Alire_Common.Host_Os is when "freebsd" => for External ("GNATCOLL_OS") use "unix"; + when "openbsd" => for External ("GNATCOLL_OS") use "unix"; when "linux" => for External ("GNATCOLL_OS") use "unix"; when "macos" => for External ("GNATCOLL_OS") use "osx"; when "windows" => for External ("GNATCOLL_OS") use "windows"; diff --git a/dev/functions.sh b/dev/functions.sh index 9ded1e89..d7631450 100755 --- a/dev/functions.sh +++ b/dev/functions.sh @@ -13,6 +13,9 @@ function guess_OS() { "freebsd") echo freebsd ;; + "openbsd") + echo openbsd + ;; "darwin"*) # varies with versions: darwin18, darwin19, etc. echo macos ;; @@ -37,6 +40,9 @@ function get_OS() { "FreeBSD") echo freebsd ;; + "OpenBSD") + echo openbsd + ;; "Darwin") echo macos ;; diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index 196aa5ca..5dabab53 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -878,8 +878,8 @@ available.'case(toolchain)'.user = false ## Parameters - - `os`: name of the OS. Currently supported values are: `freebsd`, `linux`, - `macos`, `windows`, and `os-unknown`. + - `os`: name of the OS. Currently supported values are: `freebsd`, `openbsd`, + `linux`, `macos`, `windows`, and `os-unknown`. - `distribution`: name of the Linux distribution or name of the software distribution platform if running on a different OS. Currently supported diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index 4c8142ce..f9551b4d 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -146,7 +146,7 @@ package body Alire.Directories is Keep_Links : constant String := (case Platforms.Current.Operating_System is when Linux => "-d", - when FreeBSD | MacOS => "-R", + when FreeBSD | OpenBSD | MacOS => "-R", when others => raise Program_Error with "Unsupported operation"); begin diff --git a/src/alire/alire-platforms.ads b/src/alire/alire-platforms.ads index f78e08e4..bf879bd7 100644 --- a/src/alire/alire-platforms.ads +++ b/src/alire/alire-platforms.ads @@ -3,7 +3,7 @@ package Alire.Platforms with Preelaborate is -- Platform information necessary for some releases type Extended_Architectures is - (AMD64, -- Equivalent to X86_64 (FreeBSD) + (AMD64, -- Equivalent to X86_64 (FreeBSD/OpenBSD) ARM64, -- Equivalent to AARCH64 End_Of_Duplicates, -- Up to this point, these are architectures that we want to rename to @@ -21,6 +21,7 @@ package Alire.Platforms with Preelaborate is -- See e.g. https://stackoverflow.com/a/45125525/761390 type Operating_Systems is (FreeBSD, + OpenBSD, Linux, MacOS, Windows, diff --git a/src/alire/os_openbsd/alire-check_absolute_path.adb b/src/alire/os_openbsd/alire-check_absolute_path.adb new file mode 100644 index 00000000..01caa2a3 --- /dev/null +++ b/src/alire/os_openbsd/alire-check_absolute_path.adb @@ -0,0 +1,7 @@ +separate (Alire) +function Check_Absolute_Path (Path : Any_Path) return Boolean is +begin + return (Path'Length >= 1 + and then + Path (Path'First) = GNAT.OS_Lib.Directory_Separator); +end Check_Absolute_Path; diff --git a/src/alire/os_openbsd/alire-platforms-current__openbsd.adb b/src/alire/os_openbsd/alire-platforms-current__openbsd.adb new file mode 100644 index 00000000..415056ee --- /dev/null +++ b/src/alire/os_openbsd/alire-platforms-current__openbsd.adb @@ -0,0 +1,40 @@ + +package body Alire.Platforms.Current is + + -- OpenBSD implementation (very close to Linux/FreeBSD) + + --------------------------- + -- Detected_Distribution -- + --------------------------- + + function Detected_Distribution return Platforms.Distributions + is (Platforms.Distribution_Unknown); + + ----------------------- + -- Distribution_Root -- + ----------------------- + + function Distribution_Root return Absolute_Path + is ("/"); + + ---------------------- + -- Load_Environment -- + ---------------------- + + procedure Load_Environment (Ctx : in out Alire.Environment.Context) + is null; + + ---------------------- + -- Operating_System -- + ---------------------- + + function Operating_System return Alire.Platforms.Operating_Systems + is (Alire.Platforms.OpenBSD); + + ---------------- + -- Initialize -- + ---------------- + + procedure Initialize is null; + +end Alire.Platforms.Current; diff --git a/src/alire/os_openbsd/alire-platforms-folders__openbsd.adb b/src/alire/os_openbsd/alire-platforms-folders__openbsd.adb new file mode 100644 index 00000000..51b4d1be --- /dev/null +++ b/src/alire/os_openbsd/alire-platforms-folders__openbsd.adb @@ -0,0 +1,34 @@ +with Ada.Directories; + +with Alire.Platforms.Common; + +package body Alire.Platforms.Folders is + + -- Linux implementation + + ----------- + -- Cache -- + ----------- + + function Cache return Absolute_Path is (Common.XDG_Data_Home); + + ----------- + -- Config-- + ----------- + + function Config return Absolute_Path is (Common.XDG_Config_Home); + + ---------- + -- Home -- + ---------- + + function Home return Absolute_Path is (Common.Unix_Home_Folder); + + ---------- + -- Temp -- + ---------- + + function Temp return Absolute_Path + is (Ada.Directories.Full_Name (Common.Unix_Temp_Folder)); + +end Alire.Platforms.Folders; -- 2.39.5