Skip to content

Commit a7803b8

Browse files
committed
legacy: allow using a preconfigured library manager in build
1 parent 2b45531 commit a7803b8

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

legacy/builder/libraries_loader.go

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,53 @@ import (
2626
type LibrariesLoader struct{}
2727

2828
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
3132

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+
}
3940

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)
4647

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+
}
5455

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+
}
6465

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+
}
6971
}
7072
}
7173

7274
resolver := librariesresolver.NewCppResolver()
73-
if err := resolver.ScanFromLibrariesManager(lm); err != nil {
75+
if err := resolver.ScanFromLibrariesManager(ctx.LibrariesManager); err != nil {
7476
return errors.WithStack(err)
7577
}
7678
ctx.LibrariesResolver = resolver

0 commit comments

Comments
 (0)