Devicetree DTS and YAML format improvements #492
Devicetree DTS and YAML format improvements #492KenVanHoeylandt wants to merge 21 commits intomainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughIntroduces a new 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
Buildscripts/DevicetreeCompiler/source/transformer.py (1)
5-7: Consider explicit imports fromsource.modelsinstead of star import.The static analysis tool flags
DeviceProperty(line 51) as potentially undefined due to the wildcard import on line 5. An explicit import would silence this and improve readability.-from source.models import * +from source.models import DtsVersion, Device, DeviceProperty, PropertyValue, IncludeC, DefineCBuildscripts/DevicetreeCompiler/source/generator.py (2)
62-77:"int"and"value"branches are identical — consider consolidating.Both
type == "value"(line 64) andtype == "int"(line 66) returnproperty.valueunchanged. If the semantic distinction isn't needed elsewhere, they could share a branch to reduce duplication.Proposed consolidation
- if type == "value": - return property.value - elif type == "int": + if type in ("value", "int"): return property.value
103-120: Non-required property without a default raises an error — is this intentional?Line 118 raises
DevicetreeExceptionfor a non-required property that has no default. This effectively means every binding property must either berequired, have adefault, or be of type"bool". If a property is truly optional with no sensible default (e.g., an optional label), the current logic provides no way to omit it — the pre-allocatedresultarray (line 102) assumes every binding property maps to a config struct field.If this is by design (binding authors must always specify defaults for optional properties), a brief comment documenting this invariant would help future maintainers.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Buildscripts/DevicetreeCompiler/source/generator.py (1)
62-75:⚠️ Potential issue | 🔴 Critical
",".join(property.value)will raiseTypeErrorwhen a phandle appears in a values property.The grammar allows
values: VALUE+, where each VALUE can be a NUMBER, PHANDLE, or C_VARIABLE. The PHANDLE handler returns aPropertyValueobject while others return strings. When a values property contains a phandle (e.g.,< &device_alias 10 >), the resultingproperty.valueis a list mixingPropertyValueobjects and strings. SincePropertyValuehas no__str__method, calling",".join(property.value)will fail withTypeError: expected str instance, PropertyValue found. The code should extract string representations of all elements before joining, such as",".join(item.value if isinstance(item, PropertyValue) else str(item) for item in property.value).
🧹 Nitpick comments (1)
Buildscripts/DevicetreeCompiler/source/main.py (1)
51-53: Bareexcept DevicetreeExceptionwon't catch other failure modes.Only
DevicetreeExceptionis caught here, but the code inside thetryblock can also raiseFileNotFoundError(fromread_file),lark.exceptions.LarkError(from parsing),OSError, etc. These will still produce unhandled tracebacks. Consider adding a broader fallbackexcept Exceptionto print a clean error for unexpected failures too.Proposed fix
except DevicetreeException as caught: print("\033[31mError: ", caught, "\033[0m") return 1 + except Exception as caught: + print("\033[31mUnexpected error: ", caught, "\033[0m") + return 1
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
.github/workflows/tests.yml (1)
37-39: Consider pinning dependency versions for reproducible CI builds.Unpinned
pip install lark pyyamlcan break CI silently when a new major version ships an incompatible change.Proposed fix
- run: pip install lark pyyaml + run: pip install lark==1.2.2 pyyaml==6.0.2Adjust versions to match what the project currently uses.
Buildscripts/DevicetreeCompiler/tests/test_integration.py (1)
14-21: Add atimeouttosubprocess.runto prevent tests from hanging indefinitely.If the compiler enters an infinite loop or hangs on malformed input, this test will block the CI pipeline forever.
Proposed fix
def run_compiler(config_path, output_path): result = subprocess.run( [sys.executable, COMPILE_SCRIPT, config_path, output_path], capture_output=True, text=True, - cwd=PROJECT_ROOT + cwd=PROJECT_ROOT, + timeout=60 ) return result
Summary by CodeRabbit
New Features
Improvements
Changes
Tests
Documentation