- Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathlibraries_loader.go
97 lines (86 loc) · 3.48 KB
/
libraries_loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package builder
import (
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/pkg/errors"
)
typeLibrariesLoaderstruct{}
func (s*LibrariesLoader) Run(ctx*types.Context) error {
ifctx.UseCachedLibrariesResolution {
// Since we are using the cached libraries resolution
// the library manager is not needed.
lm:=librariesmanager.NewLibraryManager(nil, nil)
ctx.LibrariesManager=lm
} elseifctx.LibrariesManager==nil {
lm:=librariesmanager.NewLibraryManager(nil, nil)
ctx.LibrariesManager=lm
builtInLibrariesFolders:=ctx.BuiltInLibrariesDirs
ifbuiltInLibrariesFolders!=nil {
iferr:=builtInLibrariesFolders.ToAbs(); err!=nil {
returnerrors.WithStack(err)
}
lm.AddLibrariesDir(builtInLibrariesFolders, libraries.IDEBuiltIn)
}
ifctx.ActualPlatform!=ctx.TargetPlatform {
lm.AddPlatformReleaseLibrariesDir(ctx.ActualPlatform, libraries.ReferencedPlatformBuiltIn)
}
lm.AddPlatformReleaseLibrariesDir(ctx.TargetPlatform, libraries.PlatformBuiltIn)
librariesFolders:=ctx.OtherLibrariesDirs
iferr:=librariesFolders.ToAbs(); err!=nil {
returnerrors.WithStack(err)
}
for_, folder:=rangelibrariesFolders {
lm.AddLibrariesDir(folder, libraries.User)
}
for_, status:=rangelm.RescanLibraries() {
// With the refactoring of the initialization step of the CLI we changed how
// errors are returned when loading platforms and libraries, that meant returning a list of
// errors instead of a single one to enhance the experience for the user.
// I have no intention right now to start a refactoring of the legacy package too, so
// here's this shitty solution for now.
// When we're gonna refactor the legacy package this will be gone.
ifctx.Verbose {
ctx.Warn(status.Message())
}
}
for_, dir:=rangectx.LibraryDirs {
// Libraries specified this way have top priority
iferr:=lm.LoadLibraryFromDir(dir, libraries.Unmanaged); err!=nil {
returnerr
}
}
}
resolver:=librariesresolver.NewCppResolver()
iferr:=resolver.ScanIDEBuiltinLibraries(ctx.LibrariesManager); err!=nil {
returnerrors.WithStack(err)
}
iferr:=resolver.ScanUserAndUnmanagedLibraries(ctx.LibrariesManager); err!=nil {
returnerrors.WithStack(err)
}
iferr:=resolver.ScanPlatformLibraries(ctx.LibrariesManager, ctx.TargetPlatform); err!=nil {
returnerrors.WithStack(err)
}
ifctx.ActualPlatform!=ctx.TargetPlatform {
iferr:=resolver.ScanPlatformLibraries(ctx.LibrariesManager, ctx.ActualPlatform); err!=nil {
returnerrors.WithStack(err)
}
}
ctx.LibrariesResolver=resolver
returnnil
}