MCPcopy
hub / github.com/whyrusleeping/gx / LoadPackageFile

Function LoadPackageFile

main.go:31–70  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

29const PkgFileName = gx.PkgFileName
30
31func LoadPackageFile(path string) (*gx.Package, error) {
32 if path == PkgFileName {
33 root, err := gx.GetPackageRoot()
34 if err != nil {
35 return nil, err
36 }
37
38 path = filepath.Join(root, PkgFileName)
39 }
40
41 var pkg gx.Package
42 err := gx.LoadPackageFile(&pkg, path)
43 if err != nil {
44 return nil, err
45 }
46
47 if pkg.GxVersion == "" {
48 pkg.GxVersion = gx.GxVersion
49 }
50
51 if pkg.SubtoolRequired {
52 found, err := gx.IsSubtoolInstalled(pkg.Language)
53 if err != nil {
54 return nil, err
55 }
56 if !found {
57 return nil, fmt.Errorf("package requires a subtool (gx-%s) and none was found", pkg.Language)
58 }
59 }
60
61 dephashes := make(map[string]string)
62 for _, dep := range pkg.Dependencies {
63 if pkgname := dephashes[dep.Hash]; pkgname != "" {
64 return nil, fmt.Errorf("have two packages with a hash of %s (%s, %s)", dep.Hash, dep.Name, pkgname)
65 }
66 dephashes[dep.Hash] = dep.Name
67 }
68
69 return &pkg, nil
70}
71
72func main() {
73 cfg, err := gx.LoadConfig()

Callers 1

main.goFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected