Repository navigation
feat(dmlfmt): add --device flag (#119) - #7
Merged
Merged
Conversation
Add `--device FILE` and `--follow-all-import` flags to `dmlfmt` to format a device DML file and its transitively imported files while respecting workspace boundaries, and refactor `pkg/fs/lookup` into focused modules. - **Device Mode (`--device FILE`)** - Traverses the device file and transitively resolves imported DML files (`import "...";`), including conditional imports within `#if` / `#else` blocks and implicit builtins (`dml-builtins.dml`). - Supports passing `dmlc` flags after `--` to configure include directories (`-I`, `--include-dir`), while ignoring compiler options (`-D`, `-P`, `--simics-api`, etc.) and rejecting unexpected positional arguments. - Implements import resolution search precedence (`./` relative vs `../` fallback vs `-I` include directories, `<dir>/1.4/<import>` versioned directory before `<dir>/<import>`, device directory, and importing directory). - Enforces workspace boundary containment and filtering (`--include`, `--exclude`, `--extend-exclude`, `--force-exclude`, `.gitignore`, `.ignore`), with symlink escape prevention. - Prevents cycles and duplicate processing on diamond dependencies using canonicalized path tracking. - Adds `--follow-all-import` flag to fail if an imported file cannot be resolved (`EIMPORT`), and enforces semantic rules (`EDEVICE` if root device lacks declaration, `EDEVIMP` if an imported file declares a device). - Streams dynamically discovered imports into the asynchronous `InputJob`/`OutputJob` worker pipeline. - **Refactor `pkg/fs/lookup`** - Decomposes monolithic lookup files into modular components: `boundary.go` (boundary & directory chain resolution), `collect.go` (recursive source collection), `cache_store.go` (thread-safe metadata/directory caching), and `ignore_parser.go` (gitignore pattern parsing & compilation). - Adds `MatchIgnore(path string)` to `lookup.Finder` to evaluate configured ignore files against individual paths. - Reorganizes tests into dedicated test files under `test/fs/lookup/` and internal unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
--device FILEand--follow-all-importflags todmlfmtto format a device DML file and its transitively imported files while respecting workspace boundaries, and refactorpkg/fs/lookupinto focused modules.Device Mode (
--device FILE)import "...";), including conditional imports within#if/#elseblocks and implicit builtins (dml-builtins.dml).dmlcflags after--to configure include directories (-I,--include-dir), while ignoring compiler options (-D,-P,--simics-api, etc.) and rejecting unexpected positional arguments../relative vs../fallback vs-Iinclude directories,<dir>/1.4/<import>versioned directory before<dir>/<import>, device directory, and importing directory).--include,--exclude,--extend-exclude,--force-exclude,.gitignore,.ignore), with symlink escape prevention.--follow-all-importflag to fail if an imported file cannot be resolved (EIMPORT), and enforces semantic rules (EDEVICEif root device lacks declaration,EDEVIMPif an imported file declares a device).InputJob/OutputJobworker pipeline.Refactor
pkg/fs/lookupboundary.go(boundary & directory chain resolution),collect.go(recursive source collection),cache_store.go(thread-safe metadata/directory caching), andignore_parser.go(gitignore pattern parsing & compilation).MatchIgnore(path string)tolookup.Finderto evaluate configured ignore files against individual paths.test/fs/lookup/and internal unit tests.