From 579a5b239b6db6dd928050f891690c323723eb54 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Fri, 13 Jan 2023 02:42:34 +0300 Subject: [PATCH] pio: helper to build single-source .E --- code/scripts/espurna_utils/build.py | 19 +++++++++++++++++++ code/scripts/pio_main.py | 3 +++ 2 files changed, 22 insertions(+) diff --git a/code/scripts/espurna_utils/build.py b/code/scripts/espurna_utils/build.py index 8eaf486b..5b93589f 100644 --- a/code/scripts/espurna_utils/build.py +++ b/code/scripts/espurna_utils/build.py @@ -69,6 +69,25 @@ def merge_cpp(target, source, env, encoding="utf-8"): def app_add_builder_single_source(env): # generate things in the $BUILD_DIR, so there's no need for any extra clean-up code source = os.path.join("${BUILD_DIR}", "espurna_single_source", "src", "main.cpp") + env.SetDefault(ESPURNA_SINGLE_SOURCE_TARGET=source) + + # also allow to generate .E file from the .cpp, so we can inspect build flags + env.SetDefault(PREPROCESSCOM=env["CXXCOM"].replace("-c", "-dM -E")) + + # Create pseudo-builder and add to enviroment + def builder_generator(target, source, env, for_signature): + return env.VerboseAction( + "$PREPROCESSCOM", + "Preprocessing $SOURCE", + ) + + env.Append( + BUILDERS={ + "PreProcess": env.Builder( + generator=builder_generator, suffix=".E", src_suffix=".cpp" + ) + } + ) # substitute a single node instead of building it somewhere else as a lib or extra source dir # (...and since we can't seem to modify src_filter specifically for the project dir, only middleware works :/) diff --git a/code/scripts/pio_main.py b/code/scripts/pio_main.py index 4fe25fc8..704bfe40 100644 --- a/code/scripts/pio_main.py +++ b/code/scripts/pio_main.py @@ -70,3 +70,6 @@ app_add_target_build_and_copy(projenv) # handle special GzipFile builder app_add_gzip_file(projenv) + +# pre-processed single-source only makes sense from projenv +projenv.PreProcess(env["ESPURNA_SINGLE_SOURCE_TARGET"])