Solved: Exclude directory from imported (external) library

Hi,
how can i exclude a directory from a library? In the new-LiquidCrystal-Library is a third-party-folder that doesnt compile, but does if i delete the “TinyWireM”-Folder. This is my not working example:

[env:megaatmega2560]
platform = atmelavr
board = megaADK
framework = arduino
lib_deps =
    LiquidCrystal_I2C=https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/NewLiquidCrystal_1.5.1.zip
src_filter = 
    +<*>
    -<.pio/libdeps/megaatmega2560/LiquidCrystal_I2C/thirdparty libraries/TinyWireM/*.*>

The Error-Messages are for example:

.pio/libdeps/megaatmega2560/LiquidCrystal_I2C/thirdparty libraries/TinyWireM/USI_TWI_Master.cpp: In function 'void USI_TWI_Master_Initialise()':
.pio/libdeps/megaatmega2560/LiquidCrystal_I2C/thirdparty libraries/TinyWireM/USI_TWI_Master.cpp:48:3: error: 'PORT_USI' was not declared in this scope

src_filter is relative to the src directory… so perhaps a leading ../ at the front the path… ie. -<../.pio/meg

thanks for your reply! I have already tried that, but that doesnt work :frowning:
i have also tried the following example (and variations):

[env:megaatmega2560]
platform = atmelavr
board = megaADK
framework = arduino
lib_deps =
   LiquidCrystal_I2C=https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/NewLiquidCrystal_1.5.1.zip
lib_ignore = LiquidCrystal_I2C
src_filter = 
   +<*>
   +<..\.pio\libdeps\megaatmega2560\LiquidCrystal_I2C\*.*>

but the Library isn’t ignored and the +<…> doesn’t matter here

EDIT: I think i got it! The Library is called LiquidCrystal in the Dependency Graph, now the lib is ignored… now to the include thing… hold on

That has worked now: EDIT: Sort of, now i have ValueError: No escaped character errors from python

[env:megaatmega2560]
platform = atmelavr
board = megaADK
framework = arduino
lib_deps =
  LiquidCrystal_I2C=https://bitbucket.org/fmalpartida/new- liquidcrystal/downloads/NewLiquidCrystal_1.5.0.zip
lib_ignore = LiquidCrystal
src_filter =
  +<*>
build_flags = 
  -Idir .pio\libdeps\megaatmega2560\LiquidCrystal_I2C\

/fmalpartida/new- liquidcrystal/

Is that space after the hypen really there? Did you have any luck with it or are you stick stuck?

that space is only a copy and paste-error. I’m still stuck at this “problem”. I dont want do delete the folder manually, so sharing a project doesnt require any copy-paste-delete-things.
My last “ValueError: No escaped character” errors was just path things, had to escape path-slashes, but i dont find any working solution yet

1 Like

Got the 'lil bugger… I think :slight_smile:

Part of the src_filter ‘madness’ is after ignoring the library, you re-add it via the src_flag in it’s entirety and then exclude the thirdparty folder, as well as adding it to the include path… And use forward, not back slashes to prevent escaping issues… let me know how it goes for you :wink:

[env:megaatmega2560]
platform = atmelavr
board = megaADK
framework = arduino
lib_deps =
    LiquidCrystal_I2C=https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/NewLiquidCrystal_1.5.1.zip
lib_ignore = 
    LiquidCrystal
src_filter =
    +<*> +<../.pio/libdeps/megaatmega2560/LiquidCrystal_I2C> -<../.pio/libdeps/megaatmega2560/LiquidCrystal_I2C/thirdparty libraries>
build_flags = 
    -I.pio/libdeps/megaatmega2560/LiquidCrystal_I2C

Plan B was going to be an extra_script that deletes the folder if present… that’ll fix it (automatically) :laughing:

2 Likes

oh yesss that works!! Okay i understand whats going on here! :slight_smile:
Great! I have tried so many diffrenet things…

1 Like

Sorry, but this mess solution. What if location ../.pio/libdeps path will change in future by some reason? Think more elegant solution via scripting:

  • platformio.ini

    extra_scripts =
          pre:filter_src.py
    
  • filter_src.py

    Import("env")
    
    
    def skip_from_build(node):
        """
        `node.name` - a name of File System Node
        `node.get_path()` - a relative path
        `node.get_abspath()` - an absolute path
         to ignore file from a build process, just return None
        """
        if "my-external-lib-name/path/to/dir" in node.get_path():
            # Return None for exclude
            return None
    
        return node
    
    # Register callback
    env.AddBuildMiddleware(skip_from_build, "*")
    
  • Docs:
    PlatformIO → Advanced scripting

1 Like

Thank you for submitting an alternative (and IMO much cleaner) option … if only you’d been around two years ago! :smiley:

1 Like

Yes, it’s too late, but decide post just for remember and for “coming after us” :slight_smile:

1 Like