An example project that shows how to check if a certain macro is active in a file.

Overview

PlatformIO Check Compiler Flags Example

Description

Demonstrates the usage of an extra script and a special compilter invocation to get the active macros in a file.

E.g., if you have a file project_config.h

#ifndef _PROJECT_CONFIG_H_
#define _PROJECT_CONFIG_H_

// select driver here
#define DRIVER_ILI9341 1
//#define DRIVER_ST7789 1

#endif /* _PROJECT_CONFIG_H_ */

And you want to check in an extra script which macro was active or not, this repo shows a way to do that.

Inner workings

The script uses primarily env.Execute() to execute the C++ compiler (stored in env.["CXX"]) with the regular build flags given by the environment and saves the output to a file.

xtensa-esp32-elf-g++ -DPLATFORMIO=50202 [..more macros..] -w -dM -E -x c++ "C:\Users\Max\temp\check_flags\src\project_config.h" > flags.txt

The file then contains all compiler-builtin macros and explicitly enabled macros.

#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __FLT_MIN__ 1.1754943508222875e-38F
#define __GCC_IEC_559_COMPLEX 0
#define PLATFORMIO 50202
[..]
#define DRIVER_ILI9341 1
#define __DEC128_MIN__ 1E-6143DL
[...]

The file is then read out line-by-line and put into a Python dictionary, the key being the macro name and the value being the macro name

The resulting dictionary can then be checked for the existance of a certain key, in the standard if "KEY_NAME" in macros: way.

Limitations

The built-up command does not include any -I flags to the e.g. Arduino core, so the target header file musn't #include <Arduino.h>. There is commented-out code in the script to fix that in a brute-force way, that is, adds all items from env["CPPPATH"] as -I flags. However, this probably misses out on library includes if additional libararies are used.

It's best to keep the configuration header file as simple as possible, only defining the configuration macros in the most minimal way.

Expected output

With the unmodified source code, one should get

check_for_flags(["buildprog"], [".pio\build\esp32dev\firmware.bin"])
AFTER build!!
xtensa-esp32-elf-g++ -DPLATFORMIO=50202 -DARDUINO_ESP32_DEV -DESP32 -DESP_PLATFORM -DF_CPU=\""240000000L\"" -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\""mbedtls/esp_config.h\"" -DARDUINO=10805 -DARDUINO_ARCH_ESP32 -DARDUINO_VARIANT=\""esp32\"" -DARDUINO_BOARD=\""Espressif ESP32 Dev Module\"" -w -dM -E -x c++ "C:\Users\Max\temp\check_flags\src\project_config.h" > flags.txt
Parsed a total of 239 defines (explicit and implicitly set).
DRIVER_ILI9341 was defined!! With value: 1
echo Super special command here....
Super special command here....

At the end, showcasing that it was successfully detected that the DRIVER_ILI9341 macro was defined (and also to which value it was defined).

Usage in a different project

Copy the check_flags.py into the project and add it to the extra_scripts expression of your platformio.ini.

Adapt the logic in check_flags.py regarding the read-out file and the reaction to it accordingly.

extra_scripts =
   check_flags.py
Owner
Maximilian Gerhardt
Firmware developer and security specialist.
Maximilian Gerhardt
A set of tools for ripping music from Konami mobile games

Konami Mobile Ripping Toolset A set of tools for ripping music from Konami mobile games Contents nigger.py for niggering konami's website, ripping all

5 Oct 20, 2022
Scripts for BGC analysis in large MAGs and results of their application to soil metagenomes within Chernevaya Taiga RSF-funded project

Scripts for BGC analysis in large MAGs and results of their application to soil metagenomes within Chernevaya Taiga RSF-funded project

1 Dec 06, 2021
Chemical Analysis Calculator, with full solution display.

Chemicology Chemical Analysis Calculator, to solve problems efficiently by displaying whole solution. Go to releases for downloading .exe, .dmg, Linux

Muhammad Moazzam 2 Aug 06, 2022
Listen Surah, prepare for next and Endless life...

Al-Quran In this repository, I have linked up all Surah with Arabic-Bangla Audio From Youtube. So, you just need to choose and listen. and the ( surah

SpiderX 1 Sep 30, 2022
The earliest beta version of pytgcalls on Linux x86_64 and ARM64! Use in production at your own risk!

Public beta test. Use in production at your own risk! tgcalls - a python binding for tgcalls (c++ lib by Telegram); pytgcalls - library connecting pyt

Il'ya 21 Jan 13, 2022
Object-oriented programming (OOP) is a method of structuring a program by bundling related properties and behaviors into individual objects. In this tutorial, you’ll learn the basics of object-oriented programming in Python.

06_Python_Object_Class Introduction 👋 Objected oriented programming as a discipline has gained a universal following among developers. Python, an in-

Milaan Parmar / Милан пармар / _米兰 帕尔马 239 Dec 20, 2022
Python data loader for Solar Orbiter's (SolO) Energetic Particle Detector (EPD).

Data loader (and downloader) for Solar Orbiter/EPD energetic charged particle sensors EPT, HET, and STEP. Supports level 2 and low latency data provided by ESA's Solar Orbiter Archive.

Jan Gieseler 9 Dec 16, 2022
Anti VirusTotal written in Python.

How it works Most of the anti-viruses on VirusToal uses sandboxes or vms to scan and detect malicious activity. The code checks to see if the devices

cliphd 3 Dec 26, 2021
Semester Project on Signal Processing @CS UCU 2021

Blur Detection with Haar Wavelet Transform Requirements Python3 opencv-python PyWavelets Install these using the following command: $ pip install -r r

ButynetsD 2 Oct 15, 2022
Add all JuliaLang unicode abbreviations to AutoKey.

Autokey Unicode characters Usage This script adds all the unicode character abbreviations supported by Julia to autokey. However, instead of [TAB], th

Randolf Scholz 49 Dec 02, 2022
Stopmagic gives you the power of creating amazing Stop Motion animations faster and easier than ever before.

Stopmagic gives you the power of creating amazing Stop Motion animations faster and easier than ever before. This project is maintained by Aldrin Mathew.

Aldrin's Art Factory 67 Dec 31, 2022
Randomly distribute members by groups making sure that every sector is represented

Generate Groups Randomly distribute members by groups making sure that every sector is represented The Scenario Imagine that you have a large group of

Jorge Gomes 1 Oct 22, 2021
The dynamic code loading framework used in LocalStack

localstack-plugin-loader localstack-plugin-loader is the dynamic code loading framework used in LocalStack. Install pip install localstack-plugin-load

LocalStack 5 Oct 09, 2022
dbt (data build tool) adapter for Oracle Autonomous Database

dbt-oracle version 1.0.0 dbt (data build tool) adapter for the Oracle database. dbt "adapters" are responsible for adapting dbt's functionality to a g

Oracle 22 Nov 15, 2022
Versión preliminar análisis general de Covid-19 en Colombia

Covid_Colombia_v09 Versión: Python 3.8.8 1/ La base de datos del Ministerio de Salud (Minsalud Colombia) está en https://www.datos.gov.co/Salud-y-Prot

Julián Gómez 1 Jan 30, 2022
Camera track the tip of a pen to use as a drawing tablet

cablet Camera track the tip of a pen to use as a drawing tablet Setup You will need: Writing utensil with a colored tip (preferably blue or green) Bac

14 Feb 20, 2022
fast_bss_eval is a fast implementation of the bss_eval metrics for the evaluation of blind source separation.

fast_bss_eval Do you have a zillion BSS audio files to process and it is taking days ? Is your simulation never ending ? Fear no more! fast_bss_eval i

Robin Scheibler 99 Dec 13, 2022
NeoInterface - Neo4j made easy for Python programmers!

Neointerface - Neo4j made easy for Python programmers! A Python interface to use the Neo4j graph database, and simplify its use. class NeoInterface: C

15 Dec 15, 2022
Placeholders is a single-unit storage solution for your Frontend.

Placeholder Placeholders is a single-unit file storage solution for your Frontend. Why Placeholder? Generally, when a website/service requests for fil

Tanmoy Sen Gupta 1 Nov 09, 2021
Bookmarkarchiver - Python script that archives all of your bookmarks on the Internet Archive

bookmarkarchiver Python script that archives all of your bookmarks on the Internet Archive. Supports all major browsers. bookmarkarchiver uses the off

Anthony Chen 3 Oct 09, 2022