Open-CMSIS-Pack / devtools

Open-CMSIS-Pack development tools - C++
Apache License 2.0
74 stars 57 forks source link

[csolution] running a generator may require to specify the `packID` to ensure uniqueness #1093

Open jkrech opened 1 year ago

jkrech commented 1 year ago

Describe the bug In case there is two packs with selected generator components using the same generatorID there is no means of choosing a generator uniquely.

Background: the scope of generator descriptions is limited to the current pdsc file. There is no mechanism to ensure unique naming of generatorIDs across packs. Therefore one needs to specify the packID + generatorID for a unique reference to a generator.

To Reproduce Create two packs Test.A.1.0.0.pack and Test.B.1.0.0 with generator components. Call both generators "generator" <generator id="generator">. Create a cproject with the generator components selected from both packs and run:

csolution list generators mytest.csolution.yml
generator ( )
generator ( )

Expected behavior

csolution list generators mytest.csolution.yml
Test::A@1.0.0 generator ( )
Test::B@1.0.0 generator ( )

Invoking the generator would require an additional flag e.g. -p

csolution run mytest.csolution.yml -g generator -p Test::A@1.0.0

If -p is not specified and there is ambiguity an error is thrown and the command aborted. If no pack version is specified the one specified in YAML input is used. If there is no version specified in YAML input then the latest installed pack version is used. If the version specified at the commandline conflicts with the version specified through YAML input and error is thrown and the command aborted.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

ReinhardKeil commented 5 months ago

I believe it is possible to define the generator directly in the pack different, for example with:

<generator id="generator-packid">

I believe this would do the same job.

badreddinebenjemaa commented 4 months ago

Hi Reinhard,

Based on your proposal: Manual definition of the "generator-Id" by the "pack PDSC writer" based on the following pattern "generatorName-PackID":

  1. "generator-id" strict rules/naming conventions should be added here to prohibit having special chars not allowed at the file system level (e.g: \ / ? * : < > ") (a control to add at the PDSC schema level and in the packchk tool?).

  2. "packId" included in the generator identifier naming conventions should be clarified also:

    • we should avoid following this pattern : <vendor>::<name>@<version> (since : char is not allowed at FileSystem level)
    • use instead the following patterns ?
      <vendor>.<name>.<version>
      <vendor>.<name>@<version>
      Others you may suggest ?

      Expected Full GeneratorId pattern : (to be confirmed): <generatorName>-<vendor>.<name>@<version> Ex: CubeGenerator-<vendor>.<name>@<version>

Observed drawbacks here:
having also the pack version in the generatorId means that it will be the responsibility of the pack developer to guarantee the alignment of the all occurrences of this generatorId in the PDSC (generators node, generator attribute at component level), this seems to be very error prone across different packs.

Other alternatives that could be analyzed/discussed:

since csolution tool is able to identify the generator original Pack (through the"from-pack" attribute), maybe be it would be more convenient that the tool should guarantee the uniqueness of Generators invocations per pack (by appending the pack Id to the Generators PDSC declared Id at invocation time ? This mechanism is already used for component identification inside a pack (always append the original packId before the component id description). @Torbjorn-Svensson, based on your latest shared feedback, could you comment further this approach. thank you

Torbjorn-Svensson commented 4 months ago

I think you explained it all well @badreddinebenjemaa. What I would like is that the tool helps to identify the generators in a way that is guaranteed to be unique. If it's up to the pack creator to uniquely name the generators, there will likely be overlap between packs with unforeseen results.

jkrech commented 4 months ago

a) updating the PACK.xsd schema file to restrict the "generatorID" (https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/pdsc_generators_pg.html) to prevent special characters b) vendor::name@version should create the directory: vendor__name_version but we could still debate whether the version becomes part of the directory name. A consequence of having the version is that each time the pack containing the generator component changes, the generated files will be located in a different directory. Also I question whether it is useful to use two different generator versions concurrently.

ReinhardKeil commented 4 months ago

An alternative idea for discussion:

A generator is associated with a component. Should we extend the run syntax so that the component can be specified?

For example:

csolution run -g CubeMX(Device:DMA) mysolution.csolution.yml -c Blinky.Debug+STM32L4

See: https://github.com/Open-CMSIS-Pack/cmsis-toolbox/blob/main/docs/build-tools.md#use-generators-ie-cubemx