mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-01-08 07:37:43 -07:00
use python to find pin_*.h files
This commit is contained in:
parent
5bbf953711
commit
caeca8bf3e
2 changed files with 31 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -8,9 +8,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) $(SCRIPTS_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)
|
||||
|
|
|
|||
29
buildroot/share/scripts/find.py
Normal file
29
buildroot/share/scripts/find.py
Normal 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('\\', '/'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue