Skip to content

Commit

Permalink
Load profiles when LoadSketch is called
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPologruto committed Aug 16, 2023
1 parent a6dc8b5 commit af46739
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions commands/sketch/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
}

defaultPort, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()

profiles := make([](*rpc.SketchProfile), len(sk.Project.Profiles))
for i, profile := range sk.Project.Profiles {
platforms, libraries := requiredPlatformsAndLibraries(profile)
profiles[i] = &rpc.SketchProfile{
Name: profile.Name,
Fqbn: profile.FQBN,
RequiredPlatforms: platforms,
RequiredLibraries: libraries,
}
}

defaultProfileResp := &rpc.SketchProfile{}
defaultProfile := sk.GetProfile(sk.Project.DefaultProfile)
if defaultProfile != nil {
defaultProfileResp.Name = defaultProfile.Name
defaultProfileResp.Fqbn = defaultProfile.FQBN
platforms, libraries := requiredPlatformsAndLibraries(defaultProfile)
defaultProfileResp.RequiredLibraries = libraries
defaultProfileResp.RequiredPlatforms = platforms
}

return &rpc.LoadSketchResponse{
MainFile: sk.MainFile.String(),
LocationPath: sk.FullPath.String(),
Expand All @@ -57,5 +79,20 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
DefaultFqbn: sk.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultProtocol: defaultProtocol,
Profiles: profiles,
DefaultProfile: defaultProfileResp,
}, nil
}

func requiredPlatformsAndLibraries(profile *sketch.Profile) ([]string, []string) {
platforms := []string{}
libraries := []string{}
for _, platform := range profile.Platforms {
platforms = append(platforms, platform.String())
}
for _, library := range profile.Libraries {
libraries = append(libraries, library.String())
}

return platforms, libraries
}

0 comments on commit af46739

Please sign in to comment.