Export performs the export operation.
()
| 42 | |
| 43 | // Export performs the export operation. |
| 44 | func (e *Exporter) Export() error { |
| 45 | // Create export directory. |
| 46 | if err := os.RemoveAll(e.exportDir); err != nil { |
| 47 | return fmt.Errorf("failed to clear existing export directory -> %w", err) |
| 48 | } |
| 49 | if err := os.MkdirAll(e.exportDir, os.ModePerm); err != nil { |
| 50 | return fmt.Errorf("failed to create export directory -> %w", err) |
| 51 | } |
| 52 | |
| 53 | title := fmt.Sprintf("\nExporting snapshot: %s", e.exportDir) |
| 54 | color.Println(color.Title, title) |
| 55 | color.Println(color.Line, strings.Repeat("-", len(title))) |
| 56 | |
| 57 | // 1. Collect used ports. |
| 58 | color.Println(color.Hint, "✔ Collecting dependencies...") |
| 59 | usedPorts, err := e.collector.CollectUsedPorts(e.celer) |
| 60 | if err != nil { |
| 61 | return fmt.Errorf("failed to collect ports -> %w", err) |
| 62 | } |
| 63 | e.usedPorts = usedPorts |
| 64 | color.Printf(color.Hint, " Found %d port(s)\n", len(e.usedPorts)) |
| 65 | |
| 66 | // 2. Export ports with fixed source checksums. |
| 67 | color.Println(color.Hint, "✔ Exporting ports...") |
| 68 | if err := e.exportPorts(); err != nil { |
| 69 | return fmt.Errorf("failed to export ports -> %w", err) |
| 70 | } |
| 71 | |
| 72 | // 3. Export conf directory. |
| 73 | color.Println(color.Hint, "✔ Exporting configuration...") |
| 74 | if err := e.exportConf(); err != nil { |
| 75 | return fmt.Errorf("failed to export conf -> %w", err) |
| 76 | } |
| 77 | |
| 78 | // 4. Export celer.toml. |
| 79 | color.Println(color.Hint, "✔ Exporting celer.toml...") |
| 80 | if err := e.exportCelerToml(); err != nil { |
| 81 | return fmt.Errorf("failed to export celer.toml -> %w", err) |
| 82 | } |
| 83 | |
| 84 | // 5. Export toolchain_file.cmake (if exists). |
| 85 | color.Println(color.Hint, "✔ Exporting toolchain file...") |
| 86 | if err := e.exportToolchainFile(); err != nil { |
| 87 | return fmt.Errorf("failed to export toolchain_file.cmake -> %w", err) |
| 88 | } |
| 89 | |
| 90 | // 6. Export celer executable. |
| 91 | color.Println(color.Hint, "✔ Exporting celer executable...") |
| 92 | if err := e.exportCelerExecutable(); err != nil { |
| 93 | return fmt.Errorf("failed to export celer executable -> %w", err) |
| 94 | } |
| 95 | |
| 96 | // 7. Generate snapshot. |
| 97 | color.Println(color.Hint, "✔ Generating snapshot report...") |
| 98 | buildEnv := BuildEnv{ |
| 99 | ExportedAt: time.Now(), |
| 100 | CelerVersion: e.celer.Version(), |
| 101 | Platform: e.celer.Platform().GetName(), |
no test coverage detected