harbor run -t openthoughts/build-system-task-orderingharbor download openthoughts/build-system-task-orderingCompute a deterministic execution ordering of build tasks from Makefile-style rules and override configurations, handling target aliases, prerequisite resolution, and circular dependency detection.
Implement /app/solution.py with solve(lines: list[str]) -> str.
Blocks start with headers:
TARGET <name> - base target definitionOVERRIDE <name> <id> - override configurationBlock continues until next header or end of input.
Inside blocks:
#) are ignored[Task] are ignoredDepends = t1 t2 ..., Before = ..., After = ..., Needs = ..., Requires = ..., Alias = ..., Phony = yes|noDirectives accumulate (set union), except Phony uses last-one-wins within a block. Whitespace around = is optional.
CRITICAL: Process in this order. Each phase depends on the previous phase's output.
TARGET followed by exactly one target name (2 tokens total)OVERRIDE followed by exactly one target name and one override id (3 tokens total)= characterDepends, Before, After, Needs, Requires, Alias, Phony (case-sensitive)Phony value must be exactly yes or no (case-sensitive)PARSE_ERROR (exact string, no quotes) for any parse errorTARGET and OVERRIDE headers (defined targets)Depends, Before, After, Needs, Requires, Alias (referenced targets)TARGET blocks in appearance order (sequential order in input, regardless of interleaved OVERRIDE blocks)OVERRIDE blocks sorted lexicographically by override idDepends, Before, After, Needs, Requires: union accumulate (add all values, canonicalize each value first)Phony: last-one-wins (overwrites previous value)Phony is unspecified after all blocks, default to "no"Depends = X1 X2 ... → edges: X1 → U, X2 → U, ...Before = Y1 Y2 ... → edges: U → Y1, U → Y2, ...After = Z1 Z2 ... → edges: Z1 → U, Z2 → U, ...Needs = W1 W2 ... → edges: U → W1, U → W2, ...Requires = V1 V2 ... → edges: U → V1, U → V2, ..."order" and "cycles":
"order": array of canonical target names in execution order"cycles": array of cycle arrays (each cycle sorted lexicographically, cycles list sorted lexicographically){"order":[],"cycles":[]}Return exactly PARSE_ERROR (no quotes, case-sensitive) for:
TARGET or OVERRIDE (case-sensitive)TARGET header not having exactly 2 tokensOVERRIDE header not having exactly 3 tokens= characterPhony value not exactly yes or no (case-sensitive, exact match)Input:
TARGET build
Alias = compile link
Depends = all
TARGET compile
Before = clean
Output:
{"order":["all","compile","clean"],"cycles":[]}
All three targets (build, compile, link) canonicalize to compile (lexicographic minimum).
Input:
TARGET test
Phony = yes
Depends = unit
OVERRIDE test 20
Phony = no
After = integration
OVERRIDE test 10
Depends = e2e
Output:
{"order":["unit","e2e","integration","test"],"cycles":[]}
Process TARGET block first, then OVERRIDE blocks sorted by id (10, then 20). Phony is overridden to no.
Input:
TARGET zebra
Alias = alpha
TARGET alpha
Alias = build
TARGET build
Depends = compile
Output:
{"order":["compile","alpha"],"cycles":[]}
All three targets canonicalize to alpha (lexicographic minimum: alpha < build < zebra).
Input:
TARGET a
Depends = b
TARGET b
Depends = c
TARGET c
Depends = a
Output:
{"order":["a","b","c"],"cycles":[["a","b","c"]]}
order and cyclesDepends = ) is valid and represents an empty set.