From a595c48526b3625f31bce2dbda7fd72932f2f8a8 Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Tue, 23 Dec 2025 03:41:21 +1300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Pins=20'find.py'=20script=20for?= =?UTF-8?q?=20Windows=20(#28195)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 9 +++--- buildroot/share/make/find.py | 29 +++++++++++++++++++ .../{scripts => make}/get_test_targets.py | 0 .../{scripts => make}/validate_boards.py | 0 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100755 buildroot/share/make/find.py rename buildroot/share/{scripts => make}/get_test_targets.py (100%) rename buildroot/share/{scripts => make}/validate_boards.py (100%) diff --git a/Makefile b/Makefile index 4e35047896..f8a9ae3c4e 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,8 @@ UNIT_TEST_CONFIG ?= default ifeq ($(OS),Windows_NT) # Windows: use `where` – fall back through the three common names PYTHON := $(shell which python 2>nul || which python3 2>nul || which py 2>nul) - # Windows: Use cmd tools to find pins files - PINS_RAW := $(shell cmd //c "dir /s /b Marlin\src\pins\*.h 2>nul | findstr /r ".*Marlin\\\\src\\\\pins\\\\.*\\\\pins_.*\.h"") - PINS := $(subst \,/,$(PINS_RAW)) + # Windows: Use Python script to find pins files + PINS := $(shell $(PYTHON) $(MAKESCRIPTS_DIR)/find.py Marlin/src/pins -mindepth 2 -name 'pins_*.h') else # POSIX: use `command -v` – prefer python3 over python PYTHON := $(shell command -v python3 2>/dev/null || command -v python 2>/dev/null) @@ -90,7 +89,7 @@ tests-all-local: @$(PYTHON) -c "import yaml" 2>/dev/null || (echo 'pyyaml module is not installed. Install it with "$(PYTHON) -m pip install pyyaml"' && exit 1) export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \ && export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \ - && for TEST_TARGET in $$($(PYTHON) $(SCRIPTS_DIR)/get_test_targets.py) ; do \ + && for TEST_TARGET in $$($(PYTHON) $(MAKESCRIPTS_DIR)/get_test_targets.py) ; do \ if [ "$$TEST_TARGET" = "linux_native" ] && [ "$$(uname)" = "Darwin" ]; then \ echo "Skipping tests for $$TEST_TARGET on macOS" ; \ continue ; \ @@ -174,4 +173,4 @@ BOARDS_FILE := Marlin/src/core/boards.h validate-boards: @echo "Validating boards.h file" - @$(PYTHON) $(SCRIPTS_DIR)/validate_boards.py $(BOARDS_FILE) || (echo "\nError: boards.h file is not valid. Please check and correct it.\n" && exit 1) + @$(PYTHON) $(MAKESCRIPTS_DIR)/validate_boards.py $(BOARDS_FILE) || (echo "\nError: boards.h file is not valid. Please check and correct it.\n" && exit 1) diff --git a/buildroot/share/make/find.py b/buildroot/share/make/find.py new file mode 100755 index 0000000000..e0dd925931 --- /dev/null +++ b/buildroot/share/make/find.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# This is a cut-down version of the Linux 'find' command, implemented in Python for Marlin build scripts. +import sys +import os +import fnmatch + +def find_files(root, mindepth, pattern): + results = [] + root = os.path.normpath(root) + for dirpath, dirnames, filenames in os.walk(root): + for filename in filenames: + if fnmatch.fnmatch(filename, pattern): + full_path = os.path.join(dirpath, filename) + rel_path = os.path.relpath(full_path, root) + # mindepth: number of path components in rel_path >= mindepth + if rel_path.count(os.sep) + 1 >= mindepth: + results.append(full_path) + return results + +if __name__ == "__main__": + if len(sys.argv) != 6 or sys.argv[2] != '-mindepth' or sys.argv[4] != '-name': + print("Usage: find.py -mindepth -name ", file=sys.stderr) + sys.exit(1) + root = sys.argv[1] + mindepth = int(sys.argv[3]) + pattern = sys.argv[5] + files = find_files(root, mindepth, pattern) + for f in files: + print(f.replace('\\', '/')) diff --git a/buildroot/share/scripts/get_test_targets.py b/buildroot/share/make/get_test_targets.py similarity index 100% rename from buildroot/share/scripts/get_test_targets.py rename to buildroot/share/make/get_test_targets.py diff --git a/buildroot/share/scripts/validate_boards.py b/buildroot/share/make/validate_boards.py similarity index 100% rename from buildroot/share/scripts/validate_boards.py rename to buildroot/share/make/validate_boards.py