Arduino-Makefile icon indicating copy to clipboard operation
Arduino-Makefile copied to clipboard

Read Arduino installation path from preference file

Open sudar opened this issue 12 years ago • 4 comments

From this commit Arduino started to place the Arduino installation path in the preference file.

Try to read the Arduino installation path, if the user has not explicitly set it.

sudar avatar Jul 28 '13 12:07 sudar

its explained here most notable is runtime.ide.path

sej7278 avatar Jun 07 '14 17:06 sej7278

the problem with this now is that its versionned, so we have:

last.ide.1.6.1.daterun=1427555323
last.ide.1.6.1.hardwarepath=~/arduino-1.6.1/hardware
last.ide.1.6.3.daterun=1428863136
last.ide.1.6.3.hardwarepath=~/arduino-1.6.3/hardware

so we can't use it to find the arduino installation path without requiring the user to specify the version s/he wants to use, and we can't auto-detect the version from the installation path (chicken & egg).

we could look for the last version run or the highest version number, but that's a fair bit of logic for a makefile, and it only works for 1.5+, and relies on people actually using the IDE

sej7278 avatar Apr 14 '15 11:04 sej7278

to find the highest ide version used and its path, you can use the following:

$ grep hardwarepath ~/.arduino15/preferences.txt 
last.ide.1.6.1.hardwarepath=/home/user/arduino/arduino-1.6.1/hardware
last.ide.1.6.3.hardwarepath=/home/user/arduino/arduino-1.6.3/hardware
last.ide.1.6.4.hardwarepath=/home/user/arduino/arduino-1.6.4/hardware

$ grep hardwarepath ~/.arduino15/preferences.txt | tail -1 | awk -F= {'print $2'}
/home/user/arduino/arduino-1.6.4/hardware

$ grep hardwarepath ~/.arduino15/preferences.txt | tail -1 | awk -F= {'print $1'} | sed s/[^0-9]*//g
164

sej7278 avatar Jun 07 '15 18:06 sej7278

this patch adds support for finding ARDUINO_DIR and ARDUINO_VERSION from the preferences but it still seems a bit pointless - as we're assuming the path to preferences.txt and assuming its 1.5+, also is "grep -h" portable?

diff --git a/Arduino.mk b/Arduino.mk
index 936645a..331cd02 100644
--- a/Arduino.mk
+++ b/Arduino.mk
@@ -277,6 +277,13 @@ ifndef ARDUINO_VERSION
     # Works for 1.0 and 1.0.1
     VERSION_FILE := $(ARDUINO_DIR)/lib/version.txt
     AUTO_ARDUINO_VERSION := $(shell [ -e $(VERSION_FILE) ] && cat $(VERSION_FILE) | sed -e 's/^[0-9]://g' -e 's/[.]//g' -e 's/$$/0000/' | head -c3)
+
+    # only works for 1.5+ if ide has previously been run
+    ifndef AUTO_ARDUINO_VERSION
+        AUTO_ARDUINO_VERSION := $(shell grep -h hardwarepath $(HOME)/.arduino15/preferences.txt \
+            $(HOME)/Library/Arduino15/preferences.txt 2> /dev/null | tail -1 | awk -F= {'print $$1'} | sed s/[^0-9]*//g)
+    endif
+
     ifdef AUTO_ARDUINO_VERSION
         ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION)
         $(call show_config_variable,ARDUINO_VERSION,[AUTODETECTED])
diff --git a/Common.mk b/Common.mk
index 7eda5ea..a16c58a 100644
--- a/Common.mk
+++ b/Common.mk
@@ -69,7 +69,10 @@ ifndef ARDUINO_DIR
     AUTO_ARDUINO_DIR := $(firstword \
         $(call dir_if_exists,/usr/share/arduino) \
         $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) \
-        $(call dir_if_exists,/Applications/Arduino.app/Contents/Java) )
+        $(call dir_if_exists,/Applications/Arduino.app/Contents/Java) \
+        $(call dir_if_exists,$(abspath $(dir $(shell grep -h hardwarepath $(HOME)/.arduino15/preferences.txt \
+            $(HOME)/Library/Arduino15/preferences.txt 2> /dev/null | tail -1 | awk -F= {'print $$2'})/../))) )
+
     ifdef AUTO_ARDUINO_DIR
        ARDUINO_DIR = $(AUTO_ARDUINO_DIR)
        $(call show_config_variable,ARDUINO_DIR,[AUTODETECTED])

sej7278 avatar Jun 07 '15 23:06 sej7278