[mbed] Fix build out of space issue (#27506)

* [mbed] Extend Python build with ota-requestor-app

Add ota-requestor-app to Python builder.
This allows for covering all supported examples.

Signed-off-by: ATmobica <artur.tynecki@arm.com>

* [mbed] CI workflow improvements

Remove changed path detection steps.
Replace custom build script with Python builder.
The application output goes into `out` directory
and does not dirty the source (#27480).

Signed-off-by: ATmobica <artur.tynecki@arm.com>

---------

Signed-off-by: ATmobica <artur.tynecki@arm.com>
diff --git a/.github/workflows/examples-mbed.yaml b/.github/workflows/examples-mbed.yaml
index e1fb72d..5b92a89 100644
--- a/.github/workflows/examples-mbed.yaml
+++ b/.github/workflows/examples-mbed.yaml
@@ -26,15 +26,15 @@
 
 env:
     CHIP_NO_LOG_TIMESTAMPS: true
-    
+
 jobs:
     mbedos:
         name: Mbed OS examples building
 
         env:
-            BUILD_TYPE: mbedos
+            PLATFORM_NAME: mbed
             APP_PROFILE: release
-            APP_TARGET: CY8CPROTO_062_4343W
+            APP_TARGET: cy8cproto_062_4343w
 
         runs-on: ubuntu-latest
         if: github.actor != 'restyled-io[bot]'
@@ -52,16 +52,6 @@
               with:
                 platform: mbed
 
-            - name: Detect changed paths
-              uses: dorny/paths-filter@v2
-              id: changed_paths
-              with:
-                  filters: |
-                      mbed:
-                        - '**/mbed/**'
-                      pigweedapp:
-                        - 'examples/pigweed-app/mbed/**'
-
             - name: Set up environment for size reports
               uses: ./.github/actions/setup-size-reports
               if: ${{ !env.ACT }}
@@ -70,70 +60,98 @@
 
             - name: Build lock-app example
               run: |
-                  scripts/examples/mbed_example.sh -a=lock-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-lock-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE lock-app \
-                    examples/lock-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-lock-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET lock-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-lock-$APP_PROFILE/chip-mbed-lock-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build lighting-app example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.mbed == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=lighting-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-light-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE lighting-app \
-                    examples/lighting-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-lighting-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET lighting-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-light-$APP_PROFILE/chip-mbed-lighting-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build pigweed-app example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.pigweedapp == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=pigweed-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-pigweed-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE pigweed-app \
-                    examples/pigweed-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-pigweed-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET pigweed-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-pigweed-$APP_PROFILE/chip-mbed-pigweed-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build all-clusters-app example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.mbed == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=all-clusters-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-all-clusters-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE all-clusters-app \
-                    examples/all-clusters-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-all-clusters-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET all-clusters-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-all-clusters-$APP_PROFILE/chip-mbed-all-clusters-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build all-clusters-minimal-app example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.mbed == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=all-clusters-minimal-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-all-clusters-minimal-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE all-clusters-minimal-app \
-                    examples/all-clusters-minimal-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-all-clusters-minimal-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET all-clusters-minimal-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-all-clusters-minimal-$APP_PROFILE/chip-mbed-all-clusters-minimal-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build shell example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.mbed == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=shell -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-shell-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE shell \
-                    examples/shell/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-shell-example.elf \
+                    $PLATFORM_NAME $APP_TARGET shell-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-shell-$APP_PROFILE/chip-mbed-shell-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
             - name: Build ota-requestor-app example
-              if: github.event_name == 'push' || steps.changed_paths.outputs.mbed == 'true'
+              if: github.event_name == 'push'
               run: |
-                  scripts/examples/mbed_example.sh -a=ota-requestor-app -b=$APP_TARGET -p=$APP_PROFILE
+                  ./scripts/run_in_build_env.sh \
+                    "./scripts/build/build_examples.py \
+                      --target $PLATFORM_NAME-$APP_TARGET-ota-requestor-$APP_PROFILE \
+                      build \
+                    "
                   .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
-                    mbed $APP_TARGET+$APP_PROFILE shell \
-                    examples/ota-requestor-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-ota-requestor-app-example.elf \
+                    $PLATFORM_NAME $APP_TARGET ota-requestor-app-$APP_PROFILE \
+                    out/$PLATFORM_NAME-$APP_TARGET-ota-requestor-$APP_PROFILE/chip-mbed-ota-requestor-app-example.elf \
                     /tmp/bloat_reports/
                   rm -rf ./out
 
diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py
index 4fc6145..7447eec 100755
--- a/scripts/build/build/targets.py
+++ b/scripts/build/build/targets.py
@@ -349,6 +349,7 @@
         TargetPart('all-clusters', app=MbedApp.ALL_CLUSTERS),
         TargetPart('all-clusters-minimal', app=MbedApp.ALL_CLUSTERS_MINIMAL),
         TargetPart('pigweed', app=MbedApp.PIGWEED),
+        TargetPart('ota-requestor', app=MbedApp.OTA_REQUESTOR),
         TargetPart('shell', app=MbedApp.SHELL),
     ])
 
diff --git a/scripts/build/builders/mbed.py b/scripts/build/builders/mbed.py
index 46b3ead..fd2aa00 100644
--- a/scripts/build/builders/mbed.py
+++ b/scripts/build/builders/mbed.py
@@ -26,6 +26,7 @@
     ALL_CLUSTERS_MINIMAL = auto()
     PIGWEED = auto()
     SHELL = auto()
+    OTA_REQUESTOR = auto()
 
     @property
     def ExampleName(self):
@@ -39,6 +40,8 @@
             return 'all-clusters-minimal-app'
         elif self == MbedApp.PIGWEED:
             return 'pigweed-app'
+        elif self == MbedApp.OTA_REQUESTOR:
+            return 'ota-requestor-app'
         elif self == MbedApp.SHELL:
             return 'shell'
         else:
@@ -56,6 +59,8 @@
             return 'chip-mbed-all-clusters-minimal-app-example'
         elif self == MbedApp.PIGWEED:
             return 'chip-mbed-pigweed-app-example'
+        elif self == MbedApp.OTA_REQUESTOR:
+            return 'chip-mbed-ota-requestor-app-example'
         elif self == MbedApp.SHELL:
             return 'chip-mbed-shell-example'
         else:
diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt
index b3e88f5..f6c21f3 100644
--- a/scripts/build/testdata/all_targets_linux_x64.txt
+++ b/scripts/build/testdata/all_targets_linux_x64.txt
@@ -15,7 +15,7 @@
 imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release]
 infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage]
 k32w-{light,shell,lock,contact}[-se05x][-no-ble][-no-ota][-low-power][-nologs][-crypto-platform][-tokenizer]
-mbed-cy8cproto_062_4343w-{lock,light,all-clusters,all-clusters-minimal,pigweed,shell}[-release][-develop][-debug]
+mbed-cy8cproto_062_4343w-{lock,light,all-clusters,all-clusters-minimal,pigweed,ota-requestor,shell}[-release][-develop][-debug]
 mw320-all-clusters-app
 nrf-{nrf5340dk,nrf52840dk,nrf52840dongle}-{all-clusters,all-clusters-minimal,lock,light,light-switch,shell,pump,pump-controller,window-covering}[-rpc]
 nrf-native-posix-64-tests