canonical / craft-application

The basis for *craft applications
https://canonical-craft-application.readthedocs-hosted.com/en/latest
GNU Lesser General Public License v3.0
5 stars 6 forks source link

feat: always process the project's grammar #279

Closed tigarmo closed 3 months ago

tigarmo commented 3 months ago

The problem this commit addresses is this: Consider the following snippet:

parts:
  hello-world:
    plugin: dump
    source:
      - on amd64 to arm64: src/on-amd64-to-arm64
      - on amd64 to armhf: src/on-amd64-to-armhf

... what should happen if the command toolname clean --destructive-mode is executed? Currently it breaks, because the grammar is not processed without an explict target arch (provided directly through the "--build-for" parameter or indirectly via the "--platform" one). This is at least inconvenient, and goes against the guideline we adopted for cleaning projects with multiple infos on the build-plan (accept the "wrong" config and remove the files).

There is no obvious, perfect answer here because at the stage that the grammar is currently processed we don't know yet what kind of command we are dealing with. Maybe the command needs the parts, maybe it doesn't. Possibly as a stop gap, this commit introduces the following logic:

This last option is risky because there's a chance it won't generate a valid parts declaration (see the new tests). That's not as bad as it looks, because either the command won't need the parts (and thus that declaration will be ignored), or it will and the lifecycle service will then generate its own error.