Browse Source

🔨 Use first g++ in path for 'native' targets

Scott Lahteine 2 years ago
parent
commit
505ab1bb62
2 changed files with 16 additions and 9 deletions
  1. 10
    6
      buildroot/share/PlatformIO/scripts/preprocessor.py
  2. 6
    3
      ini/native.ini

+ 10
- 6
buildroot/share/PlatformIO/scripts/preprocessor.py View File

@@ -3,6 +3,7 @@
3 3
 #
4 4
 import subprocess,os,re
5 5
 
6
+nocache = 1
6 7
 verbose = 0
7 8
 
8 9
 def blab(str):
@@ -50,7 +51,7 @@ def run_preprocessor(env, fn=None):
50 51
 #
51 52
 def search_compiler(env):
52 53
 
53
-	ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV'])
54
+	ENV_BUILD_PATH = os.path.join(env['PROJECT_BUILD_DIR'], env['PIOENV'])
54 55
 	GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
55 56
 
56 57
 	try:
@@ -60,14 +61,17 @@ def search_compiler(env):
60 61
 	except:
61 62
 		pass
62 63
 
63
-	if os.path.exists(GCC_PATH_CACHE):
64
+	# Warning: The cached .gcc_path will obscure a newly-installed toolkit
65
+	if not nocache and os.path.exists(GCC_PATH_CACHE):
64 66
 		blab("Getting g++ path from cache")
65 67
 		with open(GCC_PATH_CACHE, 'r') as f:
66 68
 			return f.read()
67 69
 
68
-	# Find the current platform compiler by searching the $PATH
69
-	# which will be in a platformio toolchain bin folder
70
-	path_regex = re.escape(env['PROJECT_PACKAGES_DIR'])
70
+	# Find a platform compiler by searching $PATH items
71
+	# A native target will search all PATH bin folders.
72
+	# Others look only within $HOME/.platformio.
73
+	path_regex = "" if env.GetProjectOption('platform') == 'native' else re.escape(env['PROJECT_PACKAGES_DIR'])
74
+
71 75
 	gcc = "g++"
72 76
 	if env['PLATFORM'] == 'win32':
73 77
 		path_separator = ';'
@@ -87,7 +91,7 @@ def search_compiler(env):
87 91
 			# Use entire path to not rely on env PATH
88 92
 			filepath = os.path.sep.join([pathdir, filepath])
89 93
 			# Cache the g++ path to no search always
90
-			if os.path.exists(ENV_BUILD_PATH):
94
+			if not nocache and os.path.exists(ENV_BUILD_PATH):
91 95
 				blab("Caching g++ for current env")
92 96
 				with open(GCC_PATH_CACHE, 'w+') as f:
93 97
 					f.write(filepath)

+ 6
- 3
ini/native.ini View File

@@ -63,12 +63,12 @@ build_flags = ${simulator_linux.build_flags} ${simulator_linux.release_flags}
63 63
 #
64 64
 # Simulator for macOS (MacPorts)
65 65
 #
66
-#  sudo port install gcc10 gdb glm libsdl2 libsdl2_net freetype
66
+#  sudo port install gcc11 gdb glm libsdl2 libsdl2_net freetype
67 67
 #  sudo port install ld64 @3_3 +ld64_xcode
68 68
 #
69 69
 #  cd /opt/local/bin
70 70
 #  sudo rm -f gcc g++ cc
71
-#  sudo ln -s gcc-mp-10 gcc ; sudo ln -s g++-mp-10 g++ ; sudo ln -s g++ cc
71
+#  sudo ln -s gcc-mp-11 gcc ; sudo ln -s g++-mp-11 g++ ; sudo ln -s g++ cc
72 72
 # This step may be obsolete:
73 73
 #  sudo port uninstall ld64 ld64-latest
74 74
 #
@@ -79,7 +79,6 @@ build_flags = ${simulator_linux.build_flags} ${simulator_linux.release_flags}
79 79
 #
80 80
 [simulator_macos]
81 81
 build_unflags     = -lGL
82
-custom_verbose    = 0
83 82
 build_flags       =
84 83
   -I/opt/local/include
85 84
   -I/opt/local/include/freetype2
@@ -93,11 +92,15 @@ build_flags       =
93 92
 extends         = env:simulator_linux_debug
94 93
 build_flags     = ${env:simulator_linux_debug.build_flags} ${simulator_macos.build_flags} -ggdb -Og -D_THREAD_SAFE
95 94
 build_unflags   = ${simulator_macos.build_unflags}
95
+custom_verbose  = 0
96
+custom_gcc      = g++
96 97
 
97 98
 [env:simulator_macos_release]
98 99
 extends         = env:simulator_linux_release
99 100
 build_flags     = ${env:simulator_linux_release.build_flags} ${simulator_macos.build_flags}
100 101
 build_unflags   = ${simulator_macos.build_unflags}
102
+custom_verbose  = 0
103
+custom_gcc      = g++
101 104
 
102 105
 #
103 106
 # Simulator for Windows 10

Loading…
Cancel
Save