Skip to content

Commit

Permalink
🔨 Skip bad compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 24, 2024
1 parent 80cfdb1 commit f2d585a
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions buildroot/share/PlatformIO/scripts/preprocessor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# preprocessor.py
#
import subprocess
import subprocess, os

nocache = 1
verbose = 0
Expand Down Expand Up @@ -53,12 +53,14 @@ def run_preprocessor(env, fn=None):
# Find a compiler, considering the OS
#
def search_compiler(env):
global nocache

from pathlib import Path, PurePath

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

gccpath = None
try:
gccpath = env.GetProjectOption('custom_gcc')
blab("Getting compiler from env")
Expand All @@ -71,24 +73,42 @@ def search_compiler(env):
blab("Getting g++ path from cache")
return GCC_PATH_CACHE.read_text()

# Use any item in $PATH corresponding to a platformio toolchain bin folder
path_separator = ':'
gcc_exe = '*g++'
if env['PLATFORM'] == 'win32':

sysname = os.uname().sysname
if sysname == 'Windows':
path_separator = ';'
gcc_exe += ".exe"

envpath = map(Path, env['ENV']['PATH'].split(path_separator))

# Search for the compiler in PATH
for ppath in map(Path, env['ENV']['PATH'].split(path_separator)):
for ppath in envpath:
# Use any item in $PATH corresponding to a platformio toolchain bin folder
if ppath.match(env['PROJECT_PACKAGES_DIR'] + "/**/bin"):
for gpath in ppath.glob(gcc_exe):
gccpath = str(gpath.resolve())
# Cache the g++ path to no search always
if not nocache and ENV_BUILD_PATH.exists():
blab("Caching g++ for current env")
GCC_PATH_CACHE.write_text(gccpath)
return gccpath

gccpath = env.get('CXX')
blab("Couldn't find a compiler! Fallback to %s" % gccpath)
# Skip '*-elf-g++' (crosstool-NG)
if not gpath.stem.endswith('-elf-g++'):
gccpath = str(gpath.resolve())
break

if not gccpath:
for ppath in envpath:
for gpath in ppath.glob(gcc_exe):
# Skip macOS Clang
if gpath != 'usr/bin/g++' or sysname != 'Darwin':
gccpath = str(gpath.resolve())
break

if not gccpath:
gccpath = env.get('CXX')
blab("Couldn't find a compiler! Fallback to '%s'" % gccpath)
nocache = 1

# Cache the g++ path to speed up the next build
if not nocache and gccpath and ENV_BUILD_PATH.exists():
blab("Caching g++ for current env")
GCC_PATH_CACHE.write_text(gccpath)

return gccpath

0 comments on commit f2d585a

Please sign in to comment.