Error when building nrf52_dk with mbed-os

When PIO_FRAMEWORK_MBED_RTOS_PRESENT defined in platformio.ini, I can’t build project. Without this flag build run successfull.
I need rtos features to use queues and osDelay.

Environment:
OS: Windows 10 1903 x64
PIO version: 4.0.3 and 4.1.0rc1
Python version: 3.8
PIO Core path: c:\pio

Steps to reproduce:
$mkdir nrf52pio
$cd nrf52pio
$pio init --board nrf52_dk

change platformio.ini to:

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = mbed
build_flags = -DPIO_FRAMEWORK_MBED_RTOS_PRESENT

add src/main.cpp :

#include <mbed.h>

int main() {

  while(1) {
  }
}

$pio init
$pio run -v

and the build log is full of errors like arm-none-eabi-gcc: error: CreateProcess: No such file or directory

full build log:

and two longcmd* files:

The path of your project is directly C:\? The src/ folder seems to be directly there

Mkdir("C:\src\nrf52pio\.pio\build\nrf52_dk")

Can you try and move this to a subfolder, e.g. C:\testproject?

No, project path was c:\src\nrf52pio\, and sources was in c:\src\nrf52pio\src.

I’ve tried again after reboot, with c:\testproject, and got the same result.
Build log:

longcmd:

If I use ststm32 board disco_f303vc, pio run works just fine (but it uses framework-mbed@5.51401.191023 instead of framework-mbed@5.51304.190826 in nordicnrf52)

UPD:
Just tried this case with platformio installed in python2.7 virtualenv - error reproduces.

UPD2:
Python 3.6 x64, pio 4.0.3 on another Windows 10 x64 box and the same errors.

Could you please try the following platformio.ini:

[platformio]
packages_dir = C:\\pio

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = mbed
build_flags = -DPIO_FRAMEWORK_MBED_RTOS_PRESENT

With packages_dir = c:\\pio I’ve got PermissionError: [Errno 13] Permission denied: 'C:\\pio.lock'

With packages_dir = c:\\pio\\packages error was old good arm-none-eabi-gcc: error: CreateProcess: No such file or directory.

Also during this run I noticed that tool-scons was updated to ~3.30101.0 from 2.20501.190826

After hours of debugging build scripts, compiling gcc with -g, recompiling it with -O0 -g3, debugging gcc with gdb and analyzing build logs I’ve found the problem.

When platformio (actually scons) run arm-none-eabi-gcc.exe, it pass include parameters via @longcmd-xxx.txt file (to get around 32kb char command line limit in Windows), but gcc for some reason invokes cc1.exe without command-line file - just with process args. For nrf52 with PIO_FRAMEWORK_MBED_RTOS_PRESENT defined there are lot of defines and includes (more than for stm32, about 35kb vs 25kb), so executing cc1.exe leads to arm-none-eabi-gcc: error: CreateProcess: No such file or directory .

The actual command line for cc1 (or cc1plus in case of g++) can be obtained when adding -v to build_flags and running pio run -v.

As a workaround for now, I use .mbedignore files to minimize gcc commands (and build time). One in packages\framework-mbed\components\802.15.4_RF\ with * in it, and another in packages\framework-mbed\features\ with the following content:

cellular/*
cryptocell/*
lorawan/*
nanostack/*
netsocket/*
lwipstack/*

Is there a way to set ignored mbed libraries per-project?