Skip to content

Commit 5f0de04

Browse files
committed
Compile outputs profile dump as part of the result
1 parent c117489 commit 5f0de04

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

internal/cli/compile/compile.go

+20-22
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ func NewCommand() *cobra.Command {
144144
func runCompileCommand(cmd *cobra.Command, args []string) {
145145
logrus.Info("Executing `arduino-cli compile`")
146146

147-
if dumpProfile && feedback.GetFormat() != feedback.Text {
148-
feedback.Fatal(tr("You cannot use the %[1]s flag together with %[2]s.", "--dump-profile", "--format json"), feedback.ErrBadArgument)
149-
}
150147
if profileArg.Get() != "" {
151148
if len(libraries) > 0 {
152149
feedback.Fatal(tr("You cannot use the %s flag while compiling with a profile.", "--libraries"), feedback.ErrBadArgument)
@@ -255,7 +252,10 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
255252
}
256253
}
257254

258-
if dumpProfile {
255+
profileOut := ""
256+
if dumpProfile && compileError == nil {
257+
// Output profile
258+
259259
libs := ""
260260
hasVendoredLibs := false
261261
for _, lib := range compileRes.GetUsedLibraries() {
@@ -279,43 +279,37 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
279279
if split := strings.Split(compileRequest.GetFqbn(), ":"); len(split) > 2 {
280280
newProfileName = split[2]
281281
}
282-
profile := fmt.Sprintln()
283-
profile += fmt.Sprintln("profiles:")
284-
profile += fmt.Sprintln(" " + newProfileName + ":")
285-
profile += fmt.Sprintln(" fqbn: " + compileRequest.GetFqbn())
286-
profile += fmt.Sprintln(" platforms:")
282+
profileOut = fmt.Sprintln("profiles:")
283+
profileOut += fmt.Sprintln(" " + newProfileName + ":")
284+
profileOut += fmt.Sprintln(" fqbn: " + compileRequest.GetFqbn())
285+
profileOut += fmt.Sprintln(" platforms:")
287286
boardPlatform := compileRes.GetBoardPlatform()
288-
profile += fmt.Sprintln(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
287+
profileOut += fmt.Sprintln(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
289288
if url := boardPlatform.GetPackageUrl(); url != "" {
290-
profile += fmt.Sprintln(" platform_index_url: " + url)
289+
profileOut += fmt.Sprintln(" platform_index_url: " + url)
291290
}
292291

293292
if buildPlatform := compileRes.GetBuildPlatform(); buildPlatform != nil &&
294293
buildPlatform.Id != boardPlatform.Id &&
295294
buildPlatform.Version != boardPlatform.Version {
296-
profile += fmt.Sprintln(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
295+
profileOut += fmt.Sprintln(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
297296
if url := buildPlatform.GetPackageUrl(); url != "" {
298-
profile += fmt.Sprintln(" platform_index_url: " + url)
297+
profileOut += fmt.Sprintln(" platform_index_url: " + url)
299298
}
300299
}
301300
if len(libs) > 0 {
302-
profile += fmt.Sprintln(" libraries:")
303-
profile += fmt.Sprint(libs)
301+
profileOut += fmt.Sprintln(" libraries:")
302+
profileOut += fmt.Sprint(libs)
304303
}
305-
306-
// Output profile as a result
307-
if _, err := stdOut.Write([]byte(profile)); err != nil {
308-
feedback.FatalError(err, feedback.ErrGeneric)
309-
}
310-
feedback.PrintResult(stdIORes())
311-
return
304+
profileOut += fmt.Sprintln()
312305
}
313306

314307
stdIO := stdIORes()
315308
feedback.PrintResult(&compileResult{
316309
CompilerOut: stdIO.Stdout,
317310
CompilerErr: stdIO.Stderr,
318311
BuilderResult: compileRes,
312+
ProfileOut: profileOut,
319313
Success: compileError == nil,
320314
})
321315
if compileError != nil {
@@ -357,6 +351,7 @@ type compileResult struct {
357351
CompilerErr string `json:"compiler_err"`
358352
BuilderResult *rpc.CompileResponse `json:"builder_result"`
359353
Success bool `json:"success"`
354+
ProfileOut string `json:"profile_out,omitempty"`
360355
}
361356

362357
func (r *compileResult) Data() interface{} {
@@ -405,5 +400,8 @@ func (r *compileResult) String() string {
405400
}
406401
res += platforms.Render()
407402
}
403+
if r.ProfileOut != "" {
404+
res += "\n" + fmt.Sprintln(r.ProfileOut)
405+
}
408406
return res
409407
}

0 commit comments

Comments
 (0)