mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
a6a8fd94d7
`make gen` could not run with `-j` because inter-target dependency edges were missing. Multiple recipes compile `coderd/rbac` (which includes generated files like `object_gen.go`), and without explicit ordering, parallel runs produced syntax errors from mid-write reads. Three main changes: **Dependency graph fixes** declare the compile-time chain through `coderd/rbac` so that `object_gen.go` is written before anything that imports it is compiled. The DB generation targets use a GNU Make 4.3+ grouped target (`&:`) so Make knows `generate.sh` co-produces `querier.go`, `unique_constraint.go`, `dbmetrics`, and `dbauthz` in a single invocation. `SKIP_DUMP_SQL=1` avoids re-entrant `make` inside `generate.sh` when the Makefile already guarantees `dump.sql` is fresh. **`scripts/atomicwrite` package** replaces `os.WriteFile` in all gen scripts with a temp-file-in-same-dir + rename pattern, preventing interrupted runs from leaving partial files. **`.PRECIOUS` and shell atomic writes** protect git-tracked generated files from Make's default delete-on-error behavior. Since these files are committed, deletion is worse than staleness -- `git restore` is the recovery path. CI now runs `make -j --output-sync -B gen` (~32s, down from ~85s serial). | Scenario | Before | After | |-----------------------------------|--------------------|----------| | `make gen` (serial) | 95s | 95s | | `make -j gen` (parallel) | race error | **22s** | | CI `make -j --output-sync -B gen` | forced serial ~85s | **~32s** |
52 lines
970 B
Go
52 lines
970 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/coder/coder/v2/scripts/atomicwrite"
|
|
)
|
|
|
|
func generateIconList(path string) int {
|
|
if path == "" {
|
|
return 0 // skip
|
|
}
|
|
|
|
files, err := os.ReadDir("site/static/icon/")
|
|
if err != nil {
|
|
_, _ = fmt.Println("failed to read site/static/icon/ directory")
|
|
_, _ = fmt.Println("err:", err.Error())
|
|
return 71 // OSERR
|
|
}
|
|
|
|
icons := make([]string, len(files))
|
|
i := 0
|
|
for _, file := range files {
|
|
if !file.Type().IsRegular() {
|
|
continue
|
|
}
|
|
|
|
icons[i] = file.Name()
|
|
i++
|
|
}
|
|
icons = icons[:i]
|
|
|
|
iconsJSON, err := json.Marshal(icons)
|
|
if err != nil {
|
|
_, _ = fmt.Println("failed to serialize JSON")
|
|
_, _ = fmt.Println("err:", err.Error())
|
|
return 70 // SOFTWARE
|
|
}
|
|
|
|
if err := atomicwrite.File(path, iconsJSON); err != nil {
|
|
_, _ = fmt.Println("failed to write JSON")
|
|
_, _ = fmt.Println("err:", err.Error())
|
|
return 74 // IOERR
|
|
}
|
|
|
|
_, _ = fmt.Println(green.Sprintf("==>"), path)
|
|
|
|
return 0
|
|
}
|