cmake: Zephyr CMake package clean-up and minor fix

Fixes: #27375

This is a cleanup of the Zephyr CMake package export.
The code has been simplified so that the export now happens through a
CMake script. This avoids several generated CMake build files compared
to previous export mode, and thus removes the need for a CMake pristine
script.

A benefit of this cleanup is that it also fixes #27375.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
diff --git a/scripts/west_commands/export.py b/scripts/west_commands/export.py
index f7f8dec..b650ed2 100644
--- a/scripts/west_commands/export.py
+++ b/scripts/west_commands/export.py
@@ -5,7 +5,6 @@
 import argparse
 from pathlib import Path
 from shutil import rmtree
-from subprocess import CalledProcessError
 
 from west.commands import WestCommand
 from west import log
@@ -45,35 +44,20 @@
         # The 'share' subdirectory of the top level zephyr repository.
         share = Path(__file__).parents[2] / 'share'
 
-        run_cmake_and_clean_up(share / 'zephyr-package' / 'cmake')
-        run_cmake_and_clean_up(share / 'zephyrunittest-package' / 'cmake')
+        run_cmake_export(share / 'zephyr-package' / 'cmake')
+        run_cmake_export(share / 'zephyrunittest-package' / 'cmake')
 
-def run_cmake_and_clean_up(path):
-    # Run a package installation script, cleaning up afterwards.
+def run_cmake_export(path):
+    # Run a package installation script.
     #
     # Filtering out lines that start with -- ignores the normal
     # CMake status messages and instead only prints the important
     # information.
 
-    try:
-        lines = run_cmake(['-S', str(path), '-B', str(path)],
-                          capture_output=True)
-    finally:
-        msg = [line for line in lines if not line.startswith('-- ')]
-        log.inf('\n'.join(msg))
-        clean_up(path)
-
-def clean_up(path):
-    try:
-        run_cmake(['-P', str(path / 'pristine.cmake')],
-                  capture_output=True)
-    except CalledProcessError:
-        # Do our best to clean up even though CMake failed.
-        log.wrn(f'Failed to make {path} pristine; '
-                'removing known generated files...')
-        for subpath in ['CMakeCache.txt', 'CMakeFiles', 'build.ninja',
-                        'cmake_install.cmake', 'rules.ninja']:
-            remove_if_exists(Path(path) / subpath)
+    lines = run_cmake(['-P', str(path / 'zephyr_export.cmake')],
+                      capture_output=True)
+    msg = [line for line in lines if not line.startswith('-- ')]
+    log.inf('\n'.join(msg))
 
 def remove_if_exists(pathobj):
     if pathobj.is_file():