From 1c5b552318ec251688d35d49eca9d01a6a345190 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 1 Sep 2023 23:12:34 +0200 Subject: [PATCH] remove LibrariesManager from context --- commands/compile/compile.go | 14 +++++++------- legacy/builder/test/builder_test.go | 3 +-- legacy/builder/test/libraries_loader_test.go | 8 ++++---- legacy/builder/types/context.go | 2 -- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/commands/compile/compile.go b/commands/compile/compile.go index c5f36dbcc7c..96f30a83f39 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -25,6 +25,7 @@ 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/libraries/librariesmanager" "github.com/arduino/arduino-cli/arduino/sketch" "github.com/arduino/arduino-cli/arduino/utils" "github.com/arduino/arduino-cli/buildcache" @@ -248,13 +249,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream } } - // TODO replace all UseCache call with our SketchLibrariesDetector - useCachedLibrariesResolution := req.GetSkipLibrariesDiscovery() + var libsManager *librariesmanager.LibrariesManager if pme.GetProfile() != nil { - builderCtx.LibrariesManager = lm + libsManager = lm } - lm, libsResolver, verboseOut, err := bldr.LibrariesLoader( - useCachedLibrariesResolution, builderCtx.LibrariesManager, + useCachedLibrariesResolution := req.GetSkipLibrariesDiscovery() + libsManager, libsResolver, verboseOut, err := bldr.LibrariesLoader( + useCachedLibrariesResolution, libsManager, builderCtx.BuiltInLibrariesDirs, builderCtx.LibraryDirs, builderCtx.OtherLibrariesDirs, builderCtx.ActualPlatform, builderCtx.TargetPlatform, ) @@ -262,13 +263,12 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream return r, &arduino.CompileFailedError{Message: err.Error()} } - builderCtx.LibrariesManager = lm if builderCtx.Verbose { builderCtx.Warn(string(verboseOut)) } builderCtx.SketchLibrariesDetector = bldr.NewSketchLibrariesDetector( - lm, libsResolver, + libsManager, libsResolver, builderCtx.Verbose, useCachedLibrariesResolution, func(msg string) { builderCtx.Info(msg) }, diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index 95816e42a0e..c4fc3a051b6 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -128,13 +128,12 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat if !stepToSkip[skipLibraries] { lm, libsResolver, _, err := bldr.LibrariesLoader( - false, ctx.LibrariesManager, + false, nil, ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs, ctx.ActualPlatform, ctx.TargetPlatform, ) NoError(t, err) - ctx.LibrariesManager = lm ctx.SketchLibrariesDetector = bldr.NewSketchLibrariesDetector( lm, libsResolver, ctx.Verbose, diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 66e27202fa5..dc4707455ff 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -48,7 +48,7 @@ func TestLoadLibrariesAVR(t *testing.T) { defer cleanUpBuilderTestContext(t, ctx) lm, libsResolver, _, err := builder.LibrariesLoader( - false, ctx.LibrariesManager, + false, nil, ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs, ctx.ActualPlatform, ctx.TargetPlatform, ) @@ -152,7 +152,7 @@ func TestLoadLibrariesSAM(t *testing.T) { defer cleanUpBuilderTestContext(t, ctx) lm, libsResolver, _, err := builder.LibrariesLoader( - false, ctx.LibrariesManager, + false, nil, ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs, ctx.ActualPlatform, ctx.TargetPlatform, ) @@ -229,7 +229,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { defer cleanUpBuilderTestContext(t, ctx) lm, _, _, err := builder.LibrariesLoader( - false, ctx.LibrariesManager, + false, nil, ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs, ctx.ActualPlatform, ctx.TargetPlatform, ) @@ -252,7 +252,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { defer cleanUpBuilderTestContext(t, ctx) lm, _, _, err := builder.LibrariesLoader( - false, ctx.LibrariesManager, + false, nil, ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs, ctx.ActualPlatform, ctx.TargetPlatform, ) diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index 6a50ecd21de..a78530387e9 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -25,7 +25,6 @@ import ( "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/libraries/librariesmanager" "github.com/arduino/arduino-cli/arduino/sketch" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" paths "github.com/arduino/go-paths-helper" @@ -102,7 +101,6 @@ type Context struct { WarningsLevel string // Libraries handling - LibrariesManager *librariesmanager.LibrariesManager IncludeFolders paths.PathList // C++ Parsing