Go Down

Topic: Saving pattern results in custom platforms.txt (Read 260 times) previous topic - next topic

eng101

I have a custom platform.txt for some hardware I have developed. One of the post build steps requires passing the program size as a variable on the command line to a program that patches the output file.

I can call the patcher using recipe.hooks.objcopy.postobjcopy.#.pattern and I can call the program that will give me the program size, but I can't figure out a way to capture the output of that as a variable.

It looks like Arduino has some regular expressions for parsing and outputting the size when using the recipe.size.pattern but I can't figure out a way to capture that result and send it to the next pattern.

pert

I would use a wrapper script for this purpose.

The wrapper script would run the program that gets the proggram size and then pass that information to the patcher program.

Remember to provide both a shell script for Linux and a .bat file for Windows (yeah, what a pain!).

There's a demonstration of using scripts bundled with a boards platform in a Windows/Linux/macOS-compatible manner here:
https://github.com/SpenceKonde/ATTinyCore/blob/1.4.1/platform.txt#L90-L97

eng101

Yea I was just hoping if there was a way to incorporate that into the existing Arduino script it would eliminate yet another thing to be maintained but if it's not achievable then that's the way I'll go.

eng101

#3
Sep 18, 2020, 07:20 pm Last Edit: Sep 18, 2020, 07:21 pm by eng101
Ugh, now I can't call my script because of this problem: https://github.com/arduino/arduino-builder/issues/316

pert

Ouch, that is annoying, and it's an upstream bug in Go, so I guess it's not something Arduino can fix.

I notice this:
https://github.com/golang/go/issues/17149#issuecomment-248822918
Quote
Go encodes child process parameters in a way that is understood by most programs. Go uses rules similar to what CommandLineToArgvW implements.

Unfortunately, your child process is cmd.exe (cmd.exe is called to execute the batch file you've requested). And cmd.exe parses its input parameters differently.
So I think if you were able to create an executable as a replacement for the batch file, you wouldn't have this problem. I don't have any experience with it, but I know there are tools to make a .exe from a Python script, so maybe that would provide a relatively simple alternative to a batch file.

eng101

#5
Sep 19, 2020, 12:08 am Last Edit: Sep 19, 2020, 12:10 am by eng101
Technically I guess I could incorporate it into the output file patcher (since I'm actually writing that executable) but it's also used in non-Arduino situations so that might get messy.

I was able to get around it in the batch file for now by using cd %~dp0 to move to the batch file's home directory, that's being run from the Arduino Tools directory where all of my file processing applications are stored which means I don't need to pass an actual path for those applications to the batch file.

So far so good but we'll see how portable it is once I try to deploy it...

pert

Nice! Thanks for taking the time to share your solution. I'll try to remember that workaround. I actually am the one who set up those scripts in ATTinyCore and I've done the same sort of "wrapper script" thing in a couple other boards platforms as well, so there's a good chance I've introduced incompatibility with paths containing spaces. I tend to instictively avoid creating such paths on my own system, but I'd probably be better off intentionally setting up problematic folder names because you know someone out there has every crazy combination of characters the OS will support.

Go Up