# Simple PIOC

### Introduction

This Python script processes a custom PlatformIO configuration file (`<span class="editor-theme-code">platformio.pioc</span>`<span style="white-space: pre-wrap;">) and generates a standard </span>`<span class="editor-theme-code">platformio.ini</span>`<span style="white-space: pre-wrap;"> file.</span>

It extends PlatformIO’s configuration capabilities by:

- <span style="white-space: pre-wrap;">Supporting </span>**dynamic include paths**<span style="white-space: pre-wrap;"> using glob patterns</span>
- <span style="white-space: pre-wrap;">Extracting </span>**C preprocessor defines**<span style="white-space: pre-wrap;"> from board-specific Makefiles</span>
- <span style="white-space: pre-wrap;">Expanding </span>**custom syntax**<span style="white-space: pre-wrap;"> into valid </span>`<span class="editor-theme-code">build_flags</span>`
- <span style="white-space: pre-wrap;">Resolving </span>**absolute paths**.

### Key Features

#### Custom build\_flags Processing

Supports two types of entries:

- **+&lt;pattern&gt;**: Include directories
- **-&lt;pattern&gt;**: Exclude directories
- Other entries are treated as standard compiler flags

#### Include Path Resolution

<span style="white-space: pre-wrap;">Glob patterns are expanded into directory paths using recursive search. </span>

#### Board-specific C Defines

Defines are extracted from:

```
components/<board>/firmware/Makefile
```

<span style="white-space: pre-wrap;">The script looks for a </span>`<span class="editor-theme-code">C_DEFS</span>`<span style="white-space: pre-wrap;"> section and includes all compiler defines.</span>

<span style="white-space: pre-wrap;">This is done, because cubeMX generates important definitions in the auto-generated makefile. These are not used if we don't copy them to the .ini file. </span>

#### Environment Detection

```
[env:my_board]
```

This determines which board folder is used.

#### Get Absolute Path

<span style="white-space: pre-wrap;">For some functions, like nanopb, you might need the absolute path. There is no way to get in the default platformio.ini file, so that would mean that you would have to hard code it. We do not want that, so we have a placeholder for an absolute path. </span>

The placeholder:

```
${{project_absolute_path}}$
```

<span style="white-space: pre-wrap;">is replaced with the absolute path of the project. </span>

## Workflow

1. <span style="white-space: pre-wrap;">Read </span>`<span class="editor-theme-code">platformio.pioc</span>`
2. Detect environment
3. <span style="white-space: pre-wrap;">Parse </span>`<span class="editor-theme-code">build_flags</span>`
4. Resolve glob patterns
5. Extract C defines
6. <span style="white-space: pre-wrap;">Write </span>`<span class="editor-theme-code">platformio.ini</span>`
7. Replace placeholders

## Example Input

```
[env:my_board]
build_flags =
    +<lib/**>
    -<lib/exclude/**>
    -DDEBUG
```

## Example Output

```
[env:my_board]
build_flags =
    -I lib/module1
    -I lib/module2
    -DDEBUG
    -DDEFINE_FROM_MAKEFILE
```