From 2316fb2d056d3dd71d2a3f2cf9da6746b4d655ef Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Tue, 20 Apr 2021 05:11:43 -0500
Subject: [PATCH] Extra dependency script logging

---
 .../PlatformIO/scripts/common-dependencies.py | 37 +++++++++++--------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py
index fe6ae7dba5d..01ee89e25e4 100644
--- a/buildroot/share/PlatformIO/scripts/common-dependencies.py
+++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py
@@ -40,9 +40,9 @@ try:
 except:
 	verbose = 0
 
-def blab(str):
-	if verbose:
-		print(str)
+def blab(str,level=1):
+	if verbose >= level:
+		print("[deps] %s" % str)
 
 FEATURE_CONFIG = {}
 
@@ -65,13 +65,16 @@ def add_to_feat_cnf(feature, flines):
 		name = parts.pop(0)
 		if name in ['build_flags', 'extra_scripts', 'src_filter', 'lib_ignore']:
 			feat[name] = '='.join(parts)
+			blab("[%s] %s=%s" % (feature, name, feat[name]), 3)
 		else:
-			for dep in line.split(','):
+			for dep in re.split(r",\s*", line):
 				lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0)
 				lib_re = re.compile('(?!^' + lib_name + '\\b)')
 				feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
+				blab("[%s] lib_deps = %s" % (feature, dep), 3)
 
 def load_config():
+	blab("========== Gather [features] entries...")
 	items = ProjectConfig().items('features')
 	for key in items:
 		feature = key[0].upper()
@@ -80,16 +83,20 @@ def load_config():
 		add_to_feat_cnf(feature, key[1])
 
 	# Add options matching custom_marlin.MY_OPTION to the pile
+	blab("========== Gather custom_marlin entries...")
 	all_opts = env.GetProjectOptions()
 	for n in all_opts:
-		mat = re.match(r'custom_marlin\.(.+)', n[0])
+		key = n[0]
+		mat = re.match(r'custom_marlin\.(.+)', key)
 		if mat:
 			try:
-				val = env.GetProjectOption(n[0])
+				val = env.GetProjectOption(key)
 			except:
 				val = None
 			if val:
-				add_to_feat_cnf(mat.group(1).upper(), val)
+				opt = mat.group(1).upper()
+				blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val ))
+				add_to_feat_cnf(opt, val)
 
 def get_all_known_libs():
 	known_libs = []
@@ -124,6 +131,7 @@ def force_ignore_unused_libs():
 
 def apply_features_config():
 	load_config()
+	blab("========== Apply enabled features...")
 	for feature in FEATURE_CONFIG:
 		if not env.MarlinFeatureIsEnabled(feature):
 			continue
@@ -131,12 +139,13 @@ def apply_features_config():
 		feat = FEATURE_CONFIG[feature]
 
 		if 'lib_deps' in feat and len(feat['lib_deps']):
-			blab("Adding lib_deps for %s... " % feature)
+			blab("========== Adding lib_deps for %s... " % feature, 2)
 
 			# feat to add
 			deps_to_add = {}
 			for dep in feat['lib_deps']:
 				deps_to_add[PackageSpec(dep).name] = dep
+				blab("==================== %s... " % dep, 2)
 
 			# Does the env already have the dependency?
 			deps = env.GetProjectOption('lib_deps')
@@ -159,16 +168,16 @@ def apply_features_config():
 
 		if 'build_flags' in feat:
 			f = feat['build_flags']
-			blab("Adding build_flags for %s: %s" % (feature, f))
+			blab("========== Adding build_flags for %s: %s" % (feature, f), 2)
 			new_flags = env.GetProjectOption('build_flags') + [ f ]
 			env.Replace(BUILD_FLAGS=new_flags)
 
 		if 'extra_scripts' in feat:
-			blab("Running extra_scripts for %s... " % feature)
+			blab("Running extra_scripts for %s... " % feature, 2)
 			env.SConscript(feat['extra_scripts'], exports="env")
 
 		if 'src_filter' in feat:
-			blab("Adding src_filter for %s... " % feature)
+			blab("========== Adding src_filter for %s... " % feature, 2)
 			src_filter = ' '.join(env.GetProjectOption('src_filter'))
 			# first we need to remove the references to the same folder
 			my_srcs = re.findall(r'[+-](<.*?>)', feat['src_filter'])
@@ -182,7 +191,7 @@ def apply_features_config():
 			env.Replace(SRC_FILTER=src_filter)
 
 		if 'lib_ignore' in feat:
-			blab("Adding lib_ignore for %s... " % feature)
+			blab("========== Adding lib_ignore for %s... " % feature, 2)
 			lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']]
 			set_env_field('lib_ignore', lib_ignore)
 
@@ -200,7 +209,6 @@ def search_compiler():
 		pass
 
 	if os.path.exists(GCC_PATH_CACHE):
-		blab("Getting g++ path from cache")
 		with open(GCC_PATH_CACHE, 'r') as f:
 			return f.read()
 
@@ -227,7 +235,6 @@ def search_compiler():
 			filepath = os.path.sep.join([pathdir, filepath])
 			# Cache the g++ path to no search always
 			if os.path.exists(ENV_BUILD_PATH):
-				blab("Caching g++ for current env")
 				with open(GCC_PATH_CACHE, 'w+') as f:
 					f.write(filepath)
 
@@ -262,7 +269,7 @@ def load_marlin_features():
 
 	cmd += ['-D__MARLIN_DEPS__ -w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
 	cmd = ' '.join(cmd)
-	blab(cmd)
+	blab(cmd, 4)
 	define_list = subprocess.check_output(cmd, shell=True).splitlines()
 	marlin_features = {}
 	for define in define_list: