Skip to content

Commit f2d585a

Browse files
committed
🔨 Skip bad compilers
1 parent 80cfdb1 commit f2d585a

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

buildroot/share/PlatformIO/scripts/preprocessor.py

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# preprocessor.py
33
#
4-
import subprocess
4+
import subprocess, os
55

66
nocache = 1
77
verbose = 0
@@ -53,12 +53,14 @@ def run_preprocessor(env, fn=None):
5353
# Find a compiler, considering the OS
5454
#
5555
def search_compiler(env):
56+
global nocache
5657

5758
from pathlib import Path, PurePath
5859

5960
ENV_BUILD_PATH = Path(env['PROJECT_BUILD_DIR'], env['PIOENV'])
6061
GCC_PATH_CACHE = ENV_BUILD_PATH / ".gcc_path"
6162

63+
gccpath = None
6264
try:
6365
gccpath = env.GetProjectOption('custom_gcc')
6466
blab("Getting compiler from env")
@@ -71,24 +73,42 @@ def search_compiler(env):
7173
blab("Getting g++ path from cache")
7274
return GCC_PATH_CACHE.read_text()
7375

74-
# Use any item in $PATH corresponding to a platformio toolchain bin folder
7576
path_separator = ':'
7677
gcc_exe = '*g++'
77-
if env['PLATFORM'] == 'win32':
78+
79+
sysname = os.uname().sysname
80+
if sysname == 'Windows':
7881
path_separator = ';'
7982
gcc_exe += ".exe"
8083

84+
envpath = map(Path, env['ENV']['PATH'].split(path_separator))
85+
8186
# Search for the compiler in PATH
82-
for ppath in map(Path, env['ENV']['PATH'].split(path_separator)):
87+
for ppath in envpath:
88+
# Use any item in $PATH corresponding to a platformio toolchain bin folder
8389
if ppath.match(env['PROJECT_PACKAGES_DIR'] + "/**/bin"):
8490
for gpath in ppath.glob(gcc_exe):
85-
gccpath = str(gpath.resolve())
86-
# Cache the g++ path to no search always
87-
if not nocache and ENV_BUILD_PATH.exists():
88-
blab("Caching g++ for current env")
89-
GCC_PATH_CACHE.write_text(gccpath)
90-
return gccpath
91-
92-
gccpath = env.get('CXX')
93-
blab("Couldn't find a compiler! Fallback to %s" % gccpath)
91+
# Skip '*-elf-g++' (crosstool-NG)
92+
if not gpath.stem.endswith('-elf-g++'):
93+
gccpath = str(gpath.resolve())
94+
break
95+
96+
if not gccpath:
97+
for ppath in envpath:
98+
for gpath in ppath.glob(gcc_exe):
99+
# Skip macOS Clang
100+
if gpath != 'usr/bin/g++' or sysname != 'Darwin':
101+
gccpath = str(gpath.resolve())
102+
break
103+
104+
if not gccpath:
105+
gccpath = env.get('CXX')
106+
blab("Couldn't find a compiler! Fallback to '%s'" % gccpath)
107+
nocache = 1
108+
109+
# Cache the g++ path to speed up the next build
110+
if not nocache and gccpath and ENV_BUILD_PATH.exists():
111+
blab("Caching g++ for current env")
112+
GCC_PATH_CACHE.write_text(gccpath)
113+
94114
return gccpath

0 commit comments

Comments
 (0)