Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow platforms without fixed version in profiles.
  • Loading branch information
cmaglie committed Jul 3, 2025
commit ef2317751ae8393674c990e9c5d4931d707ad9be
2 changes: 1 addition & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
}

// Load Platforms
if profile == nil {
if profile == nil || profile.RequireSystemInstalledPlatform() {
for _, err := range pmb.LoadHardware() {
s := &cmderrors.PlatformLoadingError{Cause: err}
responseError(s.GRPCStatus())
Expand Down
64 changes: 51 additions & 13 deletions internal/arduino/sketch/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ type Profile struct {
Libraries ProfileRequiredLibraries `yaml:"libraries"`
}

// UsesSystemPlatform checks if this profile requires a system installed platform.
func (p *Profile) RequireSystemInstalledPlatform() bool {
return p.Platforms[0].RequireSystemInstalledPlatform()
}

// ToRpc converts this Profile to an rpc.SketchProfile
func (p *Profile) ToRpc() *rpc.SketchProfile {
var portConfig *rpc.MonitorPortConfiguration
Expand Down Expand Up @@ -206,6 +211,12 @@ type ProfilePlatformReference struct {
PlatformIndexURL *url.URL
}

// RequireSystemInstalledPlatform returns true if the platform reference
// does not specify a version, meaning it requires the system installed platform.
func (p *ProfilePlatformReference) RequireSystemInstalledPlatform() bool {
return p.Version == nil
}

// InternalUniqueIdentifier returns the unique identifier for this object
func (p *ProfilePlatformReference) InternalUniqueIdentifier() string {
id := p.String()
Expand All @@ -224,20 +235,38 @@ func (p *ProfilePlatformReference) String() string {

// AsYaml outputs the platform reference as Yaml
func (p *ProfilePlatformReference) AsYaml() string {
res := fmt.Sprintf(" - platform: %s:%s (%s)\n", p.Packager, p.Architecture, p.Version)
res := ""
if p.Version != nil {
res += fmt.Sprintf(" - platform: %s:%s (%s)\n", p.Packager, p.Architecture, p.Version)
} else {
res += fmt.Sprintf(" - platform: %s:%s\n", p.Packager, p.Architecture)
}
if p.PlatformIndexURL != nil {
res += fmt.Sprintf(" platform_index_url: %s\n", p.PlatformIndexURL)
}
return res
}

func parseNameAndVersion(in string) (string, string, bool) {
re := regexp.MustCompile(`^([a-zA-Z0-9.\-_ :]+) \((.+)\)$`)
split := re.FindAllStringSubmatch(in, -1)
if len(split) != 1 || len(split[0]) != 3 {
return "", "", false
{
// Try to parse the input string in the format "VENDOR:ARCH (VERSION)"
re := regexp.MustCompile(`^([a-zA-Z0-9.\-_ :]+) \((.+)\)$`)
split := re.FindAllStringSubmatch(in, -1)
if len(split) == 1 && len(split[0]) == 3 {
return split[0][1], split[0][2], true
}
}
return split[0][1], split[0][2], true

{
// Try to parse the input string in the format "VENDOR:ARCH"
re := regexp.MustCompile(`^([a-zA-Z0-9.\-_ :]+)$`)
split := re.FindAllStringSubmatch(in, -1)
if len(split) == 1 && len(split[0]) == 2 {
return split[0][1], "", true
}
}

return "", "", false
}

// UnmarshalYAML decodes a ProfilePlatformReference from YAML source.
Expand All @@ -250,14 +279,23 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
return errors.New(i18n.Tr("missing '%s' directive", "platform"))
} else if platformID, platformVersion, ok := parseNameAndVersion(platformID); !ok {
return errors.New(i18n.Tr("invalid '%s' directive", "platform"))
} else if c, err := semver.Parse(platformVersion); err != nil {
return fmt.Errorf("%s: %w", i18n.Tr("error parsing version constraints"), err)
} else if split := strings.SplitN(platformID, ":", 2); len(split) != 2 {
return fmt.Errorf("%s: %s", i18n.Tr("invalid platform identifier"), platformID)
} else {
p.Packager = split[0]
p.Architecture = split[1]
p.Version = c
var version *semver.Version
if platformVersion != "" {
if v, err := semver.Parse(platformVersion); err != nil {
return fmt.Errorf("%s: %w", i18n.Tr("error parsing version constraints"), err)
} else {
version = v
}
}

if split := strings.SplitN(platformID, ":", 2); len(split) != 2 {
return fmt.Errorf("%s: %s", i18n.Tr("invalid platform identifier"), platformID)
} else {
p.Packager = split[0]
p.Architecture = split[1]
p.Version = version
}
}

if rawIndexURL, ok := data["platform_index_url"]; ok {
Expand Down
8 changes: 8 additions & 0 deletions internal/arduino/sketch/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ func TestProjectFileLoading(t *testing.T) {
require.NoError(t, err)
require.Equal(t, proj.AsYaml(), string(golden))
}
{
sketchProj := paths.New("testdata", "profiles", "profile_1.yml")
proj, err := LoadProjectFile(sketchProj)
require.NoError(t, err)
golden, err := sketchProj.ReadFile()
require.NoError(t, err)
require.Equal(t, string(golden), proj.AsYaml())
}
}
12 changes: 12 additions & 0 deletions internal/arduino/sketch/testdata/profiles/profile_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
profiles:
giga:
fqbn: arduino:mbed_giga:giga
platforms:
- platform: arduino:mbed_giga (4.3.1)

giga_any:
fqbn: arduino:mbed_giga:giga
platforms:
- platform: arduino:mbed_giga

default_profile: giga_any