Skip to content

Commit

Permalink
refactor AddAdditionalEntriesToContext in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Aug 31, 2023
1 parent 868d325 commit 2e6a5ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
37 changes: 17 additions & 20 deletions legacy/builder/add_additional_entries_to_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,34 @@ package builder
import (
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
)

type AddAdditionalEntriesToContext struct{}

func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
if ctx.BuildPath != nil {
buildPath := ctx.BuildPath
sketchBuildPath, err := buildPath.Join(constants.FOLDER_SKETCH).Abs()
func AddAdditionalEntriesToContext(buildPath *paths.Path, warningLevel string) (sketchBuildPath *paths.Path, librariesBuildPath *paths.Path, coreBuildPath *paths.Path, warningsLevel string, librariesResolutionResults map[string]types.LibraryResolutionResult, err error) {
if buildPath != nil {
buildPath := buildPath
sketchBuildPath, err = buildPath.Join(constants.FOLDER_SKETCH).Abs()
if err != nil {
return errors.WithStack(err)
err = errors.WithStack(err)
return
}
librariesBuildPath, err := buildPath.Join(constants.FOLDER_LIBRARIES).Abs()
librariesBuildPath, err = buildPath.Join(constants.FOLDER_LIBRARIES).Abs()
if err != nil {
return errors.WithStack(err)
err = errors.WithStack(err)
return
}
coreBuildPath, err := buildPath.Join(constants.FOLDER_CORE).Abs()
coreBuildPath, err = buildPath.Join(constants.FOLDER_CORE).Abs()
if err != nil {
return errors.WithStack(err)
err = errors.WithStack(err)
return
}

ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
}

if ctx.WarningsLevel == "" {
ctx.WarningsLevel = DEFAULT_WARNINGS_LEVEL
if warningLevel == "" {
warningsLevel = DEFAULT_WARNINGS_LEVEL
}

ctx.LibrariesResolutionResults = map[string]types.LibraryResolutionResult{}

return nil
librariesResolutionResults = map[string]types.LibraryResolutionResult{}
return
}
12 changes: 11 additions & 1 deletion legacy/builder/container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ import (
type ContainerSetupHardwareToolsLibsSketchAndProps struct{}

func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) error {
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
if err != nil {
return errors.WithStack(err)
}
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&AddAdditionalEntriesToContext{},
&FailIfBuildPathEqualsSketchPath{},
&LibrariesLoader{},
}
Expand Down

0 comments on commit 2e6a5ab

Please sign in to comment.