Replies: 1 comment
-
|
A bit of background context too... Previously on Discord, @jaudiger and I were discussing a The idea I mentioned at the time was to get rid of all places that we use So part of the motivation for this idea is to make recipes more expressive without needing to fall back to a Bash script. I thought to open this discussion after seeing this comment today too: https://github.com/brioche-dev/brioche-packages/pull/1603/files#r2481188583 I think the extreme path would be completely forbid |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say we have a build that ends up with a
lib/or alib64/directory in the output-- say, depending on the platform. For consistency, we want to add a symlink fromlibtolib64in the latter case. Today, the easiest way to do that is with a recipe like this:It'd feel more natural to write this with normal TypeScript features, like
if (recipe.contains("lib64") && !recipe.contains("lib")) { ... }, but this has the downside that we'd realistically need to add anawaitin the method, which causes some challenges when used too liberally.Here's another option: we represent this conditional as a recipe, and let the runtime handle it. It could look something like this:
Under the hood, this would serialize to a JSON recipe that would look something like:
{ "type": "when", "test": { "type": "and", "left": {"type": "contains", "recipe": {/* ... */}, "path": "lib64"}, "recipe": {"type": "not", "value": {"type": "contains", "recipe": {/* ... */}, "path": "lib"}}, }, "then": {/* recipe if true */}, "else": {/* recipe if false */}, }So at a high level, the idea is to write recipe conditions with a DSL, which turns into a JSON value that the runtime can handle. It doesn't look nearly as nice as using normal JS features, so this is a trade-off between flexibility and readability.
I think this would fit well with my cross-compilation ideas too too, since this would provide a way to handle platform-specific features, since the runtime would be able to handle conditions based on dynamically-scoped variables (
host,target, etc.).Some open questions / challenges:
std.when/std.ifDSL function be?ifis the most natural name, but it's a JS keyword and so isn't allowed as an identifier in some places.if(test, then, else), but there are many different ways this could be written too. I think some Lisps use a(cond)form, which JS-ified would be more likecond([test, then], [test2, then2], ... ["else", else]), which is probably more readable if you have a lot of else-if conditions.Artifactvalues (File,Directory, orSymlink), while we would need booleans for this change. Are there other places where booleans could appear (e.g. process templates)? Do we want other types of values too, like generic numbers and strings?Beta Was this translation helpful? Give feedback.
All reactions