platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
82 stars 108 forks source link

packages from platform_packages in platform.ini are not showing up properly #115

Closed prices closed 4 years ago

prices commented 4 years ago

platform_packages just needs to be loaded into a class variable called _custom_packages. This code was basically copied verbatim from configure_default_packages in the base class.

valeros commented 4 years ago

Hi @prices ! Could you explain in more detail what exactly this PR fixes?

prices commented 4 years ago

Yeah, sorry I realize I didn't explain myself well.

I put the following in my platformio.ini file for my custom ArduinoCore-samd:

platform_packages = framework-arduino-samd-prices @ https://github.com/prices/ArduinoCore-samd.git

What I get when I try to compile it is:

Error: Traceback (most recent call last):
  File "~/devel/project/toolchain/lib/python3.8/site-packages/platformio/__main__.py", line 109, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/platformio/commands/__init__.py", line 44, in invoke
    return super(PlatformioCLI, self).invoke(ctx)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "~devel/project/toolchain/lib/python3.8/site-packages/platformio/commands/run/command.py", line 128, in cli
    process_env(
  File "~/devel/project/toolchain/lib/python3.8/site-packages/platformio/commands/run/command.py", line 170, in process_env
    result = {"env": name, "duration": time(), "succeeded": ep.process()}
  File "~/devel/project/toolchain/lib/python3.8/site-packages/platformio/commands/run/processor.py", line 79, in process
    result = p.run(build_vars, build_targets, self.silent, self.verbose, self.jobs)
  File "~/devel/project/toolchain/lib/python3.8/site-packages/platformio/managers/platform.py", line 413, in run
    self.configure_default_packages(options, targets)
  File "~/devel/platform-atmelsam/platform.py", line 66, in configure_default_packages
    self.packages[framework_package]["optional"] = False
KeyError: 'framework-arduino-samd-prices'

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

I traced out the error and found that my custom package wasn't showing up in the package array. Tracing through the platformio base code I determined that it was because it wasn't getting loaded into the _custom_packages class variable. Once I put in the line of code the base class loaded the custom package correctly and everything compiled.

prices commented 4 years ago

I should also mention, that this is only a problem with packages that aren't defined in the platform.json file. If the package is defined in that file the expected behavior of loading a custom version of that package happens.

prices commented 4 years ago

I just posted example code that shows this bug here:

https://github.com/prices/platform-atmelsam/tree/example/examples/arduino-blink-example

Use:

platformio run -e samc21_custom

to build it. It will only build correctly if the above patch is applied.

valeros commented 4 years ago

Thanks for submitting the PR. Should be fixed in https://github.com/platformio/platform-atmelsam/commit/93336b98017e224afd13cfc9c0c2175941fbc70b

prices commented 4 years ago

Thank you! That solved my problem.