Skip to content

Commit

Permalink
Force cache directory creation only if strictly needed
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed May 24, 2024
1 parent 8797c63 commit 555cf7c
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions internal/arduino/builder/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
return true
}

// If there is an archived core in the current build cache, use it
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
return nil, nil, errors.New(i18n.Tr("creating core cache folder: %s", err))
}
targetArchivedCore = b.coreBuildCachePath.Join(archivedCoreName, "core.a")
if canUseArchivedCore(targetArchivedCore) {
// Update timestamp of the cache folder to extend expire time
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
return nil, nil, errors.New(i18n.Tr("creating core cache folder: %s", err))
}

// use archived core
if b.logger.Verbose() {
b.logger.Info(i18n.Tr("Using precompiled core: %[1]s", targetArchivedCore))
Expand Down Expand Up @@ -151,17 +152,23 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {

// archive core.a
if targetArchivedCore != nil && !b.onlyUpdateCompilationDatabase {
err := archiveFile.CopyTo(targetArchivedCore)
if b.logger.Verbose() {
if err == nil {
b.logger.Info(i18n.Tr("Archiving built core (caching) in: %[1]s", targetArchivedCore))
} else if os.IsNotExist(err) {
b.logger.Info(i18n.Tr("Unable to cache built core, please tell %[1]s maintainers to follow %[2]s",
b.actualPlatform,
"https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-build-the-corea-archive-file"))
} else {
if err := targetArchivedCore.Parent().MkdirAll(); err != nil {
if b.logger.Verbose() {
b.logger.Info(i18n.Tr("Error archiving built core (caching) in %[1]s: %[2]s", targetArchivedCore, err))
}
} else {
err := archiveFile.CopyTo(targetArchivedCore)
if b.logger.Verbose() {
if err == nil {
b.logger.Info(i18n.Tr("Archiving built core (caching) in: %[1]s", targetArchivedCore))
} else if os.IsNotExist(err) {
b.logger.Info(i18n.Tr("Unable to cache built core, please tell %[1]s maintainers to follow %[2]s",
b.actualPlatform,
"https://arduino.github.io/arduino-cli/latest/platform-specification/#recipes-to-build-the-corea-archive-file"))
} else {
b.logger.Info(i18n.Tr("Error archiving built core (caching) in %[1]s: %[2]s", targetArchivedCore, err))
}
}
}
}

Expand Down

0 comments on commit 555cf7c

Please sign in to comment.