Skip to content

Commit 4722d66

Browse files
committed
Using LibraryLocations and librarymanager functions to load libraries
1 parent fd8b7dc commit 4722d66

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

libraries_loader.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,39 @@ import (
4242
type LibrariesLoader struct{}
4343

4444
func (s *LibrariesLoader) Run(ctx *types.Context) error {
45+
lm := librariesmanager.NewLibraryManager()
46+
ctx.LibrariesManager = lm
47+
4548
builtInLibrariesFolders := ctx.BuiltInLibrariesFolders
4649
if err := builtInLibrariesFolders.ToAbs(); err != nil {
4750
return i18n.WrapError(err)
4851
}
49-
sortedLibrariesFolders := builtInLibrariesFolders.Clone()
52+
lm.AddLibrariesDir(libraries.IDEBuiltIn, builtInLibrariesFolders...)
5053

51-
actualPlatform := ctx.ActualPlatform
52-
platform := ctx.TargetPlatform
5354
debugLevel := ctx.DebugLevel
5455
logger := ctx.GetLogger()
5556

57+
actualPlatform := ctx.ActualPlatform
58+
platform := ctx.TargetPlatform
5659
if actualPlatform != platform {
5760
if dir := actualPlatform.GetLibrariesDir(); dir != nil {
58-
sortedLibrariesFolders.Add(dir)
61+
lm.AddLibrariesDir(libraries.ReferencedPlatformBuiltIn, dir)
5962
}
6063
}
61-
6264
if dir := platform.GetLibrariesDir(); dir != nil {
63-
sortedLibrariesFolders.Add(dir)
65+
lm.AddLibrariesDir(libraries.PlatformBuiltIn, dir)
6466
}
6567

6668
librariesFolders := ctx.OtherLibrariesFolders
6769
if err := librariesFolders.ToAbs(); err != nil {
6870
return i18n.WrapError(err)
6971
}
70-
sortedLibrariesFolders.AddAllMissing(librariesFolders)
72+
lm.AddLibrariesDir(libraries.Sketchbook, librariesFolders...)
7173

72-
ctx.LibrariesFolders = sortedLibrariesFolders
73-
74-
lm := librariesmanager.NewLibraryManager()
75-
for _, libraryFolder := range sortedLibrariesFolders {
76-
if err := lm.LoadLibrariesFromDir(libraryFolder); err != nil {
77-
return i18n.WrapError(err)
78-
}
74+
if err := lm.RescanLibraries(); err != nil {
75+
return i18n.WrapError(err)
7976
}
77+
8078
if debugLevel > 0 {
8179
for _, lib := range lm.Libraries {
8280
for _, libAlt := range lib.Alternatives {
@@ -91,8 +89,6 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
9189
}
9290
}
9391

94-
ctx.LibrariesManager = lm
95-
9692
headerToLibraries := make(map[string][]*libraries.Library)
9793
for _, lib := range lm.Libraries {
9894
for _, library := range lib.Alternatives {

phases/libraries_builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
5252
librariesBuildPath := ctx.LibrariesBuildPath
5353
buildProperties := ctx.BuildProperties
5454
includes := utils.Map(ctx.IncludeFolders.AsStrings(), utils.WrapWithHyphenI)
55-
libraries := ctx.ImportedLibraries
55+
libs := ctx.ImportedLibraries
5656

5757
if err := librariesBuildPath.MkdirAll(); err != nil {
5858
return i18n.WrapError(err)
5959
}
6060

61-
objectFiles, err := compileLibraries(ctx, libraries, librariesBuildPath, buildProperties, includes)
61+
objectFiles, err := compileLibraries(ctx, libs, librariesBuildPath, buildProperties, includes)
6262
if err != nil {
6363
return i18n.WrapError(err)
6464
}
6565

6666
ctx.LibrariesObjectFiles = objectFiles
6767

6868
// Search for precompiled libraries
69-
fixLDFLAGforPrecompiledLibraries(ctx, libraries)
69+
fixLDFLAGforPrecompiledLibraries(ctx, libs)
7070

7171
return nil
7272
}
7373

74-
func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libraries []*libraries.Library) error {
74+
func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs []*libraries.Library) error {
7575

76-
for _, library := range libraries {
76+
for _, library := range libs {
7777
if library.Precompiled {
7878
// add library src path to compiler.c.elf.extra_flags
7979
// use library.Name as lib name and srcPath/{mcpu} as location

types/context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type Context struct {
2525
HardwareFolders paths.PathList
2626
ToolsFolders paths.PathList
2727
BuiltInToolsFolders paths.PathList
28-
LibrariesFolders paths.PathList
2928
BuiltInLibrariesFolders paths.PathList
3029
OtherLibrariesFolders paths.PathList
3130
SketchLocation *paths.Path

0 commit comments

Comments
 (0)