Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Craft-parts cannot parse advanced grammar in stage and prime fields #874

Open
mr-cal opened this issue Oct 9, 2024 · 2 comments
Open

Craft-parts cannot parse advanced grammar in stage and prime fields #874

mr-cal opened this issue Oct 9, 2024 · 2 comments
Labels
Bug Something isn't working Triaged

Comments

@mr-cal
Copy link
Contributor

mr-cal commented Oct 9, 2024

Bug Description

Craft-parts assumes prime and stage entries are strings. This is not true if advanced grammar is used.

Craft-parts needs to be able to unmarshal parts with advanced grammar. The problematic code is here).

To Reproduce

See a snapcraft reproducer in https://bugs.launchpad.net/snapcraft/+bug/2083964

part yaml

parts:
  my-part:
    plugin: nil
    prime:
    - on amd64:
      - usr/lib/*/libvpl.so.*

Relevant log output

2024-10-09 09:12:00.397 Starting snapcraft, version 8.4.2
2024-10-09 09:12:00.397 Log verbosity level set to BRIEF
2024-10-09 09:12:00.397 Preparing application...
2024-10-09 09:12:00.397 Configuring application...
2024-10-09 09:12:00.398 Setting up ConfigService
2024-10-09 09:12:00.507 Build plan: platform=None, build_for=None
2024-10-09 09:12:00.507 Running snapcraft expand-extensions on host
2024-10-09 09:12:00.521 snapcraft internal error: AttributeError("'dict' object has no attribute 'startswith'")
2024-10-09 09:12:00.522 Traceback (most recent call last):
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/application.py", line 568, in run
2024-10-09 09:12:00.522     return_code = self._run_inner()
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/snapcraft/application.py", line 215, in _run_inner
2024-10-09 09:12:00.522     return_code = super()._run_inner()
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/application.py", line 549, in _run_inner
2024-10-09 09:12:00.522     return_code = dispatcher.run() or os.EX_OK
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_cli/dispatcher.py", line 487, in run
2024-10-09 09:12:00.522     return self._loaded_command.run(self._parsed_command_args)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/snapcraft/commands/extensions.py", line 137, in run
2024-10-09 09:12:00.522     project_data = models.Project.unmarshal(yaml_data_for_arch)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/models/base.py", line 61, in unmarshal
2024-10-09 09:12:00.522     return cls.model_validate(data)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/pydantic/main.py", line 568, in model_validate
2024-10-09 09:12:00.522     return cls.__pydantic_validator__.validate_python(
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/models/project.py", line 250, in _validate_part
2024-10-09 09:12:00.522     craft_parts.validate_part(part)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/parts.py", line 648, in validate_part
2024-10-09 09:12:00.522     _get_part_spec(data)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/parts.py", line 679, in _get_part_spec
2024-10-09 09:12:00.522     return PartSpec(**part_spec)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/pydantic/main.py", line 193, in __init__
2024-10-09 09:12:00.522     self.__pydantic_validator__.validate_python(data, self_instance=self)
2024-10-09 09:12:00.522   File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/constraints.py", line 44, in _validate_relative_path_str
2024-10-09 09:12:00.522     if path.startswith("/"):
2024-10-09 09:12:00.522 AttributeError: 'dict' object has no attribute 'startswith'
2024-10-09 09:12:00.522 Full execution log: '/home/developer/.local/state/snapcraft/log/snapcraft-20241009-091200.396666.log'
@mr-cal mr-cal added Bug Something isn't working Triaged labels Oct 9, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3559.

This message was autogenerated

@lengau
Copy link
Contributor

lengau commented Oct 9, 2024

While the error message here is bad, craft-parts doesn't need to handle grammar. I believe the grammar isn't being properly processed in the expand-extensions command.

The following part definition:

parts:
  my-part:
    plugin: nil
    stage-packages:
      - on amd64:
        - sl
      - nano
    prime:
      - on amd64:
        - usr/lib/*/libvpl.so.*
      - usr/bin

results in this yaml_data_for_arch object in ExpandExtensionsCommand.run():

{
  "parts": {
    "my-part": {
      "plugin": "nil",
      "stage-packages": [
        "sl",
        "nano"
      ],
      "prime": [
        {
          "on amd64": [
            "usr/lib/*/libvpl.so.*"
          ]
        },
        "usr/bin"
      ]
    }
  }
}

We should probably keep this bug around though, since this YAML:

parts:
  my-part:
    plugin: nil
    # prime:
    # - on amd64:
    #   - usr/lib/*/libvpl.so.*
    stage-packages:
      - on amd64:
        - sl

outputs a good error message:

python -m craft_parts --dry-run
Error: invalid parts specification: Part 'my-part' validation failed.
- Input should be a valid string in field 'stage-packages[0]'
Review part 'my-part' and make sure it's correct.

while uncommenting the prime keyword gets us a traceback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triaged
Projects
None yet
Development

No branches or pull requests

2 participants