2025-09-08 04:35:50 +09:00
|
|
|
# Include-only Dependency Tree (Phase 0)
|
|
|
|
|
|
|
|
|
|
Goal
|
|
|
|
|
- Build a dependency tree using only Ny (no Array/Map), scanning source text for `include "..."`, and output stable JSON.
|
|
|
|
|
|
|
|
|
|
Scope (Phase 0)
|
|
|
|
|
- Only `include` is supported. `using/module/import` are out of scope.
|
|
|
|
|
- Runner bridge: `NYASH_DEPS_JSON=<path>` is read and logged only (no behavior change).
|
|
|
|
|
|
|
|
|
|
Tool
|
2025-11-06 15:41:52 +09:00
|
|
|
- `apps/selfhost/tools/dep_tree_min_string.hako`
|
2025-09-08 04:35:50 +09:00
|
|
|
- Recursively reads source files, scans for `include "path"` outside of strings and comments.
|
|
|
|
|
- Comments: `//` and `#` (line comments) are ignored.
|
|
|
|
|
- Strings: `"..."` with `\"` escapes are honored.
|
|
|
|
|
- Cycles: detected via a simple stack string; when detected, the child appears as a leaf node with empty `includes`/`children`.
|
|
|
|
|
|
|
|
|
|
Output format
|
|
|
|
|
```
|
|
|
|
|
{ "version": 1,
|
|
|
|
|
"root_path": "<entry>",
|
|
|
|
|
"tree": {
|
|
|
|
|
"path": "<file>", "includes": ["..."], "children": [ <node> ]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Acceptance criteria
|
|
|
|
|
- Running `make dep-tree` produces `tmp/deps.json` whose first non-empty line starts with `{` and conforms to the format above.
|
|
|
|
|
- The scanner does not pick includes inside strings or comments.
|
|
|
|
|
- Cycles do not crash or loop; the repeated node is represented as a leaf.
|
|
|
|
|
|
|
|
|
|
Examples
|
2025-11-06 15:41:52 +09:00
|
|
|
- Root: `apps/selfhost/smokes/dep_smoke_root.hako` (includes `dep_smoke_child.hako`)
|
|
|
|
|
- Cycle: `apps/selfhost/smokes/dep_smoke_cycle_a.hako` ↔ `dep_smoke_cycle_b.hako`
|
2025-09-08 04:35:50 +09:00
|
|
|
|
|
|
|
|
Validation (examples)
|
2025-11-06 15:41:52 +09:00
|
|
|
- `echo apps/selfhost/smokes/dep_smoke_root.hako | ./target/release/nyash --backend vm apps/selfhost/tools/dep_tree_min_string.hako`
|
2025-09-08 04:35:50 +09:00
|
|
|
- `make dep-tree`
|
|
|
|
|
|