The rebuild that leaves a stale dependent
Invalidate every transitive dependent, then rebuild each dirty module once in deterministic dependency order.
What’s going wrong
Original Microsoft-style interview practice. This is not an actual Microsoft interview question. Bugger does not provide an AI assistant.
An incremental build planner works when modules happen to be declared from dependencies to consumers. Reordering the same project can leave a consumer serving a stale artifact. Repair invalidation in planBuild without rebuilding clean dependencies or losing deterministic build order.
Read {"modules":[{"id":"app","dependsOn":["core"]},{"id":"core","dependsOn":[]}],"changed":["core"]}. The graph is directed and acyclic: each module depends on the IDs in dependsOn. Before these edits every module has a valid cached artifact. Every changed module is dirty, and a module is dirty whenever any direct or transitive dependency is dirty. A changed consumer does not by itself dirty its dependencies.
First compute the complete dirty set independent of declaration order. Then repeatedly build the first still-pending dirty module in original declaration order whose dirty dependencies have all rebuilt. Clean dependencies already have valid cached artifacts and need no work. Each dirty module rebuilds exactly once, including shared dependencies in a diamond.
Print {"dirty":[IDs in original declaration order],"build":[IDs in rebuild order]}. Valid input contains at most 100 modules with distinct IDs of 1 to 64 ASCII letters, digits, underscores or hyphens. Every dependency and changed ID is declared; dependency lists have no duplicates. changed may contain duplicates and has at most 100 entries. Empty modules/changed arrays are valid. There are no compile failures, parallel execution, timestamps, filesystem access or network calls.
Expected behavior
Invalidate every transitive dependent, then rebuild each dirty module once in deterministic dependency order.
Reproduction
{"modules":[{"id":"app","dependsOn":["ui"]},{"id":"ui","dependsOn":["core"]},{"id":"core","dependsOn":[]}],"changed":["core"]}{"dirty":["app","ui","core"],"build":["core","ui","app"]}{"modules":[{"id":"core","dependsOn":[]},{"id":"ui","dependsOn":["core"]},{"id":"app","dependsOn":["ui"]}],"changed":["core"]}{"dirty":["core","ui","app"],"build":["core","ui","app"]}{"modules":[{"id":"app","dependsOn":["left","right"]},{"id":"left","dependsOn":["core"]},{"id":"right","dependsOn":["core"]},{"id":"core","dependsOn":[]},{"id":"docs","dependsOn":[]}],"changed":["core"]}{"dirty":["app","left","right","core"],"build":["core","left","right","app"]}Before you begin
- Transitive dependency graphs
- Worklists and set membership
- Stable topological scheduling
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.