Skip to content

Implemented --show-properties in board details command #2151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed legacy TargetBoardResolver and refactored unit-tests
  • Loading branch information
cmaglie committed Apr 15, 2023
commit f47a7bf24b6f99f8fbe0c766b8441b395f52ff36
64 changes: 47 additions & 17 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/arduino/arduino-cli/arduino"
bldr "github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/buildcache"
"github.com/arduino/arduino-cli/commands"
Expand Down Expand Up @@ -90,18 +89,21 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
if err != nil {
return nil, &arduino.InvalidFQBNError{Cause: err}
}

targetPlatform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: fqbn.Package,
PlatformArchitecture: fqbn.PlatformArch,
})
if targetPlatform == nil || pme.GetInstalledPlatformRelease(targetPlatform) == nil {
return nil, &arduino.PlatformNotFoundError{
Platform: fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch),
Cause: fmt.Errorf(tr("platform not installed")),
targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(fqbn)
if err != nil {
if targetPlatform == nil {
return nil, &arduino.PlatformNotFoundError{
Platform: fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch),
Cause: fmt.Errorf(tr("platform not installed")),
}
}
return nil, &arduino.InvalidFQBNError{Cause: err}
}

r = &rpc.CompileResponse{}
r.BoardPlatform = targetPlatform.ToRPCPlatformReference()
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()

// At the current time we do not have a way of knowing if a board supports the secure boot or not,
// so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless.
// It's not possible to use the default name for the keys since there could be more tools to sign and encrypt.
Expand All @@ -111,11 +113,22 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
securityKeysOverride = append(securityKeysOverride, "build.keys.keychain="+req.KeysKeychain, "build.keys.sign_key="+req.GetSignKey(), "build.keys.encrypt_key="+req.EncryptKey)
}

requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
if err != nil {
return nil, err
}

builderCtx := &types.Context{}
builderCtx.PackageManager = pme
if pme.GetProfile() != nil {
builderCtx.LibrariesManager = lm
}
builderCtx.TargetBoard = targetBoard
builderCtx.TargetBoardBuildProperties = buildProperties
builderCtx.TargetPlatform = targetPlatform
builderCtx.TargetPackage = targetPackage
builderCtx.ActualPlatform = buildPlatform
builderCtx.RequiredTools = requiredTools
builderCtx.UseCachedLibrariesResolution = req.GetSkipLibrariesDiscovery()
builderCtx.FQBN = fqbn
builderCtx.Sketch = sk
Expand Down Expand Up @@ -186,17 +199,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.OnlyUpdateCompilationDatabase = req.GetCreateCompilationDatabaseOnly()
builderCtx.SourceOverride = req.GetSourceOverride()

r = &rpc.CompileResponse{}
defer func() {
if p := builderCtx.BuildPath; p != nil {
r.BuildPath = p.String()
}
if pl := builderCtx.TargetPlatform; pl != nil {
r.BoardPlatform = pl.ToRPCPlatformReference()
}
if pl := builderCtx.ActualPlatform; pl != nil {
r.BuildPlatform = pl.ToRPCPlatformReference()
}
}()

defer func() {
Expand Down Expand Up @@ -243,6 +249,30 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
}()

// if it's a regular build, go on...

if req.GetVerbose() {
core := buildProperties.Get("build.core")
if core == "" {
core = "arduino"
}
// select the core name in case of "package:core" format
normalizedFQBN, err := pme.NormalizeFQBN(fqbn)
if err != nil {
outStream.Write([]byte(fmt.Sprintf("Could not normalize FQBN: %s\n", err)))
normalizedFQBN = fqbn
}
outStream.Write([]byte(fmt.Sprintf("FQBN: %s\n", normalizedFQBN)))
core = core[strings.Index(core, ":")+1:]
outStream.Write([]byte(tr("Using board '%[1]s' from platform in folder: %[2]s", targetBoard.BoardID, targetPlatform.InstallDir) + "\n"))
outStream.Write([]byte(tr("Using core '%[1]s' from platform in folder: %[2]s", core, buildPlatform.InstallDir) + "\n"))
outStream.Write([]byte("\n"))
}
if !targetBoard.Properties.ContainsKey("build.board") {
outStream.Write([]byte(
tr("Warning: Board %[1]s doesn't define a %[2]s preference. Auto-set to: %[3]s",
targetBoard.String(), "'build.board'", buildProperties.Get("build.board")) + "\n"))
}

if err := builder.RunBuilder(builderCtx); err != nil {
return r, &arduino.CompileFailedError{Message: err.Error()}
}
Expand Down
1 change: 0 additions & 1 deletion legacy/builder/container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
&AddAdditionalEntriesToContext{},
&FailIfBuildPathEqualsSketchPath{},
&HardwareLoader{},
&TargetBoardResolver{},
&LibrariesLoader{},
}

Expand Down
31 changes: 0 additions & 31 deletions legacy/builder/hardware_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,12 @@
package builder

import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/legacy/builder/types"
)

type HardwareLoader struct{}

func (s *HardwareLoader) Run(ctx *types.Context) error {
if ctx.PackageManager == nil {
// This should happen only on legacy arduino-builder.
// Hopefully this piece will be removed once the legacy package will be cleanedup.
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, "arduino-builder")
errs := pmb.LoadHardwareFromDirectories(ctx.HardwareDirs)
if ctx.Verbose {
// With the refactoring of the initialization step of the CLI we changed how
// errors are returned when loading platforms and libraries, that meant returning a list of
// errors instead of a single one to enhance the experience for the user.
// I have no intention right now to start a refactoring of the legacy package too, so
// here's this shitty solution for now.
// When we're gonna refactor the legacy package this will be gone.
for _, err := range errs {
ctx.Info(tr("Error loading hardware platform: %[1]s", err.Error()))
}
}

if !ctx.CanUseCachedTools {
if ctx.BuiltInToolsDirs != nil {
pmb.LoadToolsFromBundleDirectories(ctx.BuiltInToolsDirs)
}

ctx.CanUseCachedTools = true
}

pm := pmb.Build()
pme, _ /* never release... */ := pm.NewExplorer()
ctx.PackageManager = pme
}

ctx.AllTools = ctx.PackageManager.GetAllInstalledToolsReleases()
ctx.Hardware = ctx.PackageManager.GetPackages()
return nil
Expand Down
70 changes: 0 additions & 70 deletions legacy/builder/target_board_resolver.go

This file was deleted.

Loading