Global platform.txt on Mac OSX

The docs mention that you can have a global platform.txt that will be used for all platforms and overrides local properties. https://docs.arduino.cc/arduino-cli/platform-specification/#global-platformtxt

Where should this file go on Mac OSX? I've tried a couple of locations but haven't gotten found the right directory yet.

I've tried /Applications/Arduino\ IDE.app/hardware/platform.txt, /Applications/Arduino\ IDE.app/Contents/hardware/platform.txt, ~/Library/Arduino15/packages/esp32/hardware/platform.txt and a few others, but so far no luck.

Your link has the answer,

platform.txt created in the hardware subfolder of the Arduino IDE installation folder

Yes, I saw that thank you. What does that translate to on a Mac? Like I said I tried /Applications/Arduino\ IDE.app as well as /Applications/Arduino\ IDE.app/Contents and neither worked.

When I search, there is no existing hardware folder under /Applications/Arduino\ IDE.app/

I would guess

$ ls -l /Applications/Arduino\ IDE.app/Contents/Resources/app
total 24
-rw-r--r--@  1 kenb4  admin   824 Sep 25 02:30 arduino-ide-electron-main.js
drwxr-xr-x@  6 kenb4  admin   192 Sep 25 02:35 lib
-rw-r--r--@  1 kenb4  admin  5543 Sep 25 02:35 package.json
drwxr-xr-x@ 25 kenb4  admin   800 Sep 25 02:35 plugins
drwxr-xr-x@  3 kenb4  admin    96 Sep 25 02:35 resources
drwxr-xr-x@  4 kenb4  admin   128 Sep 25 02:35 src-gen

It's got lib and resources among others, so hardware could be a sibling. You could then try those two as parents if app itself doesn't work.

The instructions imply you need to create a folder called 'hardware' but the mention of Arduino IDE installation folder is a bit confusing. At first you might think it's the Applications folder, but I suspect it's the hidden folder called .arduinoIDE. The (period). means it is hidden by default, so do an unhide via Shift-Command-. (period key)
Here is what it looks like and the existing contents of the .arduinoIDE folder. Yes I am on a Mac too.
EDIT: This is located under your user name folder.

Is that a Linux box? The Mac does not look like that. The same stuff is there but it is inside the apparent app which you can see by doing a Show Package Contents. Given that , it is unlikely that is the location as it doesn't exist on a Mac.


Open Terminal and try that ls command

Then try

$ ls -l /Applications/Safari.app/Contents/Resources
total 8984
-rw-r--r--   1 root  wheel   110546 Nov 19 21:26 Acknowledgments.html
-rw-r--r--   1 root  wheel    75152 Nov 19 21:26 AppIcon.icns
-rw-r--r--   1 root  wheel  4185776 Nov 19 21:26 Assets.car
drwxr-xr-x  12 root  wheel      384 Nov 19 21:26 Background Images
drwxr-xr-x  31 root  wheel      992 Nov 19 21:26 Base.lproj

etc.

Show me how you plan on adding the 'hardware' folder to the Arduino.app. Even if you could, every update of the app would wipe it out.

This is what is in the manual.

Properties defined in a platform.txt created in the hardware subfolder of the Arduino IDE installation folder will be used for all platforms and will override local properties. This feature is currently only available when using the Arduino IDE.

The way I understand that is that the IDE installation folder is the hidden folder named .arduinoIDE

The easiest way to resolve this is to create the hardware folder, copy an existing platform.txt file and remove most of it leaving an entry that you can modify in a way that will be obvious. Now Take that same file and stick it in the .app.

All reasonable guesses, but none seem to work.

I tried:

/Users/mike/.arduinoIDE/hardware/platform.txt
/Applications/Arduino IDE.app/Contents/Resources/app/hardware/platform.txt
/Applications/Arduino IDE.app/Contents/Resources/app/resources/hardware/platform.txt
/Applications/Arduino IDE.app/Contents/Resources/app/lib/hardware/platform.txt

And none of them were picked up by the build.

In each file I put a variation of:

recipe.hooks.sketch.prebuild.234.pattern=echo HELLO A

but did not see that string in my verbose compilation logging.

Any other guesses?

Where do you see that on a Mac, I only see Applications/ArduinoIDE.app
There is no Arduino folder in Applications
And what is the meaning of the \

On my mac, the app is called "Arduino IDE" with a space, and on the filesystem it's called "/Applications/Arduino IDE.app". Some shells use a backslash to escape the next character, so sometimes you'll see /Applications/Arduino\ IDE.app instead of "/Applications/Arduino IDE.app", but it means the same thing.

Ah yes there is a space, but it changes nothing. You can't add a folder to an app as far as I know.
This isn't something I am likely to use so don't care one way or the other, but the OP should do a simple experiment using the folder I recommend (user).arduinoIDE and add the hardware folder then a platform.txt file in there with some contents he will know affected his verify in a known way. I only have a very rough idea how that works as I have never used it but a friend of mine had to make one at the platform level to get his library to work.
Good luck.

Hi @emmby. Unfortunately the global platform.txt feature has not been implemented in Arduino IDE 2.x. It is only supported when using Arduino IDE 1.x. I can see from your posts that you are using 2.x.

Please provide a detailed description of what you are trying to accomplish via the global platform.txt. The forum helpers may be able to suggest alternative ways to accomplish your goal.

That explains it!

I'm using recipe.hooks.sketch.prebuild.1.pattern hooks to preprocess some files before building. This lets me take advantage of more advanced tools like StateSmith.

The various platform.txt files are not perfect for this because they are global to my installation rather than specific to an individual project, but I was able to make them pseudo project-specific by having them look for a script in each project, and do nothing if it's not there.

The main remaining downside of using platform.txt is that it gets replaced whenever I upgrade the platform. I thought using the global platform.txt would make this less likely to occur.

But really, what I really want is the ability to specify build hooks per-project.

1 Like

Nice solution!

An alternative could be to add a custom board option that can be used to configure the build hooks via a submenu under Arduino IDE's Tools menu:

https://arduino.github.io/arduino-cli/latest/platform-specification/#custom-board-options

Arduino IDE 2.x remembers the custom board option selections you had the last time a given sketch was open, and automatically selects that board option when you open the sketch again. So this would achieve a per-project configuration.

Definitely. You can mitigate the problem by putting your build hook definitions in a dedicated file named platform.local.txt, placed in the same folder as the platform's boards.txt file:

https://arduino.github.io/arduino-cli/dev/platform-specification/#platformlocaltxt

And if you also add custom board options as I suggested above, then you can put them in boards.local.txt instead of in boards.txt:

https://arduino.github.io/arduino-cli/dev/platform-specification/#boardslocaltxt

These *.local.txt files will be lost each time you update to a new version of a platform. However, you can easily reapply your modifications afterwards by saving a copy of the files to a safe location outside the platform installation folder, then simply copying the file(s) back into the platform folder after the update.

You are probably already aware, but make sure to restart Arduino IDE (or run the "Arduino: Restart Daemon" command from the "Command Palette") after you make any changes to the platform configuration files (including adding or editing *.local.txt files), as Arduino IDE won't recognize any changes you make while it is running.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.