Skip to content

Commit

Permalink
🔨 Minor build script changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 23, 2022
1 parent 6577fba commit edeea5a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
18 changes: 8 additions & 10 deletions buildroot/share/PlatformIO/scripts/common-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,17 @@ def add_to_feat_cnf(feature, flines):
feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
blab("[%s] lib_deps = %s" % (feature, dep), 3)

def load_config():
def load_features():
blab("========== Gather [features] entries...")
items = ProjectConfig().items('features')
for key in items:
for key in ProjectConfig().items('features'):
feature = key[0].upper()
if not feature in FEATURE_CONFIG:
FEATURE_CONFIG[feature] = { 'lib_deps': [] }
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:
for n in env.GetProjectOptions():
key = n[0]
mat = re.match(r'custom_marlin\.(.+)', key)
if mat:
Expand Down Expand Up @@ -127,10 +125,10 @@ def force_ignore_unused_libs():
set_env_field('lib_ignore', lib_ignore)

def apply_features_config():
load_config()
load_features()
blab("========== Apply enabled features...")
for feature in FEATURE_CONFIG:
if not env.MarlinFeatureIsEnabled(feature):
if not env.MarlinHas(feature):
continue

feat = FEATURE_CONFIG[feature]
Expand Down Expand Up @@ -212,7 +210,7 @@ def load_marlin_features():
#
# Return True if a matching feature is enabled
#
def MarlinFeatureIsEnabled(env, feature):
def MarlinHas(env, feature):
load_marlin_features()
r = re.compile('^' + feature + '$')
found = list(filter(r.match, env['MARLIN_FEATURES']))
Expand All @@ -225,7 +223,7 @@ def MarlinFeatureIsEnabled(env, feature):
if val in [ '', '1', 'true' ]:
some_on = True
elif val in env['MARLIN_FEATURES']:
some_on = env.MarlinFeatureIsEnabled(val)
some_on = env.MarlinHas(val)

return some_on

Expand All @@ -239,7 +237,7 @@ def MarlinFeatureIsEnabled(env, feature):
#
# Add a method for other PIO scripts to query enabled features
#
env.AddMethod(MarlinFeatureIsEnabled)
env.AddMethod(MarlinHas)

#
# Add dependencies for enabled Marlin features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Import("env")

if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"):
if env.MarlinHas("POSTMORTEM_DEBUGGING"):
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple")
patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done")

Expand Down
5 changes: 4 additions & 1 deletion buildroot/share/PlatformIO/scripts/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def run_preprocessor(env, fn=None):
depcmd = cmd + [ filename ]
cmd = ' '.join(depcmd)
blab(cmd)
define_list = subprocess.check_output(cmd, shell=True).splitlines()
try:
define_list = subprocess.check_output(cmd, shell=True).splitlines()
except:
define_list = {}
preprocessor_cache[filename] = define_list
return define_list

Expand Down
4 changes: 2 additions & 2 deletions docs/ConfigEmbedding.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Configuration Embedding

Starting with version 2.0.9.3, Marlin automatically extracts the configuration used to generate the firmware and stores it in the firmware binary. This is enabled by defining `CONFIGURATION_EMBEDDING` in `Configuration_adv.h`.
Starting with version 2.0.9.3, Marlin can automatically extract the configuration used to generate the firmware and store it in the firmware binary. This is enabled by defining `CONFIGURATION_EMBEDDING` in `Configuration_adv.h`.

## How it's done
To create the embedded configuration, we do a compiler pass to process the Configuration files and extract all active options. The active options are parsed into key/value pairs, serialized to JSON format, and stored in a file called `marlin_config.json`, which also includes specific build information (like the git revision, the build date, and some version information. The JSON file is then compressed in a ZIP archive called `.pio/build/mc.zip` which is converted into a C array and stored in a C++ file called `mc.h` which is included in the build.
At the start of the PlatformIO build process, we create an embedded configuration by extracting all active options from the Configuration files and writing them out as JSON to `marlin_config.json`, which also includes specific build information (like the git revision, the build date, and some version information. The JSON file is then compressed in a ZIP archive called `.pio/build/mc.zip` which is converted into a C array and stored in a C++ file called `mc.h` which is included in the build.

## Extracting configurations from a Marlin binary
To get the configuration out of a binary firmware, you'll need a non-write-protected SD card inserted into the printer while running the firmware.
Expand Down

0 comments on commit edeea5a

Please sign in to comment.