| | | 1 | | package repometa |
| | | 2 | | |
| | | 3 | | import ( |
| | | 4 | | "path/filepath" |
| | | 5 | | |
| | | 6 | | "github.com/BurntSushi/toml" |
| | | 7 | | ) |
| | | 8 | | |
| | | 9 | | type rustDetector struct{} |
| | | 10 | | |
| | | 11 | | type cargoTOML struct { |
| | | 12 | | Package *cargoPackage `toml:"package"` |
| | | 13 | | Workspace *cargoWorkspace `toml:"workspace"` |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | type cargoPackage struct { |
| | | 17 | | Name string `toml:"name"` |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | type cargoWorkspace struct { |
| | | 21 | | Members []string `toml:"members"` |
| | | 22 | | } |
| | | 23 | | |
| | 84 | 24 | | func (rustDetector) detect(dv dirVisit, cfg options) []finding { |
| | 81 | 25 | | if !hasFile(dv.files, "Cargo.toml") { |
| | 81 | 26 | | return nil |
| | 81 | 27 | | } |
| | 3 | 28 | | path := filepath.Join(dv.abs, "Cargo.toml") |
| | 3 | 29 | | data, err := readManifest(path, cfg) |
| | 0 | 30 | | if err != nil { |
| | 0 | 31 | | return []finding{{ |
| | 0 | 32 | | Kind: KindRustCrate, |
| | 0 | 33 | | Confidence: confidenceUnreadable, |
| | 0 | 34 | | Evidence: []Evidence{evidenceUnreadable(dv.rel, "Cargo.toml", err)}, |
| | 0 | 35 | | }} |
| | 0 | 36 | | } |
| | | 37 | | |
| | 3 | 38 | | var manifest cargoTOML |
| | 0 | 39 | | if err := toml.Unmarshal(data, &manifest); err != nil { |
| | 0 | 40 | | // Rust keeps its own bespoke parse-failure Evidence rather than |
| | 0 | 41 | | // using evidenceUnparsable: BurntSushi/toml's error text is noisy |
| | 0 | 42 | | // and the historical Evidence line omits it entirely. Preserve |
| | 0 | 43 | | // current behavior — bring this into the shared helper only if |
| | 0 | 44 | | // consumers ask for the extra detail. |
| | 0 | 45 | | return []finding{{ |
| | 0 | 46 | | Kind: KindRustCrate, |
| | 0 | 47 | | Confidence: confidenceUnparsable, |
| | 0 | 48 | | Evidence: []Evidence{{Path: relJoin(dv.rel, "Cargo.toml"), Reason: "Cargo.toml at directory root (parse error)"} |
| | 0 | 49 | | }} |
| | 0 | 50 | | } |
| | | 51 | | |
| | 3 | 52 | | kind := KindRustCrate |
| | 3 | 53 | | reason := "Cargo.toml with [package] section" |
| | 1 | 54 | | if manifest.Package == nil { |
| | 1 | 55 | | kind = KindRustWorkspace |
| | 1 | 56 | | reason = "Cargo.toml with [workspace] section, no [package] — virtual workspace" |
| | 1 | 57 | | } |
| | | 58 | | |
| | 3 | 59 | | var workspaces []Workspace |
| | 1 | 60 | | if manifest.Workspace != nil { |
| | 1 | 61 | | members := expandMembers(dv.abs, manifest.Workspace.Members, dv.rel) |
| | 1 | 62 | | workspaces = append(workspaces, Workspace{Kind: WorkspaceCargo, Members: members}) |
| | 1 | 63 | | } |
| | | 64 | | |
| | 3 | 65 | | return []finding{{ |
| | 3 | 66 | | Kind: kind, |
| | 3 | 67 | | Confidence: 1.0, |
| | 3 | 68 | | Evidence: []Evidence{{Path: relJoin(dv.rel, "Cargo.toml"), Reason: reason}}, |
| | 3 | 69 | | Workspaces: workspaces, |
| | 3 | 70 | | }} |
| | | 71 | | } |