Skip to content

Commit 046eb74

Browse files
committed
Always add to the build the libraries requested in the active sketch profile.
This will improve sketch compile time.
1 parent 0c5888f commit 046eb74

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

commands/instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
380380
}
381381
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
382382
Path: libDir,
383-
Location: libraries.Unmanaged,
383+
Location: libraries.Profile,
384384
IsSingleLibrary: true,
385385
})
386386
continue
@@ -428,7 +428,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
428428

429429
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
430430
Path: libRoot,
431-
Location: libraries.User,
431+
Location: libraries.Profile,
432432
})
433433
}
434434
}

commands/service_compile.go

Lines changed: 4 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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ func (l *SketchLibrariesDetector) findIncludes(
284284
l.queueSourceFilesFromFolder(sourceFileQueue, srcSubfolderPath, true /* recurse */, sketchBuildPath, sketchBuildPath)
285285
}
286286

287+
for _, library := range l.librariesManager.FindAllInstalled() {
288+
if library.Location == libraries.Profile {
289+
l.logger.Info(i18n.Tr("The library %[1]s has been automatically added from sketch project.", library.Name))
290+
l.addAndBuildLibrary(sourceFileQueue, librariesBuildPath, library)
291+
l.appendIncludeFolder(cache, mergedfile.SourcePath(), "", library.SourceDir)
292+
}
293+
}
294+
287295
for !sourceFileQueue.empty() {
288296
err := l.findIncludesUntilDone(ctx, cache, sourceFileQueue, buildProperties, librariesBuildPath, platformArch)
289297
if err != nil {

internal/arduino/libraries/libraries_location.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
// Unmanaged is for libraries set manually by the user in the CLI command or from the gRPC function.
4141
// Ideally it's used for `libraries` outside folders managed by the CLI.
4242
Unmanaged
43+
// Profile is for libraries that are part of a sketch profile
44+
Profile
4345
)
4446

4547
func (d *LibraryLocation) String() string {
@@ -54,6 +56,8 @@ func (d *LibraryLocation) String() string {
5456
return "user"
5557
case Unmanaged:
5658
return "unmanaged"
59+
case Profile:
60+
return "profile"
5761
default:
5862
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
5963
}
@@ -86,6 +90,9 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
8690
case "unmanaged":
8791
*d = Unmanaged
8892
return nil
93+
case "profile":
94+
*d = Profile
95+
return nil
8996
default:
9097
return errors.New(i18n.Tr("invalid library location: %s", s))
9198
}
@@ -104,6 +111,8 @@ func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
104111
return rpc.LibraryLocation_LIBRARY_LOCATION_USER
105112
case Unmanaged:
106113
return rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED
114+
case Profile:
115+
return rpc.LibraryLocation_LIBRARY_LOCATION_PROFILE
107116
default:
108117
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
109118
}
@@ -122,6 +131,8 @@ func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
122131
return User
123132
case rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED:
124133
return Unmanaged
134+
case rpc.LibraryLocation_LIBRARY_LOCATION_PROFILE:
135+
return Profile
125136
default:
126137
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
127138
}

rpc/cc/arduino/cli/commands/v1/lib.pb.go

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/cli/commands/v1/lib.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ enum LibraryLocation {
379379
LIBRARY_LOCATION_REFERENCED_PLATFORM_BUILTIN = 3;
380380
// Outside the `libraries` folders managed by the CLI.
381381
LIBRARY_LOCATION_UNMANAGED = 4;
382+
// Library is part of the sketch profile.
383+
LIBRARY_LOCATION_PROFILE = 5;
382384
}
383385

384386
message ZipLibraryInstallRequest {

0 commit comments

Comments
 (0)