Excluding Arduino framework new.cpp from the build

Hi,
Is it possible to exclude this file from the build somehow?
C:\Users\eyaln.platformio\packages\framework-arduinoteensy\cores\teensy4\new.cpp

I’m running a teensy4.1 with freertos and would like to overload operators new & delete, but Arduino implemented these without a weak attribute, so ld complains about multiple definitions if I just provide an overload.

Did you try a src_filter?

Yes, I did.
Using the following syntax:
src_filter = -<C:/Users/eyaln.platformio/packages/framework-arduinoteensy/cores/teensy4/new.cpp>
But, it does not get filtered out.

Mhmm I’ve played around a bit with various src_filters in the platformio.ini and with Advanced scripting (a post-script with env.Append(SRC_FILTER=["-<new.cpp>"]) basically, but that didn’t help either… Still got built.

Maybe @ivankravets can shine the light here?

I came up with a hack though: Renaming the new.cpp file to new.txt just before the to-be-built files are analyzed in a pre: script to prevent if from being included, then renaming it back shortly afterwards.

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
extra_scripts = 
    pre:filter_new_pre.py
    post:filter_new_post.py

With filter_new_pre.py in the root of the project

from shutil import move
import os
Import("env")

platform = env.PioPlatform()
teensy_dir = platform.get_package_dir("framework-arduinoteensy")

src_file = os.path.join(teensy_dir, "cores", "teensy4", "new.cpp")
dst_file = os.path.join(teensy_dir, "cores", "teensy4", "new.txt")

try:
    move(src_file, dst_file)
except Exception as exc:
    print("Moving files failed")
    print(str(exc))

and filter_new_post.py

from shutil import move
import os
Import("env")

platform = env.PioPlatform()
teensy_dir = platform.get_package_dir("framework-arduinoteensy")

dst_file = os.path.join(teensy_dir, "cores", "teensy4", "new.cpp")
src_file = os.path.join(teensy_dir, "cores", "teensy4", "new.txt")

try:
    move(src_file, dst_file)
except Exception as exc:
    print("Moving files failed")
    print(str(exc))

Of course this is really ugly and not recommended, but one way that works.

1 Like

That’s great, at least it’s something.
I actually tried deleting the object file from the build directory using a post script, but that didn’t work either. Possibly because I got the something wrong in the script.

See example at Redirecting...

Thanks, this is much easier:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
extra_scripts = 
    pre:filter_new.py
Import("env")

def skip_file(node):
    # to ignore file from a build process, just return None
    return None

env.AddBuildMiddleware(skip_file, "*/teensy4/new.cpp")
1 Like

Perfect!
Thanks for the help.