@@ -26,51 +26,53 @@ import (
26
26
type LibrariesLoader struct {}
27
27
28
28
func (s * LibrariesLoader ) Run (ctx * types.Context ) error {
29
- lm := librariesmanager .NewLibraryManager (nil , nil )
30
- ctx .LibrariesManager = lm
29
+ if ctx .LibrariesManager == nil {
30
+ lm := librariesmanager .NewLibraryManager (nil , nil )
31
+ ctx .LibrariesManager = lm
31
32
32
- builtInLibrariesFolders := ctx .BuiltInLibrariesDirs
33
- if err := builtInLibrariesFolders .ToAbs (); err != nil {
34
- return errors .WithStack (err )
35
- }
36
- for _ , folder := range builtInLibrariesFolders {
37
- lm .AddLibrariesDir (folder , libraries .IDEBuiltIn )
38
- }
33
+ builtInLibrariesFolders := ctx .BuiltInLibrariesDirs
34
+ if err := builtInLibrariesFolders .ToAbs (); err != nil {
35
+ return errors .WithStack (err )
36
+ }
37
+ for _ , folder := range builtInLibrariesFolders {
38
+ lm .AddLibrariesDir (folder , libraries .IDEBuiltIn )
39
+ }
39
40
40
- actualPlatform := ctx .ActualPlatform
41
- platform := ctx .TargetPlatform
42
- if actualPlatform != platform {
43
- lm .AddPlatformReleaseLibrariesDir (actualPlatform , libraries .ReferencedPlatformBuiltIn )
44
- }
45
- lm .AddPlatformReleaseLibrariesDir (platform , libraries .PlatformBuiltIn )
41
+ actualPlatform := ctx .ActualPlatform
42
+ platform := ctx .TargetPlatform
43
+ if actualPlatform != platform {
44
+ lm .AddPlatformReleaseLibrariesDir (actualPlatform , libraries .ReferencedPlatformBuiltIn )
45
+ }
46
+ lm .AddPlatformReleaseLibrariesDir (platform , libraries .PlatformBuiltIn )
46
47
47
- librariesFolders := ctx .OtherLibrariesDirs
48
- if err := librariesFolders .ToAbs (); err != nil {
49
- return errors .WithStack (err )
50
- }
51
- for _ , folder := range librariesFolders {
52
- lm .AddLibrariesDir (folder , libraries .User )
53
- }
48
+ librariesFolders := ctx .OtherLibrariesDirs
49
+ if err := librariesFolders .ToAbs (); err != nil {
50
+ return errors .WithStack (err )
51
+ }
52
+ for _ , folder := range librariesFolders {
53
+ lm .AddLibrariesDir (folder , libraries .User )
54
+ }
54
55
55
- if errs := lm .RescanLibraries (); len (errs ) > 0 {
56
- // With the refactoring of the initialization step of the CLI we changed how
57
- // errors are returned when loading platforms and libraries, that meant returning a list of
58
- // errors instead of a single one to enhance the experience for the user.
59
- // I have no intention right now to start a refactoring of the legacy package too, so
60
- // here's this shitty solution for now.
61
- // When we're gonna refactor the legacy package this will be gone.
62
- return errors .WithStack (errs [0 ].Err ())
63
- }
56
+ if errs := lm .RescanLibraries (); len (errs ) > 0 {
57
+ // With the refactoring of the initialization step of the CLI we changed how
58
+ // errors are returned when loading platforms and libraries, that meant returning a list of
59
+ // errors instead of a single one to enhance the experience for the user.
60
+ // I have no intention right now to start a refactoring of the legacy package too, so
61
+ // here's this shitty solution for now.
62
+ // When we're gonna refactor the legacy package this will be gone.
63
+ return errors .WithStack (errs [0 ].Err ())
64
+ }
64
65
65
- for _ , dir := range ctx .LibraryDirs {
66
- // Libraries specified this way have top priority
67
- if err := lm .LoadLibraryFromDir (dir , libraries .Unmanaged ); err != nil {
68
- return err
66
+ for _ , dir := range ctx .LibraryDirs {
67
+ // Libraries specified this way have top priority
68
+ if err := lm .LoadLibraryFromDir (dir , libraries .Unmanaged ); err != nil {
69
+ return err
70
+ }
69
71
}
70
72
}
71
73
72
74
resolver := librariesresolver .NewCppResolver ()
73
- if err := resolver .ScanFromLibrariesManager (lm ); err != nil {
75
+ if err := resolver .ScanFromLibrariesManager (ctx . LibrariesManager ); err != nil {
74
76
return errors .WithStack (err )
75
77
}
76
78
ctx .LibrariesResolver = resolver
0 commit comments