Skip to content

Commit

Permalink
remove LineOffset from Context
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 12, 2023
1 parent 0c19451 commit 42be1cb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type Builder struct {
// Sizer results
executableSectionsSize ExecutablesFileSections

// C++ Parsing
lineOffset int

*BuildOptionsManager
}

Expand Down
3 changes: 1 addition & 2 deletions arduino/builder/export_cmake.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (b *Builder) ExportProjectCMake(
sketchError bool, // Was there an error while compiling the sketch?
importedLibraries libraries.List,
includeFolders paths.PathList,
lineOffset int,
) error {
// copies the contents of the file named src to the file named
// by dst. The file will be created if it does not already exist. If the
Expand Down Expand Up @@ -242,7 +241,7 @@ func (b *Builder) ExportProjectCMake(
fmt.Println(err)
}

if err := b.PreprocessSketch(includeFolders, lineOffset); err != nil {
if err := b.PreprocessSketch(includeFolders); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions arduino/builder/preprocess_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
)

// PreprocessSketch fixdoc
func (b *Builder) PreprocessSketch(includes paths.PathList, lineOffset int) error {
func (b *Builder) PreprocessSketch(includes paths.PathList) error {
// In the future we might change the preprocessor
normalOutput, verboseOutput, err := preprocessor.PreprocessSketchWithCtags(
b.sketch, b.buildPath, includes, lineOffset,
b.sketch, b.buildPath, includes, b.lineOffset,
b.buildProperties, b.onlyUpdateCompilationDatabase,
)
if b.logger.Verbose() {
Expand Down
14 changes: 8 additions & 6 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,28 @@ func (b *Builder) Sketch() *sketch.Sketch {
// PrepareSketchBuildPath copies the sketch source files in the build path.
// The .ino files are merged together to create a .cpp file (by the way, the
// .cpp file still needs to be Arduino-preprocessed to compile).
func (b *Builder) PrepareSketchBuildPath() (int, error) {
func (b *Builder) PrepareSketchBuildPath() error {
if err := b.sketchBuildPath.MkdirAll(); err != nil {
return 0, errors.Wrap(err, tr("unable to create a folder to save the sketch"))
return errors.Wrap(err, tr("unable to create a folder to save the sketch"))
}

offset, mergedSource, err := b.sketchMergeSources(b.sourceOverrides)
if err != nil {
return 0, err
return err
}

destFile := b.sketchBuildPath.Join(b.sketch.MainFile.Base() + ".cpp")
if err := destFile.WriteFile([]byte(mergedSource)); err != nil {
return 0, err
return err
}

if err := b.sketchCopyAdditionalFiles(b.sketchBuildPath, b.sourceOverrides); err != nil {
return 0, err
return err
}

return offset, nil
b.lineOffset = offset

return nil
}

// sketchMergeSources merges all the .ino source files included in a sketch to produce
Expand Down
12 changes: 4 additions & 8 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Builder) Run(ctx *types.Context) error {
return err
}

var _err, mainErr error
var mainErr error
commands := []types.Command{
containerBuildOptions(ctx),

Expand All @@ -45,8 +45,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
return _err
return ctx.Builder.PrepareSketchBuildPath()
}),

logIfVerbose(false, tr("Detecting libraries used...")),
Expand Down Expand Up @@ -191,7 +190,6 @@ func (s *Builder) Run(ctx *types.Context) error {
mainErr != nil,
ctx.SketchLibrariesDetector.ImportedLibraries(),
ctx.SketchLibrariesDetector.IncludeFolders(),
ctx.LineOffset,
)
}),

Expand Down Expand Up @@ -219,7 +217,7 @@ func (s *Builder) Run(ctx *types.Context) error {

func preprocessSketchCommand(ctx *types.Context) types.BareCommand {
return func(ctx *types.Context) error {
return ctx.Builder.PreprocessSketch(ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset)
return ctx.Builder.PreprocessSketch(ctx.SketchLibrariesDetector.IncludeFolders())
}
}

Expand All @@ -230,7 +228,6 @@ func (s *Preprocess) Run(ctx *types.Context) error {
return err
}

var _err error
commands := []types.Command{
containerBuildOptions(ctx),

Expand All @@ -239,8 +236,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
return _err
return ctx.Builder.PrepareSketchBuildPath()
}),

findIncludes(ctx),
Expand Down
3 changes: 0 additions & 3 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ type Context struct {
CoreObjectsFiles paths.PathList
LibrariesObjectFiles paths.PathList
SketchObjectFiles paths.PathList

// C++ Parsing
LineOffset int
}

0 comments on commit 42be1cb

Please sign in to comment.