fusesoc icon indicating copy to clipboard operation
fusesoc copied to clipboard

Add support for ternary operator for use with flags

Open shareefj opened this issue 3 years ago • 3 comments

The current flag implementation allows the user to optionally include dependencies (or files or set parameters etc) based on the flag being true of false:

targets:
  lint:
    <<: *default
    filesets_append:
      - flag ? (optional_fileset)

However, if you want to switch between two options based on a flag, then it quickly becomes quite ugly:

targets:
  lint:
    <<: *default
    filesets_append:
      - flag ? (optional_fileset)
      - "!flag ? (alternate_fileset)"

and this quickly gets out of order when you use more than one flag:

targets:
  lint:
    <<: *default
    filesets_append:
      - "!flag_0 ? ( !flag_1 ? ( !flag_2 ? (optional_fileset)))"

I think a umber of the issues we've had trying to express a logical combination of flags would be simplified by having a ternary operator:

targets:
  lint:
    <<: *default
    filesets_append:
      - flag ? (tru_fileset) : (false_fileset)

Is this something worth perusing?

shareefj avatar Jun 16 '22 08:06 shareefj

I want to give this whole expression parsing thing a proper think-through. The current implementation is a subset of the syntax available for Gentoo ebuilds. Originally I was hoping to find a reasonably stand-alone ebuild expression parser to get all those features for free, but in my investigations it looks like the ones that exist are too deeply embedded into their code bases to be easily extractable.

So failing that, I'm considering some other expression parser that can handle variables, comparisons, conditionals and basic math operations but not much more. Have been trying to find something existing to avoid having to invent a whole new syntax but haven't found anything.

So, right now I'm instead considering to actually spec out a custom syntax. What you suggest could very well be part of that syntax, but let's try to make a simple spec first to avoid extending the current syntax in a way that would make other things harder to implement.

olofk avatar Nov 26 '22 00:11 olofk

If there is a voting system, I would upvote this feature request.

jdwk avatar Apr 26 '23 21:04 jdwk