Skip to content

build_unflags removes flags specified in build_flags (can't remove and replace -D with new value) #4309

@egnor

Description

@egnor

What kind of issue is this?

  • [✔️] PlatformIO Core.
    If you’ve found a bug, please provide an information below.

Configuration

Operating system: Ubuntu 22.04 LTS (Linux 5.15.0)

PlatformIO Version (platformio --version): PlatformIO Core, version 6.0.2

Description of problem

I wanted to remove and replace a platform build flag with my own, so I put the following in platformio.ini:

build_unflags = "-DUSB_PRODUCT=\"Seeeduino XIAO\""
build_flags = "-DUSB_PRODUCT=\"My Project\""

However, while this did successfully remove the platform -DUSB_PRODUCT, it also removed my replacement, leaving me with no such flag (as visible in pio run-v), and the platform code used a default value instead. As far as I can tell this is because, first, unflags are run through a parser and considered to match if the flag-part (-DUSB_PRODUCT) but not necessarily the value-part (\"Seeeduino XIAO\") matches; second, build_unflags will apparently remove flags that were added with build_flags.

Changing either one of these two things would allow this to work. (Removing and replacing -D type flags has to be a common desire?) Note, I was able to work around this specific case with the following:

build_flags = '-UUSB_PRODUCT "-DUSB_PRODUCT=\"My Project\""'

However, not every flag one might wish to remove and replace has a -U type antiflag.

Steps to Reproduce

  1. Add -DFOO=bar to build_unflags
  2. Add -DFOO=bat to build_flags
  3. Observe the actual flags used with pio run -v

Actual Results

No -DFOO=... is included

Expected Results

-DFOO=bat is included

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions