Skip to content

Commit

Permalink
feat: enhance alsa_lib by adding testing and auto-update functionalit…
Browse files Browse the repository at this point in the history
…ies (#211)

* feat: enhance alsa_lib by adding testing and auto-update functionality

Signed-off-by: Jérémy Audiger <[email protected]>

* feat: update autoUpdate function to make it compatible with brioche-run command

Signed-off-by: Jérémy Audiger <[email protected]>

---------

Signed-off-by: Jérémy Audiger <[email protected]>
  • Loading branch information
jaudiger authored Jan 26, 2025
1 parent 67d1d41 commit 4f8fd12
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion packages/alsa_lib/project.bri
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nushell from "nushell";
import * as std from "std";

export const project = {
Expand All @@ -11,7 +12,7 @@ const source = Brioche.download(
.unarchive("tar", "bzip2")
.peel();

export default function (): std.Recipe<std.Directory> {
export default function alsaLib(): std.Recipe<std.Directory> {
const alsaLib = std.runBash`
./configure --prefix=/
make install DESTDIR="$BRIOCHE_OUTPUT"
Expand All @@ -26,3 +27,54 @@ export default function (): std.Recipe<std.Directory> {
PKG_CONFIG_PATH: { append: [{ path: "lib/pkgconfig" }] },
});
}

export async function test() {
const src = std.file(std.indoc`
#include <stdio.h>
#include <alsa/asoundlib.h>
int main(void)
{
const char *alsa_version = snd_asoundlib_version();
printf("%s", alsa_version);
return 0;
}
`);

const script = std.runBash`
cp "$src" main.c
gcc main.c -o main -lasound
./main | tee "$BRIOCHE_OUTPUT"
`
.dependencies(std.toolchain(), alsaLib())
.env({ src: src });

const result = await script.toFile().read();

// Check that the result contains the expected version
const expected = `${project.version}`;
std.assert(result === expected, `expected '${expected}', got '${result}'`);

return script;
}

export function autoUpdate() {
const src = std.file(std.indoc`
let version = http get https://www.alsa-project.org/files/pub/lib
| lines
| where {|it| ($it | str contains "alsa-lib") and (not ($it | str contains ".sig")) }
| parse --regex '<a href="alsa-lib-(?<version>.+)\.tar\.bz2">'
| sort-by --natural --reverse version
| get 0.version
$env.project | from json | update version $version | to json
`);

return std.withRunnable(std.directory(), {
command: "nu",
args: [src],
env: { project: JSON.stringify(project) },
dependencies: [nushell()],
});
}

0 comments on commit 4f8fd12

Please sign in to comment.