Skip to content

Commit ad7d4d8

Browse files
committed
Always add to the build the libraries requested in the active sketch profile.
This will improve sketch compile time.
1 parent 1839bb3 commit ad7d4d8

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

commands/service_compile.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
105105
return &cmderrors.CantOpenSketchError{Cause: err}
106106
}
107107

108+
profile := pme.GetProfile()
108109
fqbnIn := req.GetFqbn()
109110
if fqbnIn == "" && sk != nil {
110-
if pme.GetProfile() != nil {
111-
fqbnIn = pme.GetProfile().FQBN
111+
if profile != nil {
112+
fqbnIn = profile.FQBN
112113
} else {
113114
fqbnIn = sk.GetDefaultFQBN()
114115
}
@@ -224,7 +225,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
224225
otherLibrariesDirs.Add(s.settings.LibrariesDir())
225226

226227
var libsManager *librariesmanager.LibrariesManager
227-
if pme.GetProfile() != nil {
228+
if profile != nil {
228229
libsManager = lm
229230
}
230231

@@ -252,6 +253,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
252253
if req.GetVerbose() {
253254
verbosity = logger.VerbosityVerbose
254255
}
256+
alwaysBuildProfileLibs := profile != nil
255257
sketchBuilder, err := builder.NewBuilder(
256258
ctx,
257259
sk,
@@ -275,6 +277,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
275277
paths.NewPathList(req.GetLibrary()...),
276278
outStream, errStream, verbosity, req.GetWarnings(),
277279
progressCB,
280+
alwaysBuildProfileLibs,
278281
pme.GetEnvVarsForSpawnedProcess(),
279282
)
280283
if err != nil {

internal/arduino/builder/builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func NewBuilder(
138138
libraryDirs paths.PathList,
139139
stdout, stderr io.Writer, verbosity logger.Verbosity, warningsLevel string,
140140
progresCB rpc.TaskProgressCB,
141+
alwaysBuildProfileLibs bool,
141142
toolEnv []string,
142143
) (*Builder, error) {
143144
buildProperties := properties.NewMap()
@@ -242,6 +243,7 @@ func NewBuilder(
242243
libsManager, libsResolver,
243244
useCachedLibrariesResolution,
244245
onlyUpdateCompilationDatabase,
246+
alwaysBuildProfileLibs,
245247
log,
246248
diagnosticStore,
247249
),

internal/arduino/builder/internal/detector/detector.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type SketchLibrariesDetector struct {
5353
librariesResolver *librariesresolver.Cpp
5454
useCachedLibrariesResolution bool
5555
onlyUpdateCompilationDatabase bool
56+
alwaysBuildProfileLibs bool
5657
importedLibraries libraries.List
5758
librariesResolutionResults map[string]libraryResolutionResult
5859
includeFolders paths.PathList
@@ -66,6 +67,7 @@ func NewSketchLibrariesDetector(
6667
libsResolver *librariesresolver.Cpp,
6768
useCachedLibrariesResolution bool,
6869
onlyUpdateCompilationDatabase bool,
70+
alwaysBuildProfileLibs bool,
6971
logger *logger.BuilderLogger,
7072
diagnosticStore *diagnostics.Store,
7173
) *SketchLibrariesDetector {
@@ -77,6 +79,7 @@ func NewSketchLibrariesDetector(
7779
importedLibraries: libraries.List{},
7880
includeFolders: paths.PathList{},
7981
onlyUpdateCompilationDatabase: onlyUpdateCompilationDatabase,
82+
alwaysBuildProfileLibs: alwaysBuildProfileLibs,
8083
logger: logger,
8184
diagnosticStore: diagnosticStore,
8285
}
@@ -284,6 +287,16 @@ func (l *SketchLibrariesDetector) findIncludes(
284287
l.queueSourceFilesFromFolder(sourceFileQueue, srcSubfolderPath, true /* recurse */, sketchBuildPath, sketchBuildPath)
285288
}
286289

290+
if l.alwaysBuildProfileLibs {
291+
for _, library := range l.librariesManager.FindAllInstalled() {
292+
if library.Location == libraries.User {
293+
l.logger.Info(i18n.Tr("The library %[1]s has been automatically added from sketch project.", library.Name))
294+
l.addAndBuildLibrary(sourceFileQueue, librariesBuildPath, library)
295+
l.appendIncludeFolder(cache, mergedfile.SourcePath(), "", library.SourceDir)
296+
}
297+
}
298+
}
299+
287300
for !sourceFileQueue.empty() {
288301
err := l.findIncludesUntilDone(ctx, cache, sourceFileQueue, buildProperties, librariesBuildPath, platformArch)
289302
if err != nil {

0 commit comments

Comments
 (0)