Skip to content

Commit 3bd130a

Browse files
committed
Removed direct access to stdio streams in --dump-profile command
1 parent 7408414 commit 3bd130a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

cli/compile/compile.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,29 +281,36 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
281281
if split := strings.Split(compileRequest.GetFqbn(), ":"); len(split) > 2 {
282282
newProfileName = split[2]
283283
}
284-
fmt.Println()
285-
fmt.Println("profiles:")
286-
fmt.Println(" " + newProfileName + ":")
287-
fmt.Println(" fqbn: " + compileRequest.GetFqbn())
288-
fmt.Println(" platforms:")
284+
profile := fmt.Sprintln()
285+
profile += fmt.Sprintln("profiles:")
286+
profile += fmt.Sprintln(" " + newProfileName + ":")
287+
profile += fmt.Sprintln(" fqbn: " + compileRequest.GetFqbn())
288+
profile += fmt.Sprintln(" platforms:")
289289
boardPlatform := compileRes.GetBoardPlatform()
290-
fmt.Println(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
290+
profile += fmt.Sprintln(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
291291
if url := boardPlatform.GetPackageUrl(); url != "" {
292-
fmt.Println(" platform_index_url: " + url)
292+
profile += fmt.Sprintln(" platform_index_url: " + url)
293293
}
294294

295295
if buildPlatform := compileRes.GetBuildPlatform(); buildPlatform != nil &&
296296
buildPlatform.Id != boardPlatform.Id &&
297297
buildPlatform.Version != boardPlatform.Version {
298-
fmt.Println(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
298+
profile += fmt.Sprintln(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
299299
if url := buildPlatform.GetPackageUrl(); url != "" {
300-
fmt.Println(" platform_index_url: " + url)
300+
profile += fmt.Sprintln(" platform_index_url: " + url)
301301
}
302302
}
303303
if len(libs) > 0 {
304-
fmt.Println(" libraries:")
305-
fmt.Print(libs)
304+
profile += fmt.Sprintln(" libraries:")
305+
profile += fmt.Sprint(libs)
306306
}
307+
308+
// Output profile as a result
309+
if _, err := stdOut.Write([]byte(profile)); err != nil {
310+
feedback.FatalError(err, errorcodes.ErrGeneric)
311+
}
312+
feedback.PrintResult(stdIORes())
313+
os.Exit(0)
307314
}
308315

309316
stdIO := stdIORes()

0 commit comments

Comments
 (0)