From a7444021c6d31c554cb22e1062f72033e5f21c61 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 20 Jun 2024 12:42:26 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Fatal=20error=20for=20wrong=20GC?= =?UTF-8?q?C=20on=20macOS=20Native=20Sim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../share/PlatformIO/scripts/simulator.py | 68 ++++++++++++------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/simulator.py b/buildroot/share/PlatformIO/scripts/simulator.py index 4276a2593e..2b30ec32c0 100644 --- a/buildroot/share/PlatformIO/scripts/simulator.py +++ b/buildroot/share/PlatformIO/scripts/simulator.py @@ -17,37 +17,53 @@ if pioutil.is_pio_build(): env['PROGNAME'] = "MarlinSimulator" # - # If Xcode is installed add the path to its Frameworks folder, - # or if Mesa is installed try to use its GL/gl.h. + # Check for a valid GCC and available OpenGL on macOS # - + emsg = '' + fatal = 0 import sys if sys.platform == 'darwin': - # - # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS') - # - env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ] - - # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa - xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" - mesa_path = "/opt/local/include/GL/gl.h" - - import os.path - - if os.path.exists(xcode_path): - - env['BUILD_FLAGS'] += [ "-F" + xcode_path ] - print("Using OpenGL framework headers from Xcode.app") - - elif os.path.exists(mesa_path): - - env['BUILD_FLAGS'] += [ '-D__MESA__' ] - print("Using OpenGL header from", mesa_path) + import shutil + gcc = shutil.which('gcc') + if gcc == '' or gcc == '/usr/bin/gcc': + if gcc == '': + emsg = "\u001b[31mNo GCC found in your configured shell PATH." + elif gcc == '/usr/bin/gcc': + emsg = "\u001b[31mCan't build Marlin Native on macOS using the included version of GCC (clang)." + emsg += "\n\u001b[31mSee 'native.ini' for instructions to install GCC with MacPorts or Homebrew." + fatal = 1 else: - print("\n\nNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h.\n\n") + # + # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS') + # + env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ] - # Break out of the PIO build immediately - sys.exit(1) + # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa + xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks" + mesa_path = "/opt/local/include/GL/gl.h" + + import os.path + + if os.path.exists(xcode_path): + + env['BUILD_FLAGS'] += [ "-F" + xcode_path ] + emsg = "\u001b[33mUsing OpenGL framework headers from Xcode.app" + + elif os.path.exists(mesa_path): + + env['BUILD_FLAGS'] += [ '-D__MESA__' ] + emsg = f"\u001b[33mUsing OpenGL header from {mesa_path}" + + else: + + emsg = "\u001b[31mNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h." + fatal = 1 + + # Print error message, if any + if emsg: print(f"\n\n{emsg}\n\n") + + # Break out of the PIO build immediately + if fatal: sys.exit(1)