Skip to content

Commit af46739

Browse files
Load profiles when LoadSketch is called
1 parent a6dc8b5 commit af46739

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: commands/sketch/load.go

+37
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
4848
}
4949

5050
defaultPort, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
51+
52+
profiles := make([](*rpc.SketchProfile), len(sk.Project.Profiles))
53+
for i, profile := range sk.Project.Profiles {
54+
platforms, libraries := requiredPlatformsAndLibraries(profile)
55+
profiles[i] = &rpc.SketchProfile{
56+
Name: profile.Name,
57+
Fqbn: profile.FQBN,
58+
RequiredPlatforms: platforms,
59+
RequiredLibraries: libraries,
60+
}
61+
}
62+
63+
defaultProfileResp := &rpc.SketchProfile{}
64+
defaultProfile := sk.GetProfile(sk.Project.DefaultProfile)
65+
if defaultProfile != nil {
66+
defaultProfileResp.Name = defaultProfile.Name
67+
defaultProfileResp.Fqbn = defaultProfile.FQBN
68+
platforms, libraries := requiredPlatformsAndLibraries(defaultProfile)
69+
defaultProfileResp.RequiredLibraries = libraries
70+
defaultProfileResp.RequiredPlatforms = platforms
71+
}
72+
5173
return &rpc.LoadSketchResponse{
5274
MainFile: sk.MainFile.String(),
5375
LocationPath: sk.FullPath.String(),
@@ -57,5 +79,20 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
5779
DefaultFqbn: sk.GetDefaultFQBN(),
5880
DefaultPort: defaultPort,
5981
DefaultProtocol: defaultProtocol,
82+
Profiles: profiles,
83+
DefaultProfile: defaultProfileResp,
6084
}, nil
6185
}
86+
87+
func requiredPlatformsAndLibraries(profile *sketch.Profile) ([]string, []string) {
88+
platforms := []string{}
89+
libraries := []string{}
90+
for _, platform := range profile.Platforms {
91+
platforms = append(platforms, platform.String())
92+
}
93+
for _, library := range profile.Libraries {
94+
libraries = append(libraries, library.String())
95+
}
96+
97+
return platforms, libraries
98+
}

0 commit comments

Comments
 (0)