diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index f1946770c..0990faab6 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -219,41 +219,37 @@ with open(jsonLoc) as f: jsonStr = re.sub("//.*","", f.read(), flags=re.MULTILINE) userPrefs = json.loads(jsonStr) -pref_flags = [] -# Pre-process the userPrefs -for pref in userPrefs: - if userPrefs[pref].startswith("{"): - pref_flags.append("-D" + pref + "=" + userPrefs[pref]) - elif userPrefs[pref].lstrip("-").replace(".", "").isdigit(): - pref_flags.append("-D" + pref + "=" + userPrefs[pref]) - elif userPrefs[pref] == "true" or userPrefs[pref] == "false": - pref_flags.append("-D" + pref + "=" + userPrefs[pref]) - elif userPrefs[pref].startswith("meshtastic_"): - pref_flags.append("-D" + pref + "=" + userPrefs[pref]) - # If the value is a string, we need to wrap it in quotes - else: - pref_flags.append("-D" + pref + "=" + env.StringifyMacro(userPrefs[pref]) + "") - -# General options that are passed to the C and C++ compilers # Calculate unix epoch for current day (midnight) current_date = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) build_epoch = int(current_date.timestamp()) -flags = [ - "-DAPP_VERSION=" + verObj["long"], - "-DAPP_VERSION_SHORT=" + verObj["short"], - "-DAPP_ENV=" + env.get("PIOENV"), - "-DAPP_REPO=" + repo_owner, - "-DBUILD_EPOCH=" + str(build_epoch), - ] + pref_flags +cpp_defines = [ + ("APP_VERSION", verObj["long"]), + ("APP_VERSION_SHORT", verObj["short"]), + ("APP_ENV", env.get("PIOENV")), + ("APP_REPO", repo_owner), + ("BUILD_EPOCH", str(build_epoch)), +] -print("Using flags:") -for flag in flags: - print(flag) +# Process userPrefs into CPPDEFINES +for pref in userPrefs: + val = userPrefs[pref] + if val.startswith("{"): + cpp_defines.append((pref, val)) + elif val.lstrip("-").replace(".", "").isdigit(): + cpp_defines.append((pref, val)) + elif val == "true" or val == "false": + cpp_defines.append((pref, val)) + elif val.startswith("meshtastic_"): + cpp_defines.append((pref, val)) + else: + cpp_defines.append((pref, env.StringifyMacro(val))) -projenv.Append( - CCFLAGS=flags, -) +print("Using CPPDEFINES:") +for d in cpp_defines: + print(f" -D{d[0]}={d[1]}") + +projenv.Append(CPPDEFINES=cpp_defines) for lb in env.GetLibBuilders(): if lb.name == "meshtastic-device-ui": diff --git a/platformio.ini b/platformio.ini index d9c685e8b..7d5f9b24c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ extra_configs = description = Meshtastic [env] -test_build_src = true +; test_build_src = true ; disabled for faster incremental builds extra_scripts = pre:bin/platformio-pre.py bin/platformio-custom.py