We have several projects using espressif32 platform and we don’t update to the latest version automatically.
We are now running into a problem with a shared piece of code between projects which are build on version 1.12.4 and 3.2.0 where the signature of a method in the platform has changed.
I don;t want to update the 1.12.4 project just yet so I need to have a way to determine the current version of espressif32 platform that is being used.
Is there a define I can use in an #ifdef to realize that?
I was wrong. If you include Arduino.h you also get the information from this file
So you can check the Arduino core version macros, which are very likely the cause of the build failure.
Are you hower sure you don’t want to enforce platform = espressif32@3.2.0 so that everyone 100% guaranteed builds on the same basis? (Arduino core, platform code etc.)
Added an advanced script, based on the link by @maxgerhardt
Import("env")
from platformio.builder.tools.piolib import PackageItem
from platformio.package.version import get_original_version
print("Adding platform and package version defines")
platform = env.PioPlatform()
used_packages = platform.dump_used_packages()
pkg_metadata = PackageItem(platform.get_dir()).metadata
platform_version = str(pkg_metadata.version if pkg_metadata else platform.version)
platform_version_split = platform_version.split(sep=".")
env.Append(CPPDEFINES=[
("PIO_PLATFORM_VERSION_MAJOR", platform_version[0]),
("PIO_PLATFORM_VERSION_MINOR", platform_version[1]),
("PIO_PLATFORM_VERSION_RELEASE", platform_version[2])
])
for package in used_packages:
pio_package_version = package["version"] # e.g. "1.70300.191015"
pio_package_name = package["name"] # e.g. "toolchain-atmelavr"
# can fail at decoding and return None if package version is not in semver format
# in these cases the pio package version is already the decoded version
# e.g. 1.70300.191015 => 7.3.0
# e.g. 5.1.0 => None
pio_decoded_version = get_original_version(pio_package_version)
name_converter = lambda name: name.upper().replace(" ", "_").replace("-", "_")
print("PIO_PACKAGE_%s_PKG_VERSION=%s" % (name_converter(pio_package_name), "\\\"" + pio_package_version + "\\\""))
env.Append(CPPDEFINES=[
("PIO_PACKAGE_%s_PKG_VERSION" % name_converter(pio_package_name) , "\\\"" + pio_package_version + "\\\"")
])
if pio_decoded_version is not None:
print("PIO_PACKAGE_%s_DECODED_VERSION=%s" % (name_converter(pio_package_name), pio_decoded_version))
env.Append(CPPDEFINES=[
("PIO_PACKAGE_%s_DECODED_VERSION" % name_converter(pio_package_name) , "\\\"" + pio_decoded_version + "\\\"")
])