duff2013 / ulptool

Program the esp32 ULP coprocessor in Arduino
275 stars 69 forks source link

Add installer - Add Python 3 compatibility - Correct README.ino filename - Update README #25

Closed Vincent-Stragier closed 3 years ago

Vincent-Stragier commented 5 years ago

Hi,

I have updated the setup.py script so it will works for the ulptool 'new' repository and installation method. I have corrected the mismatch between the sketch name and the folder's name for the ulp_README example. I added the python 3 compatibility.

I've only tested it on Windows 10 with Python 3. setup.py can be launched anywhere, it detect automatically if the current folder's name starts with 'ulptool', if 'src' and 'lp' folders are present as 'platform.local.txt'. It support hybrid and full offline/online installation. For full offline just put the archive for binutils corresponding to your OS (or for all OSes) in the 'ulptool' folder (it pick the good one with the archive name).

Disclaimer, it will fully overwrite older installations. But... it's not really a problem if we (the users) don't play with the 'platform.local.txt' file and the examples folder.

Have a nice day,

Vincent

duff2013 commented 5 years ago

are all packages in your setup.py part of the base python? I don't want them have to install any extra packages to get it run.

Vincent-Stragier commented 5 years ago

Yes except for wget, for which I've already implemented an alternative method.

duff2013 commented 5 years ago

I need to fix this issue now, need to create a dummy file to fix non ulp projects. I'll fix this and then we can look at your upgrades.

Vincent-Stragier commented 5 years ago

Okay, I thing it's the best non invasive fix, but in the other way I think that an automatic update at the first compilation can result in a good non invasive solution. So the first time the recipe script read the 'platform.txt' file and generate new lines in the 'platform.local.txt' file. The next time the other script (recipe_c_combine_pattern.py) is able to manage seamlessly the ulp/non ulp compilation and the recipe script checks the compatibility at every compilation. I will be for the future 👍

Vincent-Stragier commented 5 years ago

It was not an easy one, but with that one, you don't even need to change your 'platform.local.txt' file and it update automatically the precious command line:

def update_compilation_method(ppath):
    ## Search variable in 'platform.txt'
    temp_plt = []
    with open(os.path.join(ppath, 'platform.txt'), "r") as pltf:
        for line in pltf:
            temp_plt.append(line)

    for line in temp_plt:
        if 'recipe.c.combine.pattern' in line:
            recipe_c_combine_pattern = line

    """
    From:
    ## Combine gc-sections, archives, and objects
    recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"

    To:
    ## Combine gc-sections, archives, and objects
    recipe.c.combine.pattern=python "{tools.ulptool.path}recipe_c_combine_pattern.py" -b "{build.path}" -c "{compiler.path}{compiler.c.elf.cmd}" -f {compiler.c.elf.flags} -xf {compiler.c.elf.extra_flags} -sf -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"
    """

    ## Build variable
    var = 'recipe.c.combine.pattern'
    script = '=python "{tools.ulptool.path}recipe_c_combine_pattern.py" -b "{build.path}" -c '
    compiler_path = recipe_c_combine_pattern[recipe_c_combine_pattern.find('=')+1:]
    compiler_path = compiler_path[:compiler_path.find('" ')+1] + ' -f '  
    compiler_flags = '{compiler.c.elf.flags}' if '{compiler.c.elf.flags}' in recipe_c_combine_pattern else ''
    compiler_extra_flags = '{compiler.c.elf.extra_flags}' if '{compiler.c.elf.extra_flags}' in recipe_c_combine_pattern else ''
    compiler_sufix_flags = recipe_c_combine_pattern[recipe_c_combine_pattern.find('{compiler.c.elf.extra_flags}')+len('{compiler.c.elf.extra_flags}')+1:] if recipe_c_combine_pattern.find('{compiler.c.elf.extra_flags}') != -1 else ''
    cmd = var + script + compiler_path + compiler_flags + ' -xf ' + compiler_extra_flags + ' -sf ' + compiler_sufix_flags

    ## Check 'platform.local.txt' file for update
    temp_plt_lc = []
    with open(os.path.join(ppath, 'platform.local.txt'), "r") as pltf:
        for line in pltf:
            temp_plt_lc.append(line)

    update_needed = []
    up_to_date_flag = False
    for line in temp_plt_lc:
        if cmd in line:
            sys.stdout.write("'platform.local.txt' is up to date.\n")
            up_to_date_flag = True
        elif var in line:
            sys.stdout.write("'platform.local.txt' need to be updated (from old version).\n")
            update_needed.append(line)

    for i in update_needed:
        temp_plt_lc.remove(i)

    ## Update if needed
    if up_to_date_flag:
        if len(update_needed):
            sys.stdout.write("'platform.local.txt' need to be cleaned.\nStarts cleaning.\n")
            with open(os.path.join(ppath, 'platform.local.txt'), "w") as pltf:
                for line in temp_plt_lc:
                    pltf.write(line)
            sys.exit('\nYou need to recompile your script (this should happend only once).\n')
        return

    sys.stdout.write("'platform.local.txt' need to be updated.\nStarts update.\n")
    temp_plt_lc.append('\n## Combine gc-sections, archives, and objects with python\n')
    temp_plt_lc.append(cmd)

    with open(os.path.join(ppath, 'platform.local.txt'), "w") as pltf:
        for line in temp_plt_lc:
            pltf.write(line)

    sys.exit('\nYou need to recompile your script (this should happend only once).\n')

The only question is, would it work under OSes.

duff2013 commented 5 years ago

I'll check this out monday not at my desk till then.

duff2013 commented 5 years ago

So I'm thinking that if you could squash all these commits and do the pull for the new_features branch I will pull it all in then we can work on it there?

duff2013 commented 5 years ago

OK I've spent a bunch of time trying merge certain things you pushed but I don't know git well enough so in the future please use separate pull requests for separate features.

Vincent-Stragier commented 5 years ago

Sorry I'm a bit sick so I'm not as reactive as I would be.

duff2013 commented 5 years ago

I too have been not that productive with a cold, hope you feel better soon.