oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1// Package shipped collects what Docs ships, for its Colophon (estilo's
2// colophon package, Help → Colophon). Nothing here is a list written by
3// hand: each part is read from the build that ships it.
4//
5// - Go modules: go list -deps of ./cmd/docs for linux/arm64, the release
6// build (scripts/build-release.sh), through estilo's credits/catalog.
7// - JavaScript packages: the input files esbuild reads for the bundles
8// the app serves (fixtures/bundles.mjs, via fixtures/colophon-inputs.mjs).
9// - Rust crates: cargo metadata for core/ (the WebAssembly the server
10// runs) and, for the Apple apps, native/crdt (the WebAssembly they run)
11// and native/host (the static library that runs it).
12// - Typefaces: internal/fonts/fonts.json, and estilo's retired Onest,
13// whose files the server still answers for (app.go).
14// - Icons: Lucide, the web chrome's interface icons, served as
15// static/brand/LICENSE.lucide. The Apple apps draw none.
16// - Swift packages: native/apple/Package.resolved, with each package's
17// licence vendored under native/notices/ against the pinned revision.
18// - The Go and Rust standard libraries, which are compiled in.
19// - Tools: what the build and the tests are run with, as pinned: npm
20// devDependencies, go.mod requires the server does not link, cargo
21// dev-dependencies, the pip pins in scripts/, and the toolchains.
22// A tool's own dependencies are its own.
23//
24// TestWebColophonMatchesWhatShips and TestNativeColophonMatchesWhatShips
25// regenerate all of it and fail if the committed Colophon differs; estilo's
26// colophon.Build fails if the catalog has no entry for something here, an
27// entry has no usage note, or a usage note names something not shipped.
28// Regenerate with `go run ./cmd/docs-colophon`.
29package shipped
30
31import (
32 "bytes"
33 "context"
34 "crypto/sha256"
35 "encoding/hex"
36 "encoding/json"
37 "errors"
38 "fmt"
39 "html"
40 "os"
41 "os/exec"
42 "path/filepath"
43 "regexp"
44 "sort"
45 "strings"
46 "time"
47
48 "amadan.net/oficina/estilo.git/colophon"
49 "amadan.net/oficina/estilo.git/credits"
50 "amadan.net/oficina/estilo.git/credits/catalog"
51)
52
53// FirstParty is Oficina's own modules: the suite's code, not a project it
54// is made with. Rastrillo is listed, as every Oficina app lists it: it is
55// its own project with its own licence, and that includes Rastrillo
56// Native's server half (amadan.net/rastrillo/native/server), which
57// internal/docs links as nativeauth.
58var FirstParty = map[string]bool{
59 "amadan.net/oficina/agent-access.git": true,
60 "amadan.net/oficina/estilo.git": true,
61 "amadan.net/oficina/home/connect": true,
62 "amadan.net/oficina/home/dashboard": true,
63 "amadan.net/oficina/home/handoff": true,
64 "amadan.net/oficina/home/roster": true,
65 "amadan.net/oficina/home/teammode": true,
66 // The suite contract (spec §8.2.2): Oficina's own, like Home's modules.
67 "amadan.net/oficina/suite": true,
68}
69
70// toolchain is a toolchain the build or the checks run, found by its
71// invocation in the script that runs it: a script that stops running one
72// fails here until it is taken out. The list is kept by hand, so it is
73// checked one way only; its scope (AGENTS.md, "The Colophon") is the
74// open-source language toolchains, package managers, browsers and sandboxes
75// that build or test what ships, not the shell, git, curl or Apple's
76// proprietary Xcode tools (xcodebuild, lipo, xcrun).
77type toolchain struct {
78 name, file, needle string
79}
80
81var (
82 webToolchains = []toolchain{
83 {name: "node", file: ".amadan/ci.d/10-gate", needle: "node --test"},
84 {name: "npm", file: ".amadan/ci.d/10-gate", needle: "npm ci"},
85 {name: "rustup", file: ".amadan/ci.d/10-gate", needle: "rustup target list"},
86 {name: "chromium", file: "scripts/browser-drive.sh", needle: `"$chrome" --headless=new`},
87 {name: "python", file: "scripts/vendor-fonts.py", needle: "#!/usr/bin/env python3"},
88 {name: "docker", file: "scripts/build-wasm.sh", needle: "docker run"},
89 {name: "bwrap", file: "scripts/build-wasm.sh", needle: "bwrap --tmpfs"},
90 }
91 nativeToolchains = []toolchain{
92 {name: "python", file: "native/scripts/check-native.sh", needle: "python3 native/scripts/sync-fonts.py"},
93 {name: "npm", file: "native/scripts/check-native.sh", needle: "npm ci"},
94 {name: "swift", file: "native/scripts/check-native.sh", needle: "swift test"},
95 {name: "xcodegen", file: "native/scripts/build-iphone.sh", needle: "xcodegen generate"},
96 }
97)
98
99// toolchains is each toolchain in list, as a tool, once its invocation is
100// found. None is pinned, so none has a version or a copied licence.
101func toolchains(root string, list []toolchain) ([]colophon.Package, error) {
102 var out []colophon.Package
103 for _, tc := range list {
104 raw, err := os.ReadFile(filepath.Join(root, tc.file))
105 if err != nil {
106 return nil, err
107 }
108 if !strings.Contains(string(raw), tc.needle) {
109 return nil, fmt.Errorf("shipped: %s no longer runs %q; take %s out of the toolchains", tc.file, tc.needle, tc.name)
110 }
111 out = append(out, colophon.Package{Ecosystem: colophon.Toolchain, Name: tc.name, Tool: true, Notices: []credits.Notice{}})
112 }
113 return out, nil
114}
115
116// WebPath and NativePath are where the generated Colophons are committed,
117// relative to the repository root.
118const (
119 WebPath = "internal/docs/colophon.json"
120 NativePath = "native/apple/Sources/DocsKit/Resources/Colophon.json"
121)
122
123func run(ctx context.Context, dir string, env []string, name string, args ...string) ([]byte, error) {
124 command := exec.CommandContext(ctx, name, args...)
125 command.Dir = dir
126 if env != nil {
127 command.Env = env
128 }
129 var stderr bytes.Buffer
130 command.Stderr = &stderr
131 out, err := command.Output()
132 if err != nil {
133 return nil, fmt.Errorf("shipped: %s %s: %v\n%s", name, strings.Join(args, " "), err, stderr.String())
134 }
135 return out, nil
136}
137
138// goEnv is the environment of the release build: linux/arm64, no cgo, no
139// workspace.
140func goEnv() []string {
141 var env []string
142 for _, e := range os.Environ() {
143 if !strings.HasPrefix(e, "GOOS=") && !strings.HasPrefix(e, "GOARCH=") && !strings.HasPrefix(e, "CGO_ENABLED=") && !strings.HasPrefix(e, "GOWORK=") && !strings.HasPrefix(e, "GOFLAGS=") {
144 env = append(env, e)
145 }
146 }
147 return append(env, "GOOS=linux", "GOARCH=arm64", "CGO_ENABLED=0", "GOWORK=off", "GOFLAGS=-mod=readonly")
148}
149
150func notice(name, path string) ([]credits.Notice, error) {
151 raw, err := os.ReadFile(path)
152 if err != nil {
153 return nil, err
154 }
155 if strings.TrimSpace(string(raw)) == "" {
156 return nil, fmt.Errorf("shipped: %s is empty", path)
157 }
158 return []credits.Notice{{Name: name, Text: string(raw)}}, nil
159}
160
161// Web is everything the Docs server ships, and the tools it is built and
162// tested with.
163func Web(root string) ([]colophon.Package, error) {
164 root, err := filepath.Abs(root)
165 if err != nil {
166 return nil, err
167 }
168 ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute)
169 defer cancel()
170 var out []colophon.Package
171 add := func(p []colophon.Package, err error) error {
172 out = append(out, p...)
173 return err
174 }
175 production, err := goModules(ctx, root)
176 if err != nil {
177 return nil, err
178 }
179 for _, step := range []func() error{
180 func() error { return add(production, nil) },
181 func() error { return add(goToolchain(ctx, root)) },
182 func() error { return add(npmBundles(ctx, root)) },
183 func() error {
184 return add(cargo(ctx, filepath.Join(root, "core", "Cargo.toml"), "wasm32-unknown-unknown", true))
185 },
186 func() error { return add(rustToolchain(ctx, root)) },
187 func() error { return add(typefaces(root, filepath.Join(root, "internal", "fonts", "files"))) },
188 func() error {
189 o := credits.Onest()
190 out = append(out, colophon.Package{Ecosystem: colophon.Font, Name: o.Name, Version: o.Version, Notices: o.Notices})
191 return nil
192 },
193 func() error {
194 return add(lucide(filepath.Join(root, "internal", "docs", "brand", "LICENSE.lucide")))
195 },
196 func() error { return add(npmTools(root, "fixtures"), nil) },
197 func() error { return add(npmTools(root, filepath.Join("fixtures", "engines")), nil) },
198 func() error { return add(goTools(ctx, root, production)) },
199 func() error { return add(pipTools(root)) },
200 func() error { return add(toolchains(root, webToolchains)) },
201 } {
202 if err := step(); err != nil {
203 return nil, err
204 }
205 }
206 return out, nil
207}
208
209// Native is everything the Mac and iPhone apps ship. Sparkle is the Mac's
210// alone.
211func Native(root string) ([]colophon.Package, error) {
212 root, err := filepath.Abs(root)
213 if err != nil {
214 return nil, err
215 }
216 ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute)
217 defer cancel()
218 var out []colophon.Package
219 crdt, err := cargo(ctx, filepath.Join(root, "native", "crdt", "Cargo.toml"), "wasm32-unknown-unknown", false)
220 if err != nil {
221 return nil, err
222 }
223 out = append(out, crdt...)
224 // The host library is built per Apple target; each graph's crates are
225 // marked with the platform it is for, and Build joins them, so a crate
226 // on one target alone would show in that app alone. The crdt
227 // WebAssembly runs on both, unmarked.
228 for _, target := range []struct{ triple, platform string }{
229 {"aarch64-apple-darwin", "mac"}, {"x86_64-apple-darwin", "mac"},
230 {"aarch64-apple-ios", "ios"}, {"aarch64-apple-ios-sim", "ios"}, {"x86_64-apple-ios", "ios"},
231 } {
232 host, err := cargo(ctx, filepath.Join(root, "native", "host", "Cargo.toml"), target.triple, false)
233 if err != nil {
234 return nil, err
235 }
236 for i := range host {
237 host[i].Platforms = []string{target.platform}
238 }
239 out = append(out, host...)
240 }
241 rust, err := rustToolchain(ctx, root)
242 if err != nil {
243 return nil, err
244 }
245 for i := range rust {
246 rust[i].Tool = false
247 }
248 out = append(out, rust...)
249 fontPackages, err := typefaces(root, filepath.Join(root, "native", "apple", "Sources", "DocsKit", "Fonts"))
250 if err != nil {
251 return nil, err
252 }
253 out = append(out, fontPackages...)
254 // No Lucide: nothing in the apps draws a Lucide icon (their icons are
255 // Oficina's own and the system's symbols), so they carry no notice.
256 swift, err := swiftPackages(root)
257 if err != nil {
258 return nil, err
259 }
260 out = append(out, swift...)
261 entities, err := notice("NOTICE", filepath.Join(root, "native", "notices", "html-entities", "NOTICE"))
262 if err != nil {
263 return nil, err
264 }
265 out = append(out, colophon.Package{Ecosystem: colophon.Asset, Name: "html-entities", Notices: entities})
266 tools, err := toolchains(root, nativeToolchains)
267 return append(out, tools...), err
268}
269
270func goModules(ctx context.Context, root string) ([]colophon.Package, error) {
271 raw, err := run(ctx, root, goEnv(), "go", "list", "-buildvcs=false", "-deps", "-json", "./cmd/docs")
272 if err != nil {
273 return nil, err
274 }
275 inventory, err := catalog.Collect(bytes.NewReader(raw), FirstParty)
276 if err != nil {
277 return nil, err
278 }
279 return colophon.FromComponents(colophon.Go, inventory.Components), nil
280}
281
282var goDirective = regexp.MustCompile(`(?m)^go (\d+\.\d+(\.\d+)?)$`)
283
284// goToolchain is Go's standard library, which is compiled into the
285// server. The version is go.mod's, which the release build is held to.
286func goToolchain(ctx context.Context, root string) ([]colophon.Package, error) {
287 mod, err := os.ReadFile(filepath.Join(root, "go.mod"))
288 if err != nil {
289 return nil, err
290 }
291 m := goDirective.FindSubmatch(mod)
292 if m == nil {
293 return nil, errors.New("shipped: go.mod has no go directive")
294 }
295 goroot, err := run(ctx, root, goEnv(), "go", "env", "GOROOT")
296 if err != nil {
297 return nil, err
298 }
299 text, err := notice("LICENSE", filepath.Join(strings.TrimSpace(string(goroot)), "LICENSE"))
300 if err != nil {
301 return nil, err
302 }
303 return []colophon.Package{{Ecosystem: colophon.Toolchain, Name: "go", Version: "go" + string(m[1]), Notices: text}}, nil
304}
305
306func npmBundles(ctx context.Context, root string) ([]colophon.Package, error) {
307 fixtures := filepath.Join(root, "fixtures")
308 if _, err := os.Stat(filepath.Join(fixtures, "node_modules")); err != nil {
309 return nil, errors.New("shipped: fixtures/node_modules is missing; run `npm ci` in fixtures (10-gate does)")
310 }
311 raw, err := run(ctx, fixtures, nil, "node", "colophon-inputs.mjs")
312 if err != nil {
313 return nil, err
314 }
315 var inputs []string
316 if err := json.Unmarshal(raw, &inputs); err != nil {
317 return nil, err
318 }
319 return colophon.CollectNPM(fixtures, inputs)
320}
321
322// cargo is one manifest's crates for target: what the build links, and,
323// with tools, its direct dev-dependencies as tools.
324func cargo(ctx context.Context, manifest, target string, tools bool) ([]colophon.Package, error) {
325 raw, err := run(ctx, filepath.Dir(manifest), nil, "cargo", "metadata", "--locked", "--format-version", "1", "--filter-platform", target, "--manifest-path", manifest)
326 if err != nil {
327 return nil, err
328 }
329 out, err := colophon.CollectCargo(bytes.NewReader(raw))
330 if err != nil {
331 return nil, err
332 }
333 if tools {
334 dev, err := colophon.CollectCargoTools(bytes.NewReader(raw))
335 if err != nil {
336 return nil, err
337 }
338 out = append(out, dev...)
339 }
340 return upstreamNotices(filepath.Join(filepath.Dir(manifest), ".."), out)
341}
342
343// upstreamNotices gives a crate published without its licence file the
344// files its repository has, vendored at native/notices/crates/<dir>/ with
345// a provenance.json naming the crates and exact versions they are for and
346// each file's sha256. root is any directory under the repository.
347func upstreamNotices(root string, packages []colophon.Package) ([]colophon.Package, error) {
348 for !exists(filepath.Join(root, "go.mod")) {
349 parent := filepath.Dir(root)
350 if parent == root {
351 return nil, errors.New("shipped: no repository root above the manifest")
352 }
353 root = parent
354 }
355 dirs, err := filepath.Glob(filepath.Join(root, "native", "notices", "crates", "*", "provenance.json"))
356 if err != nil {
357 return nil, err
358 }
359 for _, path := range dirs {
360 raw, err := os.ReadFile(path)
361 if err != nil {
362 return nil, err
363 }
364 var p struct {
365 Crates map[string]string
366 Sha256 map[string]string
367 }
368 if err := json.Unmarshal(raw, &p); err != nil {
369 return nil, err
370 }
371 notices, err := colophon.DirNotices(filepath.Dir(path))
372 if err != nil {
373 return nil, err
374 }
375 if len(notices) != len(p.Sha256) {
376 return nil, fmt.Errorf("shipped: %s names %d files but its directory holds %d", path, len(p.Sha256), len(notices))
377 }
378 for _, n := range notices {
379 if sum := sha256.Sum256([]byte(n.Text)); hex.EncodeToString(sum[:]) != p.Sha256[n.Name] {
380 return nil, fmt.Errorf("shipped: %s is not the file %s recorded", n.Name, path)
381 }
382 }
383 for i, pkg := range packages {
384 if version, ok := p.Crates[pkg.Name]; ok && version == pkg.Version && len(pkg.Notices) == 0 {
385 packages[i].Notices = notices
386 }
387 }
388 }
389 return packages, nil
390}
391
392func exists(path string) bool {
393 _, err := os.Stat(path)
394 return err == nil
395}
396
397var channel = regexp.MustCompile(`(?m)^channel\s*=\s*"([0-9.]+)"`)
398
399// rustToolchain is Rust's standard library, compiled into the
400// WebAssembly, at rust-toolchain.toml's version. Its notice is the
401// toolchain's own COPYRIGHT-library.html, as text.
402func rustToolchain(ctx context.Context, root string) ([]colophon.Package, error) {
403 pin, err := os.ReadFile(filepath.Join(root, "rust-toolchain.toml"))
404 if err != nil {
405 return nil, err
406 }
407 m := channel.FindSubmatch(pin)
408 if m == nil {
409 return nil, errors.New("shipped: rust-toolchain.toml pins no channel")
410 }
411 version, err := run(ctx, root, nil, "rustc", "--version")
412 if err != nil {
413 return nil, err
414 }
415 if !strings.HasPrefix(string(version), "rustc "+string(m[1])+" ") {
416 return nil, fmt.Errorf("shipped: rustc is %q, not rust-toolchain.toml's %s (put rustup's cargo first on PATH: . ~/.cargo/env)", strings.TrimSpace(string(version)), m[1])
417 }
418 sysroot, err := run(ctx, root, nil, "rustc", "--print", "sysroot")
419 if err != nil {
420 return nil, err
421 }
422 raw, err := os.ReadFile(filepath.Join(strings.TrimSpace(string(sysroot)), "share", "doc", "rust", "COPYRIGHT-library.html"))
423 if err != nil {
424 return nil, err
425 }
426 return []colophon.Package{{Ecosystem: colophon.Toolchain, Name: "rust", Version: string(m[1]), Notices: []credits.Notice{{Name: "COPYRIGHT-library.html, as text", Text: htmlText(string(raw))}}}}, nil
427}
428
429var (
430 blockTag = regexp.MustCompile(`(?i)<(/?(p|h[1-6]|li|pre|br|div|tr|ul|ol|table)\b[^>]*)>`)
431 anyTag = regexp.MustCompile(`<[^>]*>`)
432 blanks = regexp.MustCompile(`\n{3,}`)
433)
434
435// htmlText is an HTML notice as plain text: block elements become line
436// breaks, other tags go, and entities are decoded.
437func htmlText(s string) string {
438 s = blockTag.ReplaceAllString(s, "\n")
439 s = anyTag.ReplaceAllString(s, "")
440 s = html.UnescapeString(s)
441 var lines []string
442 for _, line := range strings.Split(s, "\n") {
443 lines = append(lines, strings.TrimRight(line, " \t\r"))
444 }
445 return strings.TrimSpace(blanks.ReplaceAllString(strings.Join(lines, "\n"), "\n\n")) + "\n"
446}
447
448type manifest struct {
449 Families []struct {
450 Name string `json:"name"`
451 Dir string `json:"dir"`
452 Licence string `json:"licence"`
453 } `json:"families"`
454}
455
456// typefaces is every family in internal/fonts/fonts.json, with its licence
457// read from files (internal/fonts/files for the server, the DocsKit copy
458// for the Apple apps; sync-fonts.py holds the two identical).
459func typefaces(root, files string) ([]colophon.Package, error) {
460 raw, err := os.ReadFile(filepath.Join(root, "internal", "fonts", "fonts.json"))
461 if err != nil {
462 return nil, err
463 }
464 var m manifest
465 if err := json.Unmarshal(raw, &m); err != nil {
466 return nil, err
467 }
468 var out []colophon.Package
469 for _, f := range m.Families {
470 text, err := notice(f.Licence, filepath.Join(files, f.Dir, f.Licence))
471 if err != nil {
472 return nil, err
473 }
474 out = append(out, colophon.Package{Ecosystem: colophon.Font, Name: f.Name, Notices: text})
475 }
476 if len(out) == 0 {
477 return nil, errors.New("shipped: fonts.json lists no families")
478 }
479 return out, nil
480}
481
482// lucide is the icons' licence as this build carries it; it must be the
483// same text estilo attributes.
484func lucide(path string) ([]colophon.Package, error) {
485 text, err := notice("LICENSE", path)
486 if err != nil {
487 return nil, err
488 }
489 if text[0].Text != credits.Lucide().Notices[0].Text {
490 return nil, fmt.Errorf("shipped: %s is not estilo's Lucide licence", path)
491 }
492 return []colophon.Package{{Ecosystem: colophon.Asset, Name: "lucide", Notices: text}}, nil
493}
494
495func npmTools(root, dir string) []colophon.Package {
496 raw, err := os.ReadFile(filepath.Join(root, dir, "package.json"))
497 if err != nil {
498 return nil
499 }
500 var p struct {
501 DevDependencies map[string]string `json:"devDependencies"`
502 }
503 if json.Unmarshal(raw, &p) != nil {
504 return nil
505 }
506 var out []colophon.Package
507 for name, version := range p.DevDependencies {
508 pkg := colophon.Package{Ecosystem: colophon.NPM, Name: name, Version: version, Tool: true, Notices: []credits.Notice{}}
509 // The licence is copied when the package is installed; 10-gate
510 // installs fixtures/ but not fixtures/engines/, so read neither:
511 // a tool's text is optional, and the Colophon must not depend on
512 // which of them happen to be installed.
513 out = append(out, pkg)
514 }
515 sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
516 return out
517}
518
519var require = regexp.MustCompile(`(?m)^\s*(?:require\s+)?([a-z0-9.\-]+\.[a-z]+/[^\s]+)\s+(v[^\s]+)(\s*//.*)?$`)
520
521// goTools is go.mod's direct requires that the server does not link: the
522// test tooling (chromedp, which drives the browser checks).
523func goTools(ctx context.Context, root string, production []colophon.Package) ([]colophon.Package, error) {
524 mod, err := os.ReadFile(filepath.Join(root, "go.mod"))
525 if err != nil {
526 return nil, err
527 }
528 linked := map[string]bool{}
529 for _, p := range production {
530 linked[p.Name] = true
531 }
532 var out []colophon.Package
533 for _, m := range require.FindAllStringSubmatch(string(mod), -1) {
534 if strings.Contains(m[3], "indirect") || linked[m[1]] || FirstParty[m[1]] {
535 continue
536 }
537 out = append(out, colophon.Package{Ecosystem: colophon.Go, Name: m[1], Version: m[2], Tool: true, Notices: []credits.Notice{}})
538 }
539 sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
540 return out, nil
541}
542
543var pipPin = regexp.MustCompile(`pip install ((?:[A-Za-z0-9_.\-]+==[0-9A-Za-z.]+\s*)+)`)
544
545// pipTools is the Python packages scripts/ say to install, pinned: the
546// font vendoring and the shaping goldens.
547func pipTools(root string) ([]colophon.Package, error) {
548 scripts, err := filepath.Glob(filepath.Join(root, "scripts", "*.py"))
549 if err != nil {
550 return nil, err
551 }
552 seen := map[string]bool{}
553 var out []colophon.Package
554 for _, path := range scripts {
555 raw, err := os.ReadFile(path)
556 if err != nil {
557 return nil, err
558 }
559 for _, m := range pipPin.FindAllStringSubmatch(string(raw), -1) {
560 for _, pin := range strings.Fields(m[1]) {
561 name, version, _ := strings.Cut(pin, "==")
562 name = strings.ToLower(name)
563 if seen[name+version] {
564 continue
565 }
566 seen[name+version] = true
567 out = append(out, colophon.Package{Ecosystem: colophon.Pip, Name: name, Version: version, Tool: true, Notices: []credits.Notice{}})
568 }
569 }
570 }
571 sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
572 return out, nil
573}
574
575// swiftPackages is Package.resolved's pins. Each one's licence is vendored
576// at native/notices/<identity>/ with a provenance.json naming the revision
577// it was copied from, which must be the pinned one.
578func swiftPackages(root string) ([]colophon.Package, error) {
579 raw, err := os.ReadFile(filepath.Join(root, "native", "apple", "Package.resolved"))
580 if err != nil {
581 return nil, err
582 }
583 var resolved struct {
584 Pins []struct {
585 Identity string `json:"identity"`
586 Location string `json:"location"`
587 State struct {
588 Revision string `json:"revision"`
589 Version string `json:"version"`
590 } `json:"state"`
591 } `json:"pins"`
592 }
593 if err := json.Unmarshal(raw, &resolved); err != nil {
594 return nil, err
595 }
596 var out []colophon.Package
597 for _, pin := range resolved.Pins {
598 dir := filepath.Join(root, "native", "notices", pin.Identity)
599 prov, err := os.ReadFile(filepath.Join(dir, "provenance.json"))
600 if err != nil {
601 return nil, fmt.Errorf("shipped: Swift package %s has no vendored licence at native/notices/%s: %w", pin.Identity, pin.Identity, err)
602 }
603 var p struct {
604 Location, Revision string
605 Platforms []string
606 }
607 if err := json.Unmarshal(prov, &p); err != nil {
608 return nil, err
609 }
610 if p.Revision != pin.State.Revision || p.Location != pin.Location {
611 return nil, fmt.Errorf("shipped: native/notices/%s was copied from %s at %s, but Package.resolved pins %s at %s; copy its licence again", pin.Identity, p.Location, p.Revision, pin.Location, pin.State.Revision)
612 }
613 notices, err := colophon.DirNotices(dir)
614 if err != nil {
615 return nil, err
616 }
617 version := pin.State.Version
618 if version == "" {
619 version = pin.State.Revision[:12]
620 }
621 out = append(out, colophon.Package{Ecosystem: colophon.Swift, Name: pin.Identity, Version: version, Platforms: p.Platforms, Notices: notices})
622 }
623 return out, nil
624}
625