From 33fa64c0c320feab54474fc1dab2866c4875e3a0 Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 09:39:28 -0700
Subject: [PATCH 1/6] Fix packaged python paths for Windows

Fixes #5881

The path to python.exe on Windows needs to change depending on whether
it is installed via the boards manager or GIT (similar to the compiler
paths).  Adjust accordingly.
---
 package/build_boards_manager_package.sh |  1 +
 platform.txt                            | 16 ++++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/package/build_boards_manager_package.sh b/package/build_boards_manager_package.sh
index f7c84e2bc6..9eb9d310a1 100755
--- a/package/build_boards_manager_package.sh
+++ b/package/build_boards_manager_package.sh
@@ -74,6 +74,7 @@ fi
 # handles tool paths differently when package is installed in hardware folder
 cat $srcdir/platform.txt | \
 $SED 's/runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-lx106-elf//g' | \
+$SED 's/runtime.tools.python.windows.path=.*//g' | \
 $SED 's/runtime.tools.esptool.path={runtime.platform.path}\/tools\/esptool//g' | \
 $SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' | \
 $SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' |\
diff --git a/platform.txt b/platform.txt
index c82f4ab910..1b862ed3c9 100644
--- a/platform.txt
+++ b/platform.txt
@@ -14,8 +14,8 @@ runtime.tools.signing={runtime.platform.path}/tools/signing.py
 runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py
 runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
 runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
-runtime.tools.python=python
-runtime.tools.python.windows={runtime.platform.path}/tools/python/python.exe
+runtime.tools.python.path=/usr/bin
+runtime.tools.python.windows.path={runtime.platform.path}/tools/python
 
 compiler.warning_flags=-w
 compiler.warning_flags.none=-w
@@ -83,8 +83,8 @@ compiler.elf2hex.extra_flags=
 
 ## generate file with git version number
 ## needs bash, git, and echo
-recipe.hooks.core.prebuild.1.pattern="{runtime.tools.python}" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
-recipe.hooks.core.prebuild.2.pattern="{runtime.tools.python}" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}"
+recipe.hooks.core.prebuild.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
+recipe.hooks.core.prebuild.2.pattern="{runtime.tools.python.path}/python" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}"
 
 ## Build the app.ld linker file
 recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
@@ -108,8 +108,8 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_
 recipe.objcopy.eep.pattern=
 
 ## Create hex
-recipe.objcopy.hex.1.pattern="{runtime.tools.python}" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin"
-recipe.objcopy.hex.2.pattern="{runtime.tools.python}" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
+recipe.objcopy.hex.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin"
+recipe.objcopy.hex.2.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
 
 ## Save hex
 recipe.output.tmp_file={build.project_name}.bin
@@ -125,10 +125,10 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
 
 # Need to duplicate the python path because Arduino does not replace properly in this stage
 tools.esptool.cmd=python
-tools.esptool.cmd.windows={runtime.platform.path}/tools/python/python.exe
+tools.esptool.cmd.windows={runtime.tools.python.windows.path}/python.exe
 tools.esptool.path=
 tools.esptool.network_cmd=python
-tools.esptool.network_cmd.windows={runtime.platform.path}/tools/python/python.exe
+tools.esptool.network_cmd.windows={runtime.tools.python.windows.path}/python.exe
 
 tools.esptool.upload.protocol=esp
 tools.esptool.upload.params.verbose=--trace

From b3798c0dde427ed0dc1372c9eedc64c6d5b7a705 Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 09:57:49 -0700
Subject: [PATCH 2/6] Add python-placeholder to make boardsmanager happy

An empty "python" directory will be created by the boards-manager
installer.  Required because all archs need all tools defined.
---
 .../package_esp8266com_index.template.json    | 37 ++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json
index 78d4288bec..599bf3f3ee 100644
--- a/package/package_esp8266com_index.template.json
+++ b/package/package_esp8266com_index.template.json
@@ -148,6 +148,41 @@
                      "archiveFileName": "python-3.7.2.post1-embed-win32v2.zip",
                      "checksum": "SHA-256:26665d2925ee75118bb7d8620e9ee988adc2ca3e660a9f4c06a09a06c94c0c29",
                      "size": "6431781"
+                  },
+                  {
+                     "host": "aarch64-linux-gnu",
+                     "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
+                     "archiveFileName": "python-placeholder.tar.gz",
+                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
+                     "size": "162"
+                  },
+                  {
+                     "host": "arm-linux-gnueabihf",
+                     "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
+                     "archiveFileName": "python-placeholder.tar.gz",
+                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
+                     "size": "162"
+                  },
+                  {
+                     "host": "i686-pc-linux-gnu",
+                     "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
+                     "archiveFileName": "python-placeholder.tar.gz",
+                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
+                     "size": "162"
+                  },
+                  {
+                     "host": "x86_64-apple-darwin",
+                     "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
+                     "archiveFileName": "python-placeholder.tar.gz",
+                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
+                     "size": "162"
+                  },
+                  {
+                     "host": "x86_64-pc-linux-gnu",
+                     "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
+                     "archiveFileName": "python-placeholder.tar.gz",
+                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
+                     "size": "162"
                   }
                ]
             },
@@ -264,4 +299,4 @@
          ]
       }
    ]
-}
\ No newline at end of file
+}

From a2211bf791ffadce2a4559cd473969461044d049 Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 10:07:42 -0700
Subject: [PATCH 3/6] Make the placeholder include a symlink for "python"

---
 .../package_esp8266com_index.template.json    | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json
index 599bf3f3ee..387f636c17 100644
--- a/package/package_esp8266com_index.template.json
+++ b/package/package_esp8266com_index.template.json
@@ -153,36 +153,36 @@
                      "host": "aarch64-linux-gnu",
                      "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
                      "archiveFileName": "python-placeholder.tar.gz",
-                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
-                     "size": "162"
+                     "checksum": "SHA-256:3b32fdb0905abf97e923ff968b6a0da8ce85d632b27845d7e2fc759778778785",
+                     "size": "193"
                   },
                   {
                      "host": "arm-linux-gnueabihf",
                      "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
                      "archiveFileName": "python-placeholder.tar.gz",
-                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
-                     "size": "162"
+                     "checksum": "SHA-256:3b32fdb0905abf97e923ff968b6a0da8ce85d632b27845d7e2fc759778778785",
+                     "size": "193"
                   },
                   {
                      "host": "i686-pc-linux-gnu",
                      "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
                      "archiveFileName": "python-placeholder.tar.gz",
-                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
-                     "size": "162"
+                     "checksum": "SHA-256:3b32fdb0905abf97e923ff968b6a0da8ce85d632b27845d7e2fc759778778785",
+                     "size": "193"
                   },
                   {
                      "host": "x86_64-apple-darwin",
                      "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
                      "archiveFileName": "python-placeholder.tar.gz",
-                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
-                     "size": "162"
+                     "checksum": "SHA-256:3b32fdb0905abf97e923ff968b6a0da8ce85d632b27845d7e2fc759778778785",
+                     "size": "193"
                   },
                   {
                      "host": "x86_64-pc-linux-gnu",
                      "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-3/python-placeholder.tar.gz",
                      "archiveFileName": "python-placeholder.tar.gz",
-                     "checksum": "SHA-256:520b3490299988029bb46c246a95364405b3b8b59f023399711c98e02ab2fc50",
-                     "size": "162"
+                     "checksum": "SHA-256:3b32fdb0905abf97e923ff968b6a0da8ce85d632b27845d7e2fc759778778785",
+                     "size": "193"
                   }
                ]
             },

From d851ba60c280da15c08ca40599de7cfc92193826 Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 19:49:15 -0700
Subject: [PATCH 4/6] Fix esptool windows python path

Fixes a typo in the python path for Windows for upload.
---
 platform.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/platform.txt b/platform.txt
index 1b862ed3c9..7d56992a57 100644
--- a/platform.txt
+++ b/platform.txt
@@ -125,10 +125,10 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
 
 # Need to duplicate the python path because Arduino does not replace properly in this stage
 tools.esptool.cmd=python
-tools.esptool.cmd.windows={runtime.tools.python.windows.path}/python.exe
+tools.esptool.cmd.windows={runtime.tools.python.path}/python.exe
 tools.esptool.path=
 tools.esptool.network_cmd=python
-tools.esptool.network_cmd.windows={runtime.tools.python.windows.path}/python.exe
+tools.esptool.network_cmd.windows={runtime.tools.python.path}/python.exe
 
 tools.esptool.upload.protocol=esp
 tools.esptool.upload.params.verbose=--trace

From 650c8c7f1a408d7648a8984cd3f5b59b932fe3c3 Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 19:49:15 -0700
Subject: [PATCH 5/6] Fix esptool windows python path

Fixes a typo in the python path for Windows for upload.
---
 package/build_boards_manager_package.sh |  6 +++++-
 platform.txt                            | 19 ++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/package/build_boards_manager_package.sh b/package/build_boards_manager_package.sh
index 9eb9d310a1..80592b3fd8 100755
--- a/package/build_boards_manager_package.sh
+++ b/package/build_boards_manager_package.sh
@@ -74,9 +74,13 @@ fi
 # handles tool paths differently when package is installed in hardware folder
 cat $srcdir/platform.txt | \
 $SED 's/runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-lx106-elf//g' | \
-$SED 's/runtime.tools.python.windows.path=.*//g' | \
+$SED 's/runtime.tools.python.path=.*//g' | \
 $SED 's/runtime.tools.esptool.path={runtime.platform.path}\/tools\/esptool//g' | \
 $SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' | \
+$SED 's/^tools.esptool.cmd=.*//g' | \
+$SED 's/^tools.esptool.network_cmd=.*//g' | \
+$SED 's/^#tools.esptool.cmd=/tools.esptool.cmd=/g' | \
+$SED 's/^#tools.esptool.network_cmd=/tools.esptool.network_cmd=/g' | \
 $SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' |\
 $SED 's/recipe.hooks.core.prebuild.2.pattern.*//g' |\
 $SED "s/version=.*/version=$ver/g" |\
diff --git a/platform.txt b/platform.txt
index 1b862ed3c9..d45565367b 100644
--- a/platform.txt
+++ b/platform.txt
@@ -8,14 +8,15 @@
 name=ESP8266 Boards (2.6.0-dev)
 version=2.6.0-dev
 
+# These will be removed by the packager script when doing a JSON release
 runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf
+runtime.tools.python.path={runtime.platform.path}/tools/python
+
 runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
 runtime.tools.signing={runtime.platform.path}/tools/signing.py
 runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py
 runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
 runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
-runtime.tools.python.path=/usr/bin
-runtime.tools.python.windows.path={runtime.platform.path}/tools/python
 
 compiler.warning_flags=-w
 compiler.warning_flags.none=-w
@@ -66,9 +67,6 @@ compiler.elf2hex.flags=
 
 compiler.size.cmd=xtensa-lx106-elf-size
 
-compiler.esptool.cmd=esptool
-compiler.esptool.cmd.windows=esptool.exe
-
 # This can be overriden in boards.txt
 build.extra_flags=-DESP8266
 
@@ -124,11 +122,14 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
 # ------------------------------
 
 # Need to duplicate the python path because Arduino does not replace properly in this stage
-tools.esptool.cmd=python
-tools.esptool.cmd.windows={runtime.tools.python.windows.path}/python.exe
 tools.esptool.path=
-tools.esptool.network_cmd=python
-tools.esptool.network_cmd.windows={runtime.tools.python.windows.path}/python.exe
+# Because the variable expansion doesn't allow one tool to find another, the following lines
+# will point to "{runtime.platform.path}/python/python" in GIT and "{runtime.tools.python.path}/python"
+# for JSON board manager releases.
+#tools.esptool.cmd={runtime.tools.python.path}/python
+#tools.esptool.network_cmd={runtime.tools.python.path}/python
+tools.esptool.cmd={runtime.platform.path}/python/python
+tools.esptool.network_cmd={runtime.platform.path}/python/python
 
 tools.esptool.upload.protocol=esp
 tools.esptool.upload.params.verbose=--trace

From 327363348376af786a0b7ea2ced25bfd35bd11bb Mon Sep 17 00:00:00 2001
From: "Earle F. Philhower, III" <earlephilhower@yahoo.com>
Date: Wed, 20 Mar 2019 20:54:37 -0700
Subject: [PATCH 6/6] Fix tools path when in GIT mode for upload

---
 platform.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/platform.txt b/platform.txt
index 1ee543cc32..8cdfb10131 100644
--- a/platform.txt
+++ b/platform.txt
@@ -123,12 +123,12 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
 
 tools.esptool.path=
 # Because the variable expansion doesn't allow one tool to find another, the following lines
-# will point to "{runtime.platform.path}/python/python" in GIT and "{runtime.tools.python.path}/python"
-# for JSON board manager releases.
+# will point to "{runtime.platform.path}/tools/python/python" in GIT and
+# "{runtime.tools.python.path}/python" for JSON board manager releases.
 #tools.esptool.cmd={runtime.tools.python.path}/python
 #tools.esptool.network_cmd={runtime.tools.python.path}/python
-tools.esptool.cmd={runtime.platform.path}/python/python
-tools.esptool.network_cmd={runtime.platform.path}/python/python
+tools.esptool.cmd={runtime.platform.path}/tools/python/python
+tools.esptool.network_cmd={runtime.platform.path}/tools/python/python
 
 tools.esptool.upload.protocol=esp
 tools.esptool.upload.params.verbose=--trace