Skip to content

Commit cf9bc04

Browse files
committed
Added temporary functionality to support profile creation
It will be probably deprecated and removed once a better UX is implemented.
1 parent 6644d04 commit cf9bc04

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

cli/compile/compile.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
clean bool // Cleanup the build folder and do not use any cached build
7171
compilationDatabaseOnly bool // Only create compilation database without actually compiling
7272
sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
73+
dumpProfile bool // Create and print a profile configuration from the build
7374
// library and libraries sound similar but they're actually different.
7475
// library expects a path to the root folder of one single library.
7576
// libraries expects a path to a directory containing multiple libraries, similarly to the <directories.user>/libraries path.
@@ -95,6 +96,7 @@ func NewCommand() *cobra.Command {
9596

9697
fqbnArg.AddToCommand(compileCommand)
9798
profileArg.AddToCommand(compileCommand)
99+
compileCommand.Flags().BoolVar(&dumpProfile, "dump-profile", false, tr("Create and print a profile configuration from the build."))
98100
compileCommand.Flags().BoolVar(&showProperties, "show-properties", false, tr("Show all build properties used instead of compiling."))
99101
compileCommand.Flags().BoolVar(&preprocess, "preprocess", false, tr("Print preprocessed code to stdout instead of compiling."))
100102
compileCommand.Flags().StringVar(&buildCachePath, "build-cache-path", "", tr("Builds of 'core.a' are saved into this path to be cached and reused."))
@@ -270,6 +272,50 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
270272
}
271273
}
272274

275+
if dumpProfile {
276+
libs := ""
277+
hasVendoredLibs := false
278+
for _, lib := range compileRes.GetUsedLibraries() {
279+
if lib.Location != rpc.LibraryLocation_LIBRARY_LOCATION_USER && lib.Location != rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED {
280+
continue
281+
}
282+
if lib.GetVersion() == "" {
283+
hasVendoredLibs = true
284+
continue
285+
}
286+
libs += fmt.Sprintln(" - " + lib.GetName() + " (" + lib.GetVersion() + ")")
287+
}
288+
if hasVendoredLibs {
289+
fmt.Println()
290+
fmt.Println(tr("WARNING: The sketch is compiled using one or more custom libraries."))
291+
fmt.Println(tr("Currently, Build Profiles only support libraries available through Arduino Library Manager."))
292+
}
293+
294+
fmt.Println()
295+
fmt.Println("profile:")
296+
fmt.Println(" my_profile_name:")
297+
fmt.Println(" fqbn: " + compileRequest.GetFqbn())
298+
fmt.Println(" platforms:")
299+
boardPlatform := compileRes.GetBoardPlatform()
300+
fmt.Println(" - platform: " + boardPlatform.GetId() + " (" + boardPlatform.GetVersion() + ")")
301+
if url := boardPlatform.GetPackageUrl(); url != "" {
302+
fmt.Println(" platform_index_url: " + url)
303+
}
304+
305+
if buildPlatform := compileRes.GetBuildPlatform(); buildPlatform != nil &&
306+
buildPlatform.Id != boardPlatform.Id &&
307+
buildPlatform.Version != boardPlatform.Version {
308+
fmt.Println(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")")
309+
if url := buildPlatform.GetPackageUrl(); url != "" {
310+
fmt.Println(" platform_index_url: " + url)
311+
}
312+
}
313+
if len(libs) > 0 {
314+
fmt.Println(" libraries:")
315+
fmt.Print(libs)
316+
}
317+
}
318+
273319
feedback.PrintResult(&compileResult{
274320
CompileOut: compileStdOut.String(),
275321
CompileErr: compileStdErr.String(),

0 commit comments

Comments
 (0)