From e3c0891d2b6f956ab6dbb8b27e37f8215a1d4903 Mon Sep 17 00:00:00 2001
From: Victor Oliveira <rhapsodyv@gmail.com>
Date: Sat, 8 Aug 2020 20:40:12 -0300
Subject: [PATCH] Fix compiler search in non-default PIO installs (#18960)

---
 buildroot/share/PlatformIO/scripts/common-dependencies.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py
index e09c639ad7..6c1b571bf1 100644
--- a/buildroot/share/PlatformIO/scripts/common-dependencies.py
+++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py
@@ -156,16 +156,16 @@ def search_compiler():
 	# Find the current platform compiler by searching the $PATH
 	if env['PLATFORM'] == 'win32':
 		path_separator = ';'
-		path_regex = r'platformio\\packages.*\\bin'
+		path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*\\bin'
 		gcc = "g++.exe"
 	else:
 		path_separator = ':'
-		path_regex = r'platformio/packages.*/bin'
+		path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*/bin'
 		gcc = "g++"
 
 	# Search for the compiler
 	for path in env['ENV']['PATH'].split(path_separator):
-		if not re.search(path_regex, path):
+		if not re.search(path_regex, path, re.IGNORECASE):
 			continue
 		for file in os.listdir(path):
 			if not file.endswith(gcc):