Skip to content

Commit a5f7f36

Browse files
committed
add VersionedNamesForPlatform and PackageNamesForPlatform
1 parent 59ec765 commit a5f7f36

File tree

5 files changed

+29
-43
lines changed

5 files changed

+29
-43
lines changed

internal/devconfig/packages.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ type Packages struct {
3232
Collection []Package `json:"-,omitempty"`
3333
}
3434

35-
// TODO savil: rm
36-
func (pkgs *Packages) Kind() int {
37-
return int(pkgs.jsonKind)
38-
}
39-
4035
// VersionedNames returns a list of package names with versions.
4136
// NOTE: if the package is unversioned, the version will be omitted (doesn't default to @latest).
4237
//
@@ -249,14 +244,25 @@ func NewPackage(name string, values map[string]any) Package {
249244
}
250245
}
251246

252-
// TODO savil: rm
253-
func (p *Package) Name() string {
254-
return p.name
255-
}
256-
257-
// TODO savil: rm
258-
func (p *Package) Kind() int {
259-
return int(p.kind)
247+
// enabledOnPlatform returns whether the package is enabled on the given platform.
248+
// If the package has a list of platforms, it is enabled only on those platforms.
249+
// If the package has a list of excluded platforms, it is enabled on all platforms
250+
// except those.
251+
func (p *Package) enabledOnPlatform(platform string) bool {
252+
if len(p.Platforms) > 0 {
253+
for _, plt := range p.Platforms {
254+
if plt == platform {
255+
return true
256+
}
257+
}
258+
return false
259+
}
260+
for _, plt := range p.ExcludedPlatforms {
261+
if plt == platform {
262+
return false
263+
}
264+
}
265+
return true
260266
}
261267

262268
func (p *Package) VersionedName() string {
@@ -268,8 +274,7 @@ func (p *Package) VersionedName() string {
268274
}
269275

270276
func (p *Package) IsEnabledOnPlatform() bool {
271-
// TODO savil. Next PR will update this implementation
272-
return true
277+
return p.enabledOnPlatform(nix.MustGetSystem())
273278
}
274279

275280
func (p *Package) UnmarshalJSON(data []byte) error {
@@ -290,10 +295,6 @@ func (p *Package) UnmarshalJSON(data []byte) error {
290295

291296
*p = Package(*alias)
292297
p.kind = regular
293-
294-
// TODO savil. needed?
295-
//p.Platforms = alias.Platforms
296-
//p.ExcludedPlatforms = alias.ExcludedPlatforms
297298
return nil
298299
}
299300

internal/devconfig/packages_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,3 @@ func TestParseVersionedName(t *testing.T) {
209209
})
210210
}
211211
}
212-
213-
func TestConvertToKind(t *testing.T) {
214-
testCase := Packages{
215-
jsonKind: jsonList,
216-
Collection: packagesFromLegacyList([]string{"python", "hello@latest", "[email protected]"}),
217-
}
218-
219-
expected := Packages{
220-
jsonKind: jsonMap,
221-
Collection: []Package{
222-
NewVersionOnlyPackage("python", "" /*version*/),
223-
NewVersionOnlyPackage("hello", "latest"),
224-
NewVersionOnlyPackage("go", "1.20"),
225-
},
226-
}
227-
228-
testCase.convertToKind(jsonMap)
229-
if !reflect.DeepEqual(testCase, expected) {
230-
t.Errorf("expected: %+v, got: %+v", expected, testCase)
231-
}
232-
}

internal/devpkg/package.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,13 @@ func (p *Package) Versioned() string {
412412
}
413413

414414
func (p *Package) IsLegacy() bool {
415-
return p.IsDevboxPackage() && !p.isVersioned() && p.lockfile.Get(p.Raw).GetSource() == ""
415+
if !p.IsDevboxPackage() || p.isVersioned() {
416+
return false
417+
}
418+
if p.IsInstallable() {
419+
return false
420+
}
421+
return p.lockfile.Get(p.Raw).GetSource() == ""
416422
}
417423

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

internal/impl/packages.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (d *Devbox) Add(ctx context.Context, platform, excludePlatform string, pkgs
4848
addedPackageNames := []string{}
4949
existingPackageNames := d.PackageNames()
5050
for _, pkg := range pkgs {
51-
5251
// If exact versioned package is already in the config, skip.
5352
if slices.Contains(existingPackageNames, pkg.Versioned()) {
5453
addedPackageNames = append(addedPackageNames, pkg.Versioned())

internal/nix/nix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ var nixPlatforms = []string{
185185
"x86_64-darwin",
186186
"x86_64-linux",
187187
// not technically supported, but should work?
188-
// ref.
188+
// ref. https://nixos.wiki/wiki/Nix_on_ARM
189+
// ref. https://github.com/jetpack-io/devbox/pull/1300
189190
"armv7l-linux",
190191
}
191192

0 commit comments

Comments
 (0)