Trouble with Custom Firmware Naming

Let me check code, it could also be that the defines dictionary wasn’t filled properly.

1 Like

i thought this as well, was trying to debuyg and print the defines - but can’t figure out how to output the values to the console - so i am trying to write-up a minimal code to recreate the issue (in an empty python project).

A fully working and updated example is at GitHub - maxgerhardt/pio-git-test. Indeed it wasn’t tuple I should be checking for but a list. I also added proper stringifcation (quoting) to the macros.

That by itself can’t work since you don’t include the git_rev.py output as macros and also don’t define VERSION which the script needs. Check the full example above.

It outpus .pio\build\uno\pio-git-test-1.2.3-uno-b3a3c14-master.hex no problem.

No, i had all of that already setup - i jsut didn’t include it in my example - as it wasn’t pertinent. I got the customname.py working on my own. Thank you for you time, and everything that you have done. My customname.py looks like this (and works as intended):

Import("env")

from collections import Iterable

class hash_list(list): 
    def __init__(self, *args): 
        if len(args) == 1 and isinstance(args[0], Iterable): 
            args = args[0] 
        super().__init__(args) 
         
    def __hash__(self): 
        return hash(e for e in self)

my_flags = env.ParseFlags(env['BUILD_FLAGS'])
defines = dict()
for x in my_flags.get("CPPDEFINES"):
    if type(x) is tuple:
        k = x[0]
        for y in x:
            v = y
            defines[k] = v  
            
        # (k,v) = x
        defines[k] = v
    else:
        k = x[0]
        for y in x:
            v = y
            defines[k] = v  
            
        # (k,v) = x
        defines[hash(hash_list(k))] = ""
        
# defines.get("PIO_SRC_TAG") - tag name
env.Replace(
    PROGNAME="%s-%s-%s-%s-%s" %
    (defines.get("PIO_SRC_NAM"), defines.get("VERSION"), str(env["BOARD"]),
     defines.get("PIO_SRC_REV"), defines.get("PIO_SRC_BRH")))

I like your approach here to using a lambda and just checking if the type is a list. I just hashed the list and iterated through the tuple elements … xD a little extreme tbh. Your method is much cleaner.