Skip to content

Commit

Permalink
rename diagnostic manager in Store
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Jan 31, 2024
1 parent e6c58c4 commit 06ee3bd
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 53 deletions.
11 changes: 5 additions & 6 deletions internal/arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/arduino/arduino-cli/internal/arduino/builder/internal/compilation"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/detector"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnosticmanager"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/logger"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/progress"
Expand Down Expand Up @@ -94,7 +93,7 @@ type Builder struct {

toolEnv []string

diagnosticsManager *diagnosticmanager.Manager
diagnosticStore *diagnostics.Store
}

// buildArtifacts contains the result of various build
Expand Down Expand Up @@ -195,7 +194,7 @@ func NewBuilder(
logger.Warn(string(verboseOut))
}

diagnosticmanager := diagnosticmanager.New()
diagnosticStore := diagnostics.NewStore()
b := &Builder{
sketch: sk,
buildProperties: buildProperties,
Expand Down Expand Up @@ -228,13 +227,13 @@ func NewBuilder(
buildProperties.GetPath("runtime.platform.path"),
buildProperties.GetPath("build.core.path"), // TODO can we buildCorePath ?
),
diagnosticsManager: diagnosticmanager,
diagnosticStore: diagnosticStore,
libsDetector: detector.NewSketchLibrariesDetector(
libsManager, libsResolver,
useCachedLibrariesResolution,
onlyUpdateCompilationDatabase,
logger,
diagnosticmanager,
diagnosticStore,
),
}
return b, nil
Expand Down Expand Up @@ -262,7 +261,7 @@ func (b *Builder) ImportedLibraries() libraries.List {

// CompilerDiagnostics returns the parsed compiler diagnostics
func (b *Builder) CompilerDiagnostics() diagnostics.Diagnostics {
return b.diagnosticsManager.CompilerDiagnostics()
return b.diagnosticStore.Diagnostics()
}

// Preprocess fixdoc
Expand Down
6 changes: 3 additions & 3 deletions internal/arduino/builder/compilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func (b *Builder) compileFileWithRecipe(
b.logger.WriteStderr(commandStderr.Bytes())

// Parse the output of the compiler to gather errors and warnings...
if b.diagnosticsManager != nil {
b.diagnosticsManager.Parse(command.GetArgs(), commandStdout.Bytes())
b.diagnosticsManager.Parse(command.GetArgs(), commandStderr.Bytes())
if b.diagnosticStore != nil {
b.diagnosticStore.Parse(command.GetArgs(), commandStdout.Bytes())
b.diagnosticStore.Parse(command.GetArgs(), commandStderr.Bytes())
}

// ...and then return the error
Expand Down
12 changes: 6 additions & 6 deletions internal/arduino/builder/internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"strings"
"time"

"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnosticmanager"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/logger"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/preprocessor"
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils"
Expand Down Expand Up @@ -58,7 +58,7 @@ type SketchLibrariesDetector struct {
librariesResolutionResults map[string]libraryResolutionResult
includeFolders paths.PathList
logger *logger.BuilderLogger
diagnosticManager *diagnosticmanager.Manager
diagnosticStore *diagnostics.Store
}

// NewSketchLibrariesDetector todo
Expand All @@ -68,7 +68,7 @@ func NewSketchLibrariesDetector(
useCachedLibrariesResolution bool,
onlyUpdateCompilationDatabase bool,
logger *logger.BuilderLogger,
diagnosticManager *diagnosticmanager.Manager,
diagnosticStore *diagnostics.Store,
) *SketchLibrariesDetector {
return &SketchLibrariesDetector{
librariesManager: lm,
Expand All @@ -79,7 +79,7 @@ func NewSketchLibrariesDetector(
includeFolders: paths.PathList{},
onlyUpdateCompilationDatabase: onlyUpdateCompilationDatabase,
logger: logger,
diagnosticManager: diagnosticManager,
diagnosticStore: diagnosticStore,
}
}

Expand Down Expand Up @@ -392,11 +392,11 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
// deleted, so hopefully the next compilation will succeed.
return errors.New(tr("Internal error in cache"))
}
l.diagnosticManager.Parse(result.Args(), result.Stderr())
l.diagnosticStore.Parse(result.Args(), result.Stderr())
l.logger.WriteStderr(result.Stderr())
return err
}
l.diagnosticManager.Parse(preprocFirstResult.Args(), preprocFirstResult.Stderr())
l.diagnosticStore.Parse(preprocFirstResult.Args(), preprocFirstResult.Stderr())
l.logger.WriteStderr(preprocFirstResult.Stderr())
return preprocErr
}
Expand Down

This file was deleted.

34 changes: 34 additions & 0 deletions internal/arduino/builder/internal/diagnostics/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package diagnostics

import (
"github.com/sirupsen/logrus"
)

type Store struct {
results Diagnostics
}

func NewStore() *Store {
return &Store{}
}

func (m *Store) Parse(cmdline []string, out []byte) {
compiler := DetectCompilerFromCommandLine(
cmdline,
false, // at the moment compiler-probing is not required
)
if compiler == nil {
logrus.Warnf("Could not detect compiler from: %s", cmdline)
return
}
diags, err := ParseCompilerOutput(compiler, out)
if err != nil {
logrus.Warnf("Error parsing compiler output: %s", err)
return
}
m.results = append(m.results, diags...)
}

func (m *Store) Diagnostics() Diagnostics {
return m.results
}
2 changes: 1 addition & 1 deletion internal/arduino/builder/preprocess_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (b *Builder) preprocessSketch(includes paths.PathList) error {
} else {
b.logger.WriteStdout(result.Stderr())
}
b.diagnosticsManager.Parse(result.Args(), result.Stderr())
b.diagnosticStore.Parse(result.Args(), result.Stderr())

return err
}

0 comments on commit 06ee3bd

Please sign in to comment.