Skip to content

Commit 89b6055

Browse files
authored
Update lockfile api for package source (#1266)
## Summary Update lockfile api for package source as suggested in #1264 (comment) ## How was it tested? devbox run build devbox update
1 parent f6f94fe commit 89b6055

File tree

5 files changed

+44
-32
lines changed

5 files changed

+44
-32
lines changed

internal/devpkg/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (p *Package) Versioned() string {
403403
}
404404

405405
func (p *Package) IsLegacy() bool {
406-
return p.isDevboxPackage() && !p.isVersioned() && p.lockfile.Source(p.Raw) == ""
406+
return p.isDevboxPackage() && !p.isVersioned() && p.lockfile.Get(p.Raw).GetSource() == ""
407407
}
408408

409409
func (p *Package) LegacyToVersioned() string {

internal/devpkg/package_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func (l *lockfile) LegacyNixpkgsPath(pkg string) string {
119119
)
120120
}
121121

122-
func (l *lockfile) Source(pkg string) string {
123-
return ""
122+
func (l *lockfile) Get(pkg string) *lock.Package {
123+
return nil
124124
}
125125

126126
func (l *lockfile) Resolve(pkg string) (*lock.Package, error) {

internal/lock/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type devboxProject interface {
1111
}
1212

1313
type Locker interface {
14+
Get(string) *Package
1415
LegacyNixpkgsPath(string) string
1516
ProjectDir() string
1617
Resolve(string) (*Package, error)
17-
Source(string) string
1818
}

internal/lock/lockfile.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import (
1717
)
1818

1919
const lockFileVersion = "1"
20-
const (
21-
nixpkgSource string = "nixpkg"
22-
devboxSearchSource string = "devbox-search"
23-
)
2420

2521
// Lightly inspired by package-lock.json
2622
type File struct {
@@ -32,27 +28,6 @@ type File struct {
3228
Packages map[string]*Package `json:"packages"`
3329
}
3430

35-
type Package struct {
36-
LastModified string `json:"last_modified,omitempty"`
37-
PluginVersion string `json:"plugin_version,omitempty"`
38-
Resolved string `json:"resolved,omitempty"`
39-
Source string `json:"source,omitempty"`
40-
Version string `json:"version,omitempty"`
41-
// Systems is keyed by the system name
42-
Systems map[string]*SystemInfo `json:"systems,omitempty"`
43-
}
44-
45-
type SystemInfo struct {
46-
// StorePath is the input-addressed path for the nix package in /nix/store
47-
// It is the cache key in the Binary Cache Store (cache.nixos.org)
48-
// It is of the form <hash>-<name>-<version>
49-
// <name> may be different from the canonicalName so we store the full store path.
50-
StorePath string `json:"store_path,omitempty"`
51-
// CAStorePath is the content-addressed path for the nix package in /nix/store
52-
// It is of the form <hash>-<name>-<version>
53-
CAStorePath string `json:"ca_store_path,omitempty"`
54-
}
55-
5631
func GetFile(project devboxProject) (*File, error) {
5732
lockFile := &File{
5833
devboxProject: project,
@@ -130,12 +105,12 @@ func (l *File) LegacyNixpkgsPath(pkg string) string {
130105
)
131106
}
132107

133-
func (l *File) Source(pkg string) string {
108+
func (l *File) Get(pkg string) *Package {
134109
entry, hasEntry := l.Packages[pkg]
135110
if !hasEntry || entry.Resolved == "" {
136-
return ""
111+
return nil
137112
}
138-
return entry.Source
113+
return entry
139114
}
140115

141116
// This probably belongs in input.go but can't add it there because it will

internal/lock/package.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved.
2+
// Use of this source code is governed by the license in the LICENSE file.
3+
4+
package lock
5+
6+
const (
7+
nixpkgSource string = "nixpkg"
8+
devboxSearchSource string = "devbox-search"
9+
)
10+
11+
type Package struct {
12+
LastModified string `json:"last_modified,omitempty"`
13+
PluginVersion string `json:"plugin_version,omitempty"`
14+
Resolved string `json:"resolved,omitempty"`
15+
Source string `json:"source,omitempty"`
16+
Version string `json:"version,omitempty"`
17+
// Systems is keyed by the system name
18+
Systems map[string]*SystemInfo `json:"systems,omitempty"`
19+
}
20+
21+
type SystemInfo struct {
22+
// StorePath is the input-addressed path for the nix package in /nix/store
23+
// It is the cache key in the Binary Cache Store (cache.nixos.org)
24+
// It is of the form <hash>-<name>-<version>
25+
// <name> may be different from the canonicalName so we store the full store path.
26+
StorePath string `json:"store_path,omitempty"`
27+
// CAStorePath is the content-addressed path for the nix package in /nix/store
28+
// It is of the form <hash>-<name>-<version>
29+
CAStorePath string `json:"ca_store_path,omitempty"`
30+
}
31+
32+
func (p *Package) GetSource() string {
33+
if p == nil {
34+
return ""
35+
}
36+
return p.Source
37+
}

0 commit comments

Comments
 (0)