Install install a port and tell me where it was installed from.
(options InstallOptions)
| 21 | |
| 22 | // Install install a port and tell me where it was installed from. |
| 23 | func (p *Port) Install(options InstallOptions) (installedFrom string, retErr error) { |
| 24 | // At the top-level entry, reset the installReport. |
| 25 | if p.Parent == "" { |
| 26 | p.installReport = newInstallReport(p.NameVersion()) |
| 27 | } |
| 28 | defer func() { |
| 29 | if retErr != nil || p.installReport == nil { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | finalFrom := installedFrom |
| 34 | if finalFrom == "" { |
| 35 | finalFrom = "preinstalled" |
| 36 | } |
| 37 | p.installReport.add(p, finalFrom) |
| 38 | |
| 39 | // Only top-level port writes report files. |
| 40 | if p.Parent == "" { |
| 41 | reportPath, err := p.installReport.write(p) |
| 42 | if err != nil { |
| 43 | color.PrintWarning("failed to write install report for %s: %s", p.NameVersion(), err) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | color.PrintPass("%s's install report is generated", p.NameVersion()) |
| 48 | color.PrintHint("Location: %s\n", reportPath) |
| 49 | } |
| 50 | }() |
| 51 | |
| 52 | installedDir := expr.If(p.DevDep || p.HostDep, |
| 53 | filepath.Join(dirs.InstalledDir, p.ctx.Platform().GetHostName()+"-dev"), |
| 54 | filepath.Join(dirs.InstalledDir, |
| 55 | p.ctx.Platform().GetName()+"@"+p.ctx.Project().GetName()+"@"+p.ctx.BuildType()), |
| 56 | ) |
| 57 | |
| 58 | // There is no need to read p.Installed() if build with --force, this API may time-consuming. |
| 59 | var installed bool |
| 60 | if options.Force { |
| 61 | installed = false |
| 62 | } else { |
| 63 | if result, err := p.Installed(); err != nil { |
| 64 | return "", err |
| 65 | } else { |
| 66 | installed = result |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Remvoe installed port when repo source changed. |
| 71 | if p.sourceModified { |
| 72 | options := RemoveOptions{ |
| 73 | Purge: true, |
| 74 | Recursive: false, |
| 75 | BuildCache: false, |
| 76 | } |
| 77 | if err := p.Remove(options); err != nil { |
| 78 | return "", fmt.Errorf("failed to remove installed package -> %w", err) |
| 79 | } |
| 80 | installed = false // Mark as not installed. |