🔨 Pins 'find.py' script for Windows (#28195)
Some checks are pending
CI - Build Tests / Build Test (push) Waiting to run
CI - Unit Tests / Unit Test (push) Waiting to run
CI - Validate Source Files / Validate Source Files (push) Waiting to run

This commit is contained in:
ellensp 2025-12-23 03:41:21 +13:00 committed by GitHub
parent 0ca11bc2f0
commit a595c48526
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 5 deletions

View file

@ -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)

29
buildroot/share/make/find.py Executable file
View file

@ -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 <dir> -mindepth <num> -name <pattern>", 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('\\', '/'))