Skip to content

Commit 9229bff

Browse files
committed
Made gRPC Init return a full Profile structure
Makes it more future-proof in case of further expasion
1 parent c4ce087 commit 9229bff

File tree

8 files changed

+715
-627
lines changed

8 files changed

+715
-627
lines changed

Diff for: cli/compile/compile.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646

4747
var (
4848
fqbnArg arguments.Fqbn // Fully Qualified Board Name, e.g.: arduino:avr:uno.
49-
profile arguments.Profile // Profile to use
49+
profileArg arguments.Profile // Profile to use
5050
showProperties bool // Show all build preferences used instead of compiling.
5151
preprocess bool // Print preprocessed code to stdout.
5252
buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
@@ -92,7 +92,7 @@ func NewCommand() *cobra.Command {
9292
}
9393

9494
fqbnArg.AddToCommand(compileCommand)
95-
profile.AddToCommand(compileCommand)
95+
profileArg.AddToCommand(compileCommand)
9696
compileCommand.Flags().BoolVar(&showProperties, "show-properties", false, tr("Show all build properties used instead of compiling."))
9797
compileCommand.Flags().BoolVar(&preprocess, "preprocess", false, tr("Print preprocessed code to stdout instead of compiling."))
9898
compileCommand.Flags().StringVar(&buildCachePath, "build-cache-path", "", tr("Builds of 'core.a' are saved into this path to be cached and reused."))
@@ -150,9 +150,9 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
150150
sketchPath := arguments.InitSketchPath(path)
151151
sk := arguments.NewSketch(sketchPath)
152152

153-
inst, profileFqbn := instance.CreateAndInitWithProfile(profile.Get(), sketchPath)
153+
inst, profile := instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
154154
if fqbnArg.String() == "" {
155-
fqbnArg.Set(profileFqbn)
155+
fqbnArg.Set(profile.GetFqbn())
156156
}
157157

158158
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, sk)

Diff for: cli/instance/instance.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ func CreateAndInit() *rpc.Instance {
4141
return inst
4242
}
4343

44-
func CreateAndInitWithProfile(profile string, sketchPath *paths.Path) (*rpc.Instance, string) {
44+
func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc.Instance, *rpc.Profile) {
4545
instance, err := Create()
4646
if err != nil {
4747
feedback.Errorf(tr("Error creating instance: %v"), err)
4848
os.Exit(errorcodes.ErrGeneric)
4949
}
50-
fqbn, errs := InitWithProfile(instance, profile, sketchPath)
50+
profile, errs := InitWithProfile(instance, profileName, sketchPath)
5151
for _, err := range errs {
5252
feedback.Errorf(tr("Error initializing instance: %v"), err)
5353
}
54-
return instance, fqbn
54+
return instance, profile
5555
}
5656

5757
// Create and return a new Instance.
@@ -73,12 +73,12 @@ func Init(instance *rpc.Instance) []error {
7373
return errs
7474
}
7575

76-
func InitWithProfile(instance *rpc.Instance, profile string, sketchPath *paths.Path) (string, []error) {
76+
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) (*rpc.Profile, []error) {
7777
errs := []error{}
7878

7979
// In case the CLI is executed for the first time
8080
if err := FirstUpdate(instance); err != nil {
81-
return "", append(errs, err)
81+
return nil, append(errs, err)
8282
}
8383

8484
downloadCallback := output.ProgressBar()
@@ -87,9 +87,9 @@ func InitWithProfile(instance *rpc.Instance, profile string, sketchPath *paths.P
8787
initReq := &rpc.InitRequest{Instance: instance}
8888
if sketchPath != nil {
8989
initReq.SketchPath = sketchPath.String()
90-
initReq.Profile = profile
90+
initReq.Profile = profileName
9191
}
92-
profileFqbn := ""
92+
var profile *rpc.Profile
9393
err := commands.Init(initReq, func(res *rpc.InitResponse) {
9494
if st := res.GetError(); st != nil {
9595
errs = append(errs, errors.New(st.Message))
@@ -104,15 +104,15 @@ func InitWithProfile(instance *rpc.Instance, profile string, sketchPath *paths.P
104104
}
105105
}
106106

107-
if fqbn := res.GetProfileSelectedFqbn(); fqbn != "" {
108-
profileFqbn = fqbn
107+
if p := res.GetProfile(); p != nil {
108+
profile = p
109109
}
110110
})
111111
if err != nil {
112112
errs = append(errs, err)
113113
}
114114

115-
return profileFqbn, errs
115+
return profile, errs
116116
}
117117

118118
// FirstUpdate downloads libraries and packages indexes if they don't exist.

Diff for: cli/upload/upload.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
var (
4242
fqbnArg arguments.Fqbn
4343
portArgs arguments.Port
44-
profile arguments.Profile
44+
profileArg arguments.Profile
4545
verbose bool
4646
verify bool
4747
importDir string
@@ -67,7 +67,7 @@ func NewCommand() *cobra.Command {
6767

6868
fqbnArg.AddToCommand(uploadCommand)
6969
portArgs.AddToCommand(uploadCommand)
70-
profile.AddToCommand(uploadCommand)
70+
profileArg.AddToCommand(uploadCommand)
7171
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries to upload."))
7272
uploadCommand.Flags().StringVarP(&importFile, "input-file", "i", "", tr("Binary file to upload."))
7373
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
@@ -97,9 +97,9 @@ func runUploadCommand(command *cobra.Command, args []string) {
9797
os.Exit(errorcodes.ErrGeneric)
9898
}
9999

100-
instance, profileFqbn := instance.CreateAndInitWithProfile(profile.Get(), sketchPath)
100+
instance, profile := instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
101101
if fqbnArg.String() == "" {
102-
fqbnArg.Set(profileFqbn)
102+
fqbnArg.Set(profile.GetFqbn())
103103
}
104104

105105
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk)

Diff for: commands/instances.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
212212
}
213213
profile = sk.GetProfile(req.GetProfile())
214214
responseCallback(&rpc.InitResponse{
215-
Message: &rpc.InitResponse_ProfileSelectedFqbn{
216-
ProfileSelectedFqbn: profile.FQBN,
215+
Message: &rpc.InitResponse_Profile{
216+
Profile: &rpc.Profile{
217+
Name: req.GetProfile(),
218+
Fqbn: profile.FQBN,
219+
// TODO: Other profile infos may be provided here...
220+
},
217221
},
218222
})
219223
}

0 commit comments

Comments
 (0)