The right way of using modified local copy of library?

If I understand correctly, according to this answer it should be possible to copy the library from e.g. .pio\libdeps\uno to lib and then modify the source code.

For example, I have this:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200
lib_deps = 
	adafruit/Adafruit GFX Library@^1.11.9
	adafruit/Adafruit ST7735 and ST7789 Library@^1.10.3

in platformio.ini and the libraries downloaded into .pio\libdeps\uno are:

Adafruit BusIO
Adafruit GFX Library
Adafruit seesaw Library
Adafruit ST7735 and ST7789 Library

I copied those folders into lib and made some modifications but I don’t see the lib folder being mentioned during build process.

Do I have to remove those libraries from platformio.ini to use the local libraries with my edits?

I thought the code in lib would have a higher priority over .pio\libdeps.

And how to handle multiple environments? I have uno and megaatmega2560 environments and there are two copies of the libraries - one in .pio\libdeps\uno and the other one in .pio\libdeps\megaatmega2560.

How can the local libraries be edited for each environment separately to have different modifications for every environment?

EDIT:
The modified local copy of the library does have a higher priority over the the code in .pio\libdeps and the modifications do work despite I didn’t remove the libraries from platformio.ini.

The only question that still remains is how to have a different local copy of certain libraries for each environment.

Can I just copy some libraries from .pio\libdeps\uno to lib\uno and some libraries from .pio\libdeps\megaatmega2560 to lib\megaatmega2560 and then make edits? Will the compiler and linker in that case use the right local libraries depending on currently active environment?

“The right way of using modified local copy of library” is not modifying a local copy of the library.

What is the use case for this?
Usually there should be no use case for this.

I am afraid that your project architecture may fundamentally wrong ?!

I am working on a firmware for driving motors with ATmega328 and ATmega2560 boards and I am using 240x320 ST7789 display for displaying some data during field testing.

The problem is that display has slightly nonstandard communication so I had to change the source code in some of the library files.

In the same time, I am using another library for reading the incoming data from the receiver over iBUS and I’d like to have two versions of that library - one version for using with ATmega328 which has only one hardware serial port and another version for using with ATmega2560 which has 4 UART ports.

But anyway - I’d like to know if it is possible to have a separate modified local libraries for each environment.

Because, there must be a reason why is the same library which is added automatically through lib_deps in platformio.ini installed twice - once for each environment.

Compiler and linker are obviously using the library corresponding to the active environment - despite both copies of the library in .pio\libdeps\uno and .pio\libdeps\megaatmega2560 are exactly the same.

Now that I copied those libraries into lib and made modifications, my code really has precedence over the code in .pio\libdeps\* and that works exactly as expected and as was described in the accepted answer that I linked. However, now both environments are using the very same local (modified) copy of the library.

My question is now if there is a way of telling: "When the active environment is uno then use lib\uno\* and when the active environment is megaatmega2560 then use lib\megaatmega2560\*.

In other words, is there a way to specify the lib path for each environment separately.