Merge pull request #311688 from onemoresuza/hare-fix-mime-module

This commit is contained in:
Sandro 2024-06-02 23:49:01 +02:00 committed by GitHub
commit 8c1597626f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 3 deletions

View File

@ -0,0 +1,13 @@
diff --git a/mime/system.ha b/mime/system.ha
index 73ff3496..42e7b640 100644
--- a/mime/system.ha
+++ b/mime/system.ha
@@ -11,7 +11,7 @@ use strings;
use types;
// Path to the system MIME database.
-export def SYSTEM_DB: str = "/etc/mime.types";
+export def SYSTEM_DB: str = "@mailcap@/etc/mime.types";
@init fn init() void = {
// Done in a separate function so we can discard errors here

View File

@ -0,0 +1,28 @@
{
hare,
runCommandNoCC,
writeText,
}:
let
mainDotHare = writeText "main.ha" ''
use fmt;
use mime;
export fn main() void = {
const ext = "json";
match(mime::lookup_ext(ext)) {
case let mime: const *mime::mimetype =>
fmt::printfln("Found mimetype for extension `{}`: {}", ext, mime.mime)!;
case null =>
fmt::fatalf("Could not find mimetype for `{}`", ext);
};
};
'';
in
runCommandNoCC "mime-module-test" { nativeBuildInputs = [ hare ]; } ''
HARECACHE="$(mktemp -d)"
export HARECACHE
readonly binout="test-bin"
hare build -qRo "$binout" ${mainDotHare}
./$binout
: 1>$out
''

View File

@ -7,6 +7,7 @@
gitUpdater,
scdoc,
tzdata,
mailcap,
substituteAll,
fetchpatch,
callPackage,
@ -116,6 +117,11 @@ stdenv.mkDerivation (finalAttrs: {
url = "https://git.sr.ht/~sircmpwn/hare/commit/e35f2284774436f422e06f0e8d290b173ced1677.patch";
hash = "sha256-A59bGO/9tOghV8/MomTxd8xRExkHVdoMom2d+HTfQGg=";
})
# Use mailcap `/etc/mime.types` for Hare's mime module
(substituteAll {
src = ./003-use-mailcap-for-mimetypes.patch;
inherit mailcap;
})
];
nativeBuildInputs = [
@ -169,9 +175,13 @@ stdenv.mkDerivation (finalAttrs: {
passthru = {
updateScript = gitUpdater { };
tests = lib.optionalAttrs enableCrossCompilation {
crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
};
tests =
lib.optionalAttrs enableCrossCompilation {
crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
}
// lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; };
};
};
meta = {