Skip to content

Commit 2710805

Browse files
authored
[per-OS Packages] Error if adding --platform, when excluded_platforms is defined (#1373)
## Summary Background: for a package, `platforms` and `excluded_platforms` should be defined mutually-exclusively. Previously, we were being "clever" by dropping "excluded_platforms" when a user does `devbox add <package> --platform <platform>`. But I think we should: 1. Ensure the user explicitly makes the change to their devbox config. 2. Be consistent with how the inverse is handled: using `--exclude-platform` when `platform` is defined. ## How was it tested? added testscript unit-tests
1 parent 1678c13 commit 2710805

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

internal/devconfig/packages.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ func (pkgs *Packages) AddPlatforms(versionedname string, platforms []string) err
8787

8888
// Adding any platform will restrict installation to it, so
8989
// the ExcludedPlatforms are no longer needed
90-
pkg.ExcludedPlatforms = nil
90+
if len(pkg.ExcludedPlatforms) > 0 {
91+
return usererr.New(
92+
"cannot add any platform for package %s because it already has `excluded_platforms` defined. "+
93+
"Please delete the `excludedPlatforms` for this package from devbox.json and re-try.",
94+
pkg.VersionedName(),
95+
)
96+
}
9197

9298
pkgs.jsonKind = jsonMap
9399
pkg.kind = regular

testscripts/add/add_platforms.test.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ json.superset devbox.json expected_devbox3.json
2626
exec devbox add cowsay --exclude-platform x86_64-darwin,x86_64-linux --exclude-platform aarch64-darwin
2727
json.superset devbox.json expected_devbox4.json
2828

29+
### Part 3: Ensure we error to prevent inconsistent state
30+
31+
! exec devbox add cowsay --platform x86_64-darwin
32+
stderr 'Error: cannot add any platform for package cowsay@latest because it already has `excluded_platforms` defined'
33+
34+
! exec devbox add hello --exclude-platform x86_64-darwin
35+
stderr 'Error: cannot exclude any platform for package hello@latest because it already has `platforms` defined'
36+
2937
-- devbox.json --
3038
{
3139
"packages": [

0 commit comments

Comments
 (0)