Skip to content

Conditional list entries are reordered after unconditional entries #779

@BaseHardware

Description

@BaseHardware

Description

I found an ordering issue when using conditional expressions in ordered list fields.

When a conditional entry evaluates to true, I would expect it to remain at its original position in the list. However, it appears that conditional entries are moved to the end of the resolved list.

This can cause unexpected behavior when the order of filesets, dependencies, imports, or scripts matters.

Minimal example with the expected and actual behavior

Given a list like this:

      post_build:
        - "target_chip_Virtex ? (generate_mcs_Virtex)"
        - "target_chip_Artix ? (generate_mcs_Artix)"
        - "post_build_script"

and assuming target_chip_Virtex evaluates to true (a flag named target_chip is set to Virtex), I would expect the resolved order to be:

      post_build:
        - "generate_mcs_Virtex"
        - "post_build_script"

However, the actual resolved order appears to be:

      post_build:
        - "post_build_script"
        - "generate_mcs_Virtex"

Workaround for my case:

As a workaround, I made the originally unconditional post_build_script entry conditional as well, by adding both the positive and negative forms of a dummy flag:

      post_build:
        - "target_chip_Virtex ? (generate_mcs_Virtex)"
        - "target_chip_Artix ? (generate_mcs_Artix)"
        # A trick to ensure the order of execution of scripts
        # (generate_mcs* must be called BEFORE post_build_script)
        - "_ ? (post_build_script)"
        - "!_ ? (post_build_script)"

This works in my case because exactly one of the two dummy-flag conditions should evaluate to true, so post_build_script is also treated as a conditional entry and the relative order is preserved.

Why this matters

Some FuseSoC fields are order-sensitive. For example, the order of imported filesets, dependencies, or scripts may affect the final build result.

If conditional entries are reordered, this can lead to subtle and unintended bugs, especially when a conditional fileset, dependency, or script must be processed before later entries.

Suggested fix

When resolving conditional expressions in ordered lists, entries that evaluate to true should be inserted at the same position where the conditional expression originally appeared, rather than being appended to the end of the list.

Environment

  • FuseSoC version: 2.4.3
  • Python version: Python 3.12
  • OS: Fedora 42
  • Backend / tool: Vivado

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions