Skip to content

Commit 1519cdf

Browse files
GZGavinZhaojoebonrichie
authored andcommitted
Add ghc-pkg trigger
Signed-off-by: Gavin Zhao <git@gzgz.dev>
1 parent 207cb7f commit 1519cdf

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/build/
22
/state
3+
.cache

src/context.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ static const UscHandler *usc_handlers[] = {
9999
&usc_handler_sshd,
100100

101101
&usc_handler_udev_rules,
102+
103+
&usc_handler_ghc_pkg,
102104
};
103105

104106
/**

src/handlers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ extern UscHandler usc_handler_sshd;
7373

7474
extern UscHandler usc_handler_udev_rules;
7575

76+
extern UscHandler usc_handler_ghc_pkg;
77+
7678
/*
7779
* Editor modelines - https://www.wireshark.org/tools/modelines.html
7880
*

src/handlers/ghc-pkg.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* This file is part of usysconf.
3+
*
4+
* Copyright © 2017-2019 Solus Project
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*/
11+
12+
#define _GNU_SOURCE
13+
14+
#include "context.h"
15+
#include "files.h"
16+
#include "util.h"
17+
18+
static const char *library_paths[] = {
19+
/* Match all Haskell package paths directories and run ghc-pkg for them */
20+
"/usr/lib64/ghc-*",
21+
};
22+
23+
/**
24+
* Update the global Haskell package cache (`ghc-pkg recache`) when library directories update
25+
*/
26+
static UscHandlerStatus usc_handler_ghc_pkg_exec(UscContext *ctx, const char *path)
27+
{
28+
char *command[] = {
29+
"/usr/bin/ghc-pkg",
30+
"recache",
31+
"--global",
32+
NULL, /* Terminator */
33+
};
34+
35+
if (!usc_file_is_dir(path)) {
36+
return USC_HANDLER_SKIP;
37+
}
38+
39+
usc_context_emit_task_start(ctx, "Updating Haskell library cache");
40+
int ret = usc_exec_command(command);
41+
if (ret != 0) {
42+
usc_context_emit_task_finish(ctx, USC_HANDLER_FAIL);
43+
return USC_HANDLER_FAIL | USC_HANDLER_BREAK;
44+
}
45+
usc_context_emit_task_finish(ctx, USC_HANDLER_SUCCESS);
46+
/* Only want to run once for all of our globs */
47+
return USC_HANDLER_SUCCESS | USC_HANDLER_BREAK;
48+
}
49+
50+
const UscHandler usc_handler_ghc_pkg = {
51+
.name = "ghc-pkg",
52+
.description = "Update Haskell library cache",
53+
.required_bin = "/usr/bin/ghc-pkg",
54+
.exec = usc_handler_ghc_pkg_exec,
55+
.paths = library_paths,
56+
.n_paths = ARRAY_SIZE(library_paths),
57+
};
58+
59+
/*
60+
* Editor modelines - https://www.wireshark.org/tools/modelines.html
61+
*
62+
* Local variables:
63+
* c-basic-offset: 8
64+
* tab-width: 8
65+
* indent-tabs-mode: nil
66+
* End:
67+
*
68+
* vi: set shiftwidth=8 tabstop=8 expandtab:
69+
* :indentSize=8:tabSize=8:noTabs=true:
70+
*/

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ xdg_handlers = [
1212
]
1313

1414
handlers = [
15+
'ghc-pkg',
1516
'ldconfig',
1617
'hwdb',
1718
'mandb',

0 commit comments

Comments
 (0)