From fe94636ac3353e737299463a47e5afb0c6dd24ff Mon Sep 17 00:00:00 2001 From: demostanis Date: Sat, 10 Sep 2022 18:17:36 +0200 Subject: [PATCH] Ports: Add a kakoune port --- Ports/AvailablePorts.md | 1 + Ports/kakoune/package.sh | 9 +++ ...0001-Use-proc-self-exe-on-SerenityOS.patch | 25 +++++++ .../0002-Use-bash-instead-of-bin-sh.patch | 66 +++++++++++++++++++ Ports/kakoune/patches/ReadMe.md | 9 +++ 5 files changed, 110 insertions(+) create mode 100755 Ports/kakoune/package.sh create mode 100644 Ports/kakoune/patches/0001-Use-proc-self-exe-on-SerenityOS.patch create mode 100644 Ports/kakoune/patches/0002-Use-bash-instead-of-bin-sh.patch create mode 100644 Ports/kakoune/patches/ReadMe.md diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md index c7374f9e2cd..e84facc9636 100644 --- a/Ports/AvailablePorts.md +++ b/Ports/AvailablePorts.md @@ -98,6 +98,7 @@ This list is also available at [ports.serenityos.net](https://ports.serenityos.n | [`joe`](joe/) | joe's own editor | 4.6 | https://joe-editor.sourceforge.io/ | | [`jot`](jot/) | jot (OpenBSD) | 6.6 | https://github.com/ibara/libpuffy | | [`jq`](jq/) | jq | 1.6 | https://stedolan.github.io/jq/ | +| [`kakoune`](kakoune/) | Modal text editor | 24d6072 | https://github.com/mawww/kakoune | | [`klong`](klong/) | Klong | 20220315 | https://t3x.org/klong/ | | [`less`](less/) | less | 590 | https://www.greenwoodsoftware.com/less/ | | [`libarchive`](libarchive/) | libarchive | 3.6.1 | https://libarchive.org/ | diff --git a/Ports/kakoune/package.sh b/Ports/kakoune/package.sh new file mode 100755 index 00000000000..75388e12556 --- /dev/null +++ b/Ports/kakoune/package.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env -S bash ../.port_include.sh +port='kakoune' +version='24d6072353f7c7e7cac84b4eb085036a8c852f96' +files="https://github.com/mawww/kakoune/archive/${version}.tar.gz ${version}.tar.gz 16440b204770972f318e24e4e178ada474b7cfeb029cefa69e9ff035700a129e" +auth_type='sha256' +depends=("bash" "sed") +makeopts+=( + "LDFLAGS=-L${DESTDIR}/usr/local/lib" +) diff --git a/Ports/kakoune/patches/0001-Use-proc-self-exe-on-SerenityOS.patch b/Ports/kakoune/patches/0001-Use-proc-self-exe-on-SerenityOS.patch new file mode 100644 index 00000000000..10f18861d75 --- /dev/null +++ b/Ports/kakoune/patches/0001-Use-proc-self-exe-on-SerenityOS.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: demostanis +Date: Sat, 10 Sep 2022 20:19:23 +0200 +Subject: [PATCH] Use /proc/self/exe on SerenityOS + +--- + src/file.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/file.cc b/src/file.cc +index d38c956..9c74364 100644 +--- a/src/file.cc ++++ b/src/file.cc +@@ -603,7 +603,7 @@ FsStatus get_fs_status(StringView filename) + String get_kak_binary_path() + { + char buffer[2048]; +-#if defined(__linux__) or defined(__CYGWIN__) or defined(__gnu_hurd__) ++#if defined(__linux__) or defined(__CYGWIN__) or defined(__gnu_hurd__) or defined(__serenity__) + ssize_t res = readlink("/proc/self/exe", buffer, 2048); + kak_assert(res != -1); + buffer[res] = '\0'; +-- +2.37.3 + diff --git a/Ports/kakoune/patches/0002-Use-bash-instead-of-bin-sh.patch b/Ports/kakoune/patches/0002-Use-bash-instead-of-bin-sh.patch new file mode 100644 index 00000000000..23b591a0a36 --- /dev/null +++ b/Ports/kakoune/patches/0002-Use-bash-instead-of-bin-sh.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: demostanis +Date: Sat, 10 Sep 2022 23:32:51 +0200 +Subject: [PATCH] Use bash instead of /bin/sh + +--- + src/shell_manager.cc | 43 +++++-------------------------------------- + 1 file changed, 5 insertions(+), 38 deletions(-) + +diff --git a/src/shell_manager.cc b/src/shell_manager.cc +index 96cfb06..4eb71db 100644 +--- a/src/shell_manager.cc ++++ b/src/shell_manager.cc +@@ -34,44 +34,11 @@ namespace Kakoune + ShellManager::ShellManager(ConstArrayView builtin_env_vars) + : m_env_vars{builtin_env_vars} + { +- auto is_executable = [](StringView path) { +- struct stat st; +- if (stat(path.zstr(), &st)) +- return false; +- +- bool executable = (st.st_mode & S_IXUSR) +- | (st.st_mode & S_IXGRP) +- | (st.st_mode & S_IXOTH); +- return S_ISREG(st.st_mode) and executable; +- }; +- +- if (const char* shell = getenv("KAKOUNE_POSIX_SHELL")) +- { +- if (not is_executable(shell)) +- throw runtime_error{format("KAKOUNE_POSIX_SHELL '{}' is not executable", shell)}; +- m_shell = shell; +- } +- else // Get a guaranteed to be POSIX shell binary +- { +- #if defined(_CS_PATH) +- auto size = confstr(_CS_PATH, nullptr, 0); +- String path; path.resize(size-1, 0); +- confstr(_CS_PATH, path.data(), size); +- #else +- StringView path = "/bin:/usr/bin"; +- #endif +- for (auto dir : StringView{path} | split(':')) +- { +- auto candidate = format("{}/sh", dir); +- if (is_executable(candidate)) +- { +- m_shell = std::move(candidate); +- break; +- } +- } +- if (m_shell.empty()) +- throw runtime_error{format("unable to find a posix shell in {}", path)}; +- } ++ // We hardcode bash since /bin/sh (/bin/Shell) is not ++ // a POSIX-compliant shell, that will error out when ++ // fed with Kakoune's scripts. It is expected to be ++ // installed along with the port. ++ m_shell = "/usr/local/bin/bash"; + + // Add Kakoune binary location to the path to guarantee that %sh{ ... } + // have access to the kak command regardless of if the user installed it +-- +2.37.3 + diff --git a/Ports/kakoune/patches/ReadMe.md b/Ports/kakoune/patches/ReadMe.md new file mode 100644 index 00000000000..ba302dae339 --- /dev/null +++ b/Ports/kakoune/patches/ReadMe.md @@ -0,0 +1,9 @@ +# Patches for Kakoune on SerenityOS + +## `0001-Use-proc-self-exe-on-SerenityOS.patch` + +Use /proc/self/exe on SerenityOS + +## `0002-Use-bash-instead-of-bin-sh.patch` + +Use bash instead of /bin/sh