Skip to content

Commit 4766a9f

Browse files
authored
Merge branch 'espressif:master' into master
2 parents 7b6250e + 89bcb9c commit 4766a9f

File tree

311 files changed

+1197
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+1197
-48
lines changed

.github/codeql/codeql-config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ query-filters:
2323
id: tob/cpp/use-of-legacy-algorithm # We use legacy algorithms in many places for integrity checks
2424
- exclude:
2525
id: cpp/dead-code-goto # Too many false positives in no-build mode
26+
- exclude:
27+
id: cpp/wrong-type-format-argument # Too many false positives in no-build mode
2628

2729
paths-ignore:
2830
- tests/**

.github/scripts/get_affected.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def is_source_file(path: str) -> bool:
198198
return os.path.splitext(path)[1].lower() in source_extensions
199199

200200
def should_skip_file(path: str) -> bool:
201-
return os.path.splitext(path)[1].lower() in skip_extensions
201+
return os.path.splitext(path)[1].lower() in skip_extensions or path.startswith("tests/") or path.startswith("variants/")
202202

203203
def detect_universal_ctags() -> bool:
204204
"""

.github/scripts/include_checker.py

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Arduino Include Checker
4+
Scans .ino files and ensures they have #include <Arduino.h> before preprocessor directives
5+
"""
6+
7+
import sys
8+
import re
9+
import argparse
10+
from pathlib import Path
11+
from typing import List, Tuple
12+
13+
14+
def has_arduino_include(content: str) -> bool:
15+
"""Check if content already has Arduino.h include"""
16+
patterns = [
17+
r'#include\s*<Arduino\.h>',
18+
r'#include\s*"Arduino\.h"'
19+
]
20+
for pattern in patterns:
21+
if re.search(pattern, content):
22+
return True
23+
return False
24+
25+
26+
def find_first_preprocessor_line(lines: List[str]) -> int:
27+
"""
28+
Find the index of the first preprocessor directive (line starting with #)
29+
Returns -1 if no preprocessor directive found
30+
"""
31+
for i, line in enumerate(lines):
32+
stripped = line.lstrip()
33+
if stripped.startswith('#'):
34+
return i
35+
return -1
36+
37+
38+
def add_arduino_include(filepath: Path, verbose: bool = False) -> Tuple[bool, str]:
39+
"""
40+
Add #include <Arduino.h> to the file before the first preprocessor directive
41+
Returns (success, message)
42+
"""
43+
try:
44+
with open(filepath, 'r', encoding='utf-8') as f:
45+
content = f.read()
46+
47+
# Check if already has Arduino.h include
48+
if has_arduino_include(content):
49+
return True, "Already has Arduino.h include"
50+
51+
lines = content.split('\n')
52+
first_directive_idx = find_first_preprocessor_line(lines)
53+
54+
if first_directive_idx == -1:
55+
return False, "No preprocessor directive found"
56+
57+
# Insert the include before the first directive
58+
lines.insert(first_directive_idx, '#include <Arduino.h>')
59+
60+
# Write back to file
61+
with open(filepath, 'w', encoding='utf-8') as f:
62+
f.write('\n'.join(lines))
63+
64+
return True, "Added #include <Arduino.h>"
65+
66+
except Exception as e:
67+
return False, f"Error processing file: {str(e)}"
68+
69+
70+
def scan_ino_files(root_dir: str, verbose: bool = False) -> Tuple[List[Path], List[Path], List[Tuple[Path, str]]]:
71+
"""
72+
Scan directory for .ino files and process them
73+
Returns (already_had_include, files_added, failed_files_with_reasons)
74+
"""
75+
already_had = []
76+
added = []
77+
failed = []
78+
79+
root_path = Path(root_dir)
80+
if not root_path.exists():
81+
print(f"Error: Directory '{root_dir}' does not exist")
82+
sys.exit(1)
83+
84+
# Find all .ino files
85+
ino_files = list(root_path.rglob('*.ino'))
86+
87+
if not ino_files:
88+
if verbose:
89+
print(f"No .ino files found in '{root_dir}'")
90+
return already_had, added, failed
91+
92+
if verbose:
93+
print(f"Found {len(ino_files)} .ino file(s)")
94+
print("-" * 60)
95+
96+
for filepath in ino_files:
97+
if verbose:
98+
print(f"\nProcessing: {filepath.relative_to(root_path)}")
99+
100+
success, message = add_arduino_include(filepath, verbose)
101+
102+
if verbose:
103+
print(f" → {message}")
104+
105+
if success:
106+
if "Already has" in message:
107+
already_had.append(filepath)
108+
else:
109+
added.append(filepath)
110+
else:
111+
failed.append((filepath, message))
112+
113+
return already_had, added, failed
114+
115+
116+
def process_individual_files(filepaths: List[str], verbose: bool = False) -> Tuple[List[Path], List[Path], List[Tuple[Path, str]]]:
117+
"""
118+
Process individual .ino files (used by pre-commit hooks)
119+
Returns (already_had_include, files_added, failed_files_with_reasons)
120+
"""
121+
already_had = []
122+
added = []
123+
failed = []
124+
125+
if verbose:
126+
print(f"Processing {len(filepaths)} file(s)")
127+
print("-" * 60)
128+
129+
for filepath_str in filepaths:
130+
filepath = Path(filepath_str).resolve()
131+
132+
if not filepath.exists():
133+
if verbose:
134+
print(f"\n⚠️ File not found: {filepath}")
135+
failed.append((filepath, "File not found"))
136+
continue
137+
138+
if not filepath.suffix == '.ino':
139+
if verbose:
140+
print(f"\n⚠️ Skipping non-.ino file: {filepath}")
141+
continue
142+
143+
if verbose:
144+
print(f"\nProcessing: {filepath}")
145+
146+
success, message = add_arduino_include(filepath, verbose)
147+
148+
if verbose:
149+
print(f" → {message}")
150+
151+
if success:
152+
if "Already has" in message:
153+
already_had.append(filepath)
154+
else:
155+
added.append(filepath)
156+
else:
157+
failed.append((filepath, message))
158+
159+
return already_had, added, failed
160+
161+
162+
def main():
163+
parser = argparse.ArgumentParser(
164+
description='Check and fix Arduino.h includes in .ino files',
165+
epilog='Exit code 0: All files OK. Exit code 1: Files modified or failed.'
166+
)
167+
parser.add_argument(
168+
'paths',
169+
nargs='*',
170+
help='Directory to scan or specific .ino files to check (default: two levels up from script)'
171+
)
172+
parser.add_argument(
173+
'-v', '--verbose',
174+
action='store_true',
175+
help='Show detailed processing information'
176+
)
177+
178+
args = parser.parse_args()
179+
180+
# Determine what to process
181+
if not args.paths:
182+
# Default to project root (two levels up from script location)
183+
script_dir = Path(__file__).resolve().parent
184+
project_root = (script_dir / "../../").resolve()
185+
root_dir = str(project_root)
186+
if args.verbose:
187+
print(f"No directory specified, using default: {root_dir}")
188+
print(f"Scanning directory: {root_dir}")
189+
print("=" * 60)
190+
already_had, added, failed = scan_ino_files(root_dir, args.verbose)
191+
else:
192+
# Check if first argument is a directory or a file
193+
first_path = Path(args.paths[0])
194+
195+
if first_path.is_dir():
196+
# Directory mode: scan directory
197+
root_dir = args.paths[0]
198+
if args.verbose:
199+
print(f"Scanning directory: {root_dir}")
200+
print("=" * 60)
201+
already_had, added, failed = scan_ino_files(root_dir, args.verbose)
202+
else:
203+
# File mode: process individual files (pre-commit hook mode)
204+
if args.verbose:
205+
print("Running in pre-commit hook mode")
206+
print("=" * 60)
207+
already_had, added, failed = process_individual_files(args.paths, args.verbose)
208+
209+
# Only show summary in verbose mode or if there are issues
210+
if args.verbose:
211+
print("\n" + "=" * 60)
212+
print("SUMMARY")
213+
print("=" * 60)
214+
print(f"Total files found: {len(already_had) + len(added) + len(failed)}")
215+
print(f"Already had Arduino.h: {len(already_had)}")
216+
print(f"Arduino.h added: {len(added)}")
217+
print(f"Failed: {len(failed)}")
218+
219+
# Always show files that were modified
220+
if added:
221+
if not args.verbose:
222+
print("Arduino.h was added to the following file(s):")
223+
else:
224+
print(f"\n✓ Arduino.h was added to {len(added)} file(s):")
225+
for filepath in added:
226+
print(f" • {filepath}")
227+
228+
# Always show files that failed
229+
if failed:
230+
if not args.verbose:
231+
print("\nFailed to add include to the following file(s):")
232+
else:
233+
print(f"\n⚠️ Failed to add include to {len(failed)} file(s):")
234+
for filepath, reason in failed:
235+
print(f" • {filepath}")
236+
print(f" Reason: {reason}")
237+
238+
# Exit with code 1 if any files were modified or failed
239+
if added or failed:
240+
sys.exit(1)
241+
else:
242+
if args.verbose:
243+
print("\n✓ All .ino files already have Arduino.h include!")
244+
sys.exit(0)
245+
246+
247+
if __name__ == "__main__":
248+
main()

.pre-commit-config.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,28 @@ repos:
1616
hooks:
1717
# Generic checks
1818
- id: check-case-conflict
19+
name: Check for Case Conflicts
1920
- id: check-symlinks
21+
name: Check for Broken Symlinks
2022
- id: debug-statements
23+
name: Check for Debug Statements
2124
- id: destroyed-symlinks
25+
name: Check for Destroyed Symlinks
2226
- id: detect-private-key
27+
name: Check for Private Keys
2328
- id: end-of-file-fixer
29+
name: Fix End of File Formatting
2430
exclude: ^.*\.(bin|BIN)$
2531
- id: mixed-line-ending
32+
name: Fix Mixed Line Endings
2633
args: [--fix=lf]
2734
- id: trailing-whitespace
35+
name: Fix Trailing Whitespace
2836
args: [--markdown-linebreak-ext=md]
2937

3038
# JSON formatting
3139
- id: pretty-format-json
40+
name: Fix JSON Formatting
3241
stages: [manual]
3342
args: [--autofix]
3443
types_or: [json]
@@ -44,6 +53,7 @@ repos:
4453
hooks:
4554
# C/C++ formatting
4655
- id: clang-format
56+
name: Format C/C++ code using Clang Format
4757
types_or: [c, c++]
4858
exclude: ^.*\/build_opt\.h$
4959

@@ -52,6 +62,7 @@ repos:
5262
hooks:
5363
# Python formatting
5464
- id: black
65+
name: Format Python code using Black
5566
types_or: [python]
5667
args: [--line-length=120] #From the arduino code style. Add as argument rather than creating a new config file.
5768

@@ -60,6 +71,7 @@ repos:
6071
hooks:
6172
# Python linting
6273
- id: flake8
74+
name: Lint Python code using Flake8
6375
types_or: [python]
6476
additional_dependencies:
6577
- flake8-bugbear
@@ -71,49 +83,62 @@ repos:
7183
hooks:
7284
# YAML formatting
7385
- id: prettier
86+
name: Format YAML code using Prettier
7487
types_or: [yaml]
7588

7689
- repo: https://github.com/codespell-project/codespell
7790
rev: "63c8f8312b7559622c0d82815639671ae42132ac" # v2.4.1
7891
hooks:
7992
# Spell checking
8093
- id: codespell
94+
name: Check spelling in code using Codespell
8195
exclude: ^.*\.(svd|SVD)$
8296

8397
- repo: https://github.com/shellcheck-py/shellcheck-py
8498
rev: "a23f6b85d0fdd5bb9d564e2579e678033debbdff" # v0.10.0.1
8599
hooks:
86100
# Bash linting
87101
- id: shellcheck
102+
name: Lint Bash code using Shellcheck
88103
types: [shell]
89104

90105
- repo: https://github.com/openstack/bashate
91106
rev: "fbd7c2534c2701351c603ff700ddf08202430a31" # 2.1.1
92107
hooks:
93108
# Bash formatting
94109
- id: bashate
110+
name: Lint Bash code using Bashate
95111
types: [shell]
96112
args: ["-i", "E006"] # Ignore E006: Line too long
97113

114+
- repo: local
115+
hooks:
116+
- id: arduino-include-checker
117+
name: Check for Arduino.h include
118+
entry: .github/scripts/include_checker.py
119+
language: python
120+
files: ^.*\.ino$
121+
98122
- repo: https://github.com/errata-ai/vale
99123
rev: "dc4c47923788a413fb5677de6e3370d514aecb78" # v3.11.2
100124
hooks:
101125
# Sync vale styles and lint markdown and reStructuredText
102126
- id: vale
103-
name: vale-sync
127+
name: Sync Vale styles
104128
language_version: "1.23.2"
105129
pass_filenames: false
106130
args: [sync]
107131
types_or: [markdown, rst]
108132
- id: vale
133+
name: Lint markdown and reStructuredText using Vale
109134
language_version: "1.23.2"
110135
types_or: [markdown, rst]
111136

112137
# Always leave this last to ensure that all hooks have already run
113138
- repo: local
114139
hooks:
115140
- id: git-diff
116-
name: git diff
141+
name: Check if changes were made by the pre-commit hooks
117142
entry: |
118143
bash -c '
119144
if [ "$CI" = "true" ]; then

0 commit comments

Comments
 (0)