// Package shipped collects what Docs ships, for its Colophon (estilo's // colophon package, Help → Colophon). Nothing here is a list written by // hand: each part is read from the build that ships it. // // - Go modules: go list -deps of ./cmd/docs for linux/arm64, the release // build (scripts/build-release.sh), through estilo's credits/catalog. // - JavaScript packages: the input files esbuild reads for the bundles // the app serves (fixtures/bundles.mjs, via fixtures/colophon-inputs.mjs). // - Rust crates: cargo metadata for core/ (the WebAssembly the server // runs) and, for the Apple apps, native/crdt (the WebAssembly they run) // and native/host (the static library that runs it). // - Typefaces: internal/fonts/fonts.json, and estilo's retired Onest, // whose files the server still answers for (app.go). // - Icons: Lucide, the web chrome's interface icons, served as // static/brand/LICENSE.lucide. The Apple apps draw none. // - Swift packages: native/apple/Package.resolved, with each package's // licence vendored under native/notices/ against the pinned revision. // - The Go and Rust standard libraries, which are compiled in. // - Tools: what the build and the tests are run with, as pinned: npm // devDependencies, go.mod requires the server does not link, cargo // dev-dependencies, the pip pins in scripts/, and the toolchains. // A tool's own dependencies are its own. // // TestWebColophonMatchesWhatShips and TestNativeColophonMatchesWhatShips // regenerate all of it and fail if the committed Colophon differs; estilo's // colophon.Build fails if the catalog has no entry for something here, an // entry has no usage note, or a usage note names something not shipped. // Regenerate with `go run ./cmd/docs-colophon`. package shipped import ( "bytes" "context" "crypto/sha256" "encoding/hex" "encoding/json" "errors" "fmt" "html" "os" "os/exec" "path/filepath" "regexp" "sort" "strings" "time" "amadan.net/oficina/estilo.git/colophon" "amadan.net/oficina/estilo.git/credits" "amadan.net/oficina/estilo.git/credits/catalog" ) // FirstParty is Oficina's own modules: the suite's code, not a project it // is made with. Rastrillo is listed, as every Oficina app lists it: it is // its own project with its own licence, and that includes Rastrillo // Native's server half (amadan.net/rastrillo/native/server), which // internal/docs links as nativeauth. var FirstParty = map[string]bool{ "amadan.net/oficina/agent-access.git": true, "amadan.net/oficina/estilo.git": true, "amadan.net/oficina/home/connect": true, "amadan.net/oficina/home/dashboard": true, "amadan.net/oficina/home/handoff": true, "amadan.net/oficina/home/roster": true, "amadan.net/oficina/home/teammode": true, // The suite contract (spec §8.2.2): Oficina's own, like Home's modules. "amadan.net/oficina/suite": true, } // toolchain is a toolchain the build or the checks run, found by its // invocation in the script that runs it: a script that stops running one // fails here until it is taken out. The list is kept by hand, so it is // checked one way only; its scope (AGENTS.md, "The Colophon") is the // open-source language toolchains, package managers, browsers and sandboxes // that build or test what ships, not the shell, git, curl or Apple's // proprietary Xcode tools (xcodebuild, lipo, xcrun). type toolchain struct { name, file, needle string } var ( webToolchains = []toolchain{ {name: "node", file: ".amadan/ci.d/10-gate", needle: "node --test"}, {name: "npm", file: ".amadan/ci.d/10-gate", needle: "npm ci"}, {name: "rustup", file: ".amadan/ci.d/10-gate", needle: "rustup target list"}, {name: "chromium", file: "scripts/browser-drive.sh", needle: `"$chrome" --headless=new`}, {name: "python", file: "scripts/vendor-fonts.py", needle: "#!/usr/bin/env python3"}, {name: "docker", file: "scripts/build-wasm.sh", needle: "docker run"}, {name: "bwrap", file: "scripts/build-wasm.sh", needle: "bwrap --tmpfs"}, } nativeToolchains = []toolchain{ {name: "python", file: "native/scripts/check-native.sh", needle: "python3 native/scripts/sync-fonts.py"}, {name: "npm", file: "native/scripts/check-native.sh", needle: "npm ci"}, {name: "swift", file: "native/scripts/check-native.sh", needle: "swift test"}, {name: "xcodegen", file: "native/scripts/build-iphone.sh", needle: "xcodegen generate"}, } ) // toolchains is each toolchain in list, as a tool, once its invocation is // found. None is pinned, so none has a version or a copied licence. func toolchains(root string, list []toolchain) ([]colophon.Package, error) { var out []colophon.Package for _, tc := range list { raw, err := os.ReadFile(filepath.Join(root, tc.file)) if err != nil { return nil, err } if !strings.Contains(string(raw), tc.needle) { return nil, fmt.Errorf("shipped: %s no longer runs %q; take %s out of the toolchains", tc.file, tc.needle, tc.name) } out = append(out, colophon.Package{Ecosystem: colophon.Toolchain, Name: tc.name, Tool: true, Notices: []credits.Notice{}}) } return out, nil } // WebPath and NativePath are where the generated Colophons are committed, // relative to the repository root. const ( WebPath = "internal/docs/colophon.json" NativePath = "native/apple/Sources/DocsKit/Resources/Colophon.json" ) func run(ctx context.Context, dir string, env []string, name string, args ...string) ([]byte, error) { command := exec.CommandContext(ctx, name, args...) command.Dir = dir if env != nil { command.Env = env } var stderr bytes.Buffer command.Stderr = &stderr out, err := command.Output() if err != nil { return nil, fmt.Errorf("shipped: %s %s: %v\n%s", name, strings.Join(args, " "), err, stderr.String()) } return out, nil } // goEnv is the environment of the release build: linux/arm64, no cgo, no // workspace. func goEnv() []string { var env []string for _, e := range os.Environ() { if !strings.HasPrefix(e, "GOOS=") && !strings.HasPrefix(e, "GOARCH=") && !strings.HasPrefix(e, "CGO_ENABLED=") && !strings.HasPrefix(e, "GOWORK=") && !strings.HasPrefix(e, "GOFLAGS=") { env = append(env, e) } } return append(env, "GOOS=linux", "GOARCH=arm64", "CGO_ENABLED=0", "GOWORK=off", "GOFLAGS=-mod=readonly") } func notice(name, path string) ([]credits.Notice, error) { raw, err := os.ReadFile(path) if err != nil { return nil, err } if strings.TrimSpace(string(raw)) == "" { return nil, fmt.Errorf("shipped: %s is empty", path) } return []credits.Notice{{Name: name, Text: string(raw)}}, nil } // Web is everything the Docs server ships, and the tools it is built and // tested with. func Web(root string) ([]colophon.Package, error) { root, err := filepath.Abs(root) if err != nil { return nil, err } ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) defer cancel() var out []colophon.Package add := func(p []colophon.Package, err error) error { out = append(out, p...) return err } production, err := goModules(ctx, root) if err != nil { return nil, err } for _, step := range []func() error{ func() error { return add(production, nil) }, func() error { return add(goToolchain(ctx, root)) }, func() error { return add(npmBundles(ctx, root)) }, func() error { return add(cargo(ctx, filepath.Join(root, "core", "Cargo.toml"), "wasm32-unknown-unknown", true)) }, func() error { return add(rustToolchain(ctx, root)) }, func() error { return add(typefaces(root, filepath.Join(root, "internal", "fonts", "files"))) }, func() error { o := credits.Onest() out = append(out, colophon.Package{Ecosystem: colophon.Font, Name: o.Name, Version: o.Version, Notices: o.Notices}) return nil }, func() error { return add(lucide(filepath.Join(root, "internal", "docs", "brand", "LICENSE.lucide"))) }, func() error { return add(npmTools(root, "fixtures"), nil) }, func() error { return add(npmTools(root, filepath.Join("fixtures", "engines")), nil) }, func() error { return add(goTools(ctx, root, production)) }, func() error { return add(pipTools(root)) }, func() error { return add(toolchains(root, webToolchains)) }, } { if err := step(); err != nil { return nil, err } } return out, nil } // Native is everything the Mac and iPhone apps ship. Sparkle is the Mac's // alone. func Native(root string) ([]colophon.Package, error) { root, err := filepath.Abs(root) if err != nil { return nil, err } ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) defer cancel() var out []colophon.Package crdt, err := cargo(ctx, filepath.Join(root, "native", "crdt", "Cargo.toml"), "wasm32-unknown-unknown", false) if err != nil { return nil, err } out = append(out, crdt...) // The host library is built per Apple target; each graph's crates are // marked with the platform it is for, and Build joins them, so a crate // on one target alone would show in that app alone. The crdt // WebAssembly runs on both, unmarked. for _, target := range []struct{ triple, platform string }{ {"aarch64-apple-darwin", "mac"}, {"x86_64-apple-darwin", "mac"}, {"aarch64-apple-ios", "ios"}, {"aarch64-apple-ios-sim", "ios"}, {"x86_64-apple-ios", "ios"}, } { host, err := cargo(ctx, filepath.Join(root, "native", "host", "Cargo.toml"), target.triple, false) if err != nil { return nil, err } for i := range host { host[i].Platforms = []string{target.platform} } out = append(out, host...) } rust, err := rustToolchain(ctx, root) if err != nil { return nil, err } for i := range rust { rust[i].Tool = false } out = append(out, rust...) fontPackages, err := typefaces(root, filepath.Join(root, "native", "apple", "Sources", "DocsKit", "Fonts")) if err != nil { return nil, err } out = append(out, fontPackages...) // No Lucide: nothing in the apps draws a Lucide icon (their icons are // Oficina's own and the system's symbols), so they carry no notice. swift, err := swiftPackages(root) if err != nil { return nil, err } out = append(out, swift...) entities, err := notice("NOTICE", filepath.Join(root, "native", "notices", "html-entities", "NOTICE")) if err != nil { return nil, err } out = append(out, colophon.Package{Ecosystem: colophon.Asset, Name: "html-entities", Notices: entities}) tools, err := toolchains(root, nativeToolchains) return append(out, tools...), err } func goModules(ctx context.Context, root string) ([]colophon.Package, error) { raw, err := run(ctx, root, goEnv(), "go", "list", "-buildvcs=false", "-deps", "-json", "./cmd/docs") if err != nil { return nil, err } inventory, err := catalog.Collect(bytes.NewReader(raw), FirstParty) if err != nil { return nil, err } return colophon.FromComponents(colophon.Go, inventory.Components), nil } var goDirective = regexp.MustCompile(`(?m)^go (\d+\.\d+(\.\d+)?)$`) // goToolchain is Go's standard library, which is compiled into the // server. The version is go.mod's, which the release build is held to. func goToolchain(ctx context.Context, root string) ([]colophon.Package, error) { mod, err := os.ReadFile(filepath.Join(root, "go.mod")) if err != nil { return nil, err } m := goDirective.FindSubmatch(mod) if m == nil { return nil, errors.New("shipped: go.mod has no go directive") } goroot, err := run(ctx, root, goEnv(), "go", "env", "GOROOT") if err != nil { return nil, err } text, err := notice("LICENSE", filepath.Join(strings.TrimSpace(string(goroot)), "LICENSE")) if err != nil { return nil, err } return []colophon.Package{{Ecosystem: colophon.Toolchain, Name: "go", Version: "go" + string(m[1]), Notices: text}}, nil } func npmBundles(ctx context.Context, root string) ([]colophon.Package, error) { fixtures := filepath.Join(root, "fixtures") if _, err := os.Stat(filepath.Join(fixtures, "node_modules")); err != nil { return nil, errors.New("shipped: fixtures/node_modules is missing; run `npm ci` in fixtures (10-gate does)") } raw, err := run(ctx, fixtures, nil, "node", "colophon-inputs.mjs") if err != nil { return nil, err } var inputs []string if err := json.Unmarshal(raw, &inputs); err != nil { return nil, err } return colophon.CollectNPM(fixtures, inputs) } // cargo is one manifest's crates for target: what the build links, and, // with tools, its direct dev-dependencies as tools. func cargo(ctx context.Context, manifest, target string, tools bool) ([]colophon.Package, error) { raw, err := run(ctx, filepath.Dir(manifest), nil, "cargo", "metadata", "--locked", "--format-version", "1", "--filter-platform", target, "--manifest-path", manifest) if err != nil { return nil, err } out, err := colophon.CollectCargo(bytes.NewReader(raw)) if err != nil { return nil, err } if tools { dev, err := colophon.CollectCargoTools(bytes.NewReader(raw)) if err != nil { return nil, err } out = append(out, dev...) } return upstreamNotices(filepath.Join(filepath.Dir(manifest), ".."), out) } // upstreamNotices gives a crate published without its licence file the // files its repository has, vendored at native/notices/crates/