Skip to content

Commit 1c9864d

Browse files
remove LineOffset from Context
1 parent 296dffd commit 1c9864d

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

Diff for: arduino/builder/builder.go

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type Builder struct {
6969
// Sizer results
7070
executableSectionsSize ExecutablesFileSections
7171

72+
// C++ Parsing
73+
lineOffset int
74+
7275
*BuildOptionsManager
7376
}
7477

Diff for: arduino/builder/export_cmake.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (b *Builder) ExportProjectCMake(
3939
sketchError bool, // Was there an error while compiling the sketch?
4040
importedLibraries libraries.List,
4141
includeFolders paths.PathList,
42-
lineOffset int,
4342
) error {
4443
// copies the contents of the file named src to the file named
4544
// by dst. The file will be created if it does not already exist. If the
@@ -242,7 +241,7 @@ func (b *Builder) ExportProjectCMake(
242241
fmt.Println(err)
243242
}
244243

245-
if err := b.PreprocessSketch(includeFolders, lineOffset); err != nil {
244+
if err := b.PreprocessSketch(includeFolders); err != nil {
246245
return err
247246
}
248247

Diff for: arduino/builder/preprocess_sketch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
)
2222

2323
// PreprocessSketch fixdoc
24-
func (b *Builder) PreprocessSketch(includes paths.PathList, lineOffset int) error {
24+
func (b *Builder) PreprocessSketch(includes paths.PathList) error {
2525
// In the future we might change the preprocessor
2626
normalOutput, verboseOutput, err := preprocessor.PreprocessSketchWithCtags(
27-
b.sketch, b.buildPath, includes, lineOffset,
27+
b.sketch, b.buildPath, includes, b.lineOffset,
2828
b.buildProperties, b.onlyUpdateCompilationDatabase,
2929
)
3030
if b.logger.Verbose() {

Diff for: arduino/builder/sketch.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,28 @@ func (b *Builder) Sketch() *sketch.Sketch {
4747
// PrepareSketchBuildPath copies the sketch source files in the build path.
4848
// The .ino files are merged together to create a .cpp file (by the way, the
4949
// .cpp file still needs to be Arduino-preprocessed to compile).
50-
func (b *Builder) PrepareSketchBuildPath() (int, error) {
50+
func (b *Builder) PrepareSketchBuildPath() error {
5151
if err := b.sketchBuildPath.MkdirAll(); err != nil {
52-
return 0, errors.Wrap(err, tr("unable to create a folder to save the sketch"))
52+
return errors.Wrap(err, tr("unable to create a folder to save the sketch"))
5353
}
5454

5555
offset, mergedSource, err := b.sketchMergeSources(b.sourceOverrides)
5656
if err != nil {
57-
return 0, err
57+
return err
5858
}
5959

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

6565
if err := b.sketchCopyAdditionalFiles(b.sketchBuildPath, b.sourceOverrides); err != nil {
66-
return 0, err
66+
return err
6767
}
6868

69-
return offset, nil
69+
b.lineOffset = offset
70+
71+
return nil
7072
}
7173

7274
// sketchMergeSources merges all the .ino source files included in a sketch to produce

Diff for: legacy/builder/builder.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *Builder) Run(ctx *types.Context) error {
3636
return err
3737
}
3838

39-
var _err, mainErr error
39+
var mainErr error
4040
commands := []types.Command{
4141
containerBuildOptions(ctx),
4242

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

4747
types.BareCommand(func(ctx *types.Context) error {
48-
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
49-
return _err
48+
return ctx.Builder.PrepareSketchBuildPath()
5049
}),
5150

5251
logIfVerbose(false, tr("Detecting libraries used...")),
@@ -191,7 +190,6 @@ func (s *Builder) Run(ctx *types.Context) error {
191190
mainErr != nil,
192191
ctx.SketchLibrariesDetector.ImportedLibraries(),
193192
ctx.SketchLibrariesDetector.IncludeFolders(),
194-
ctx.LineOffset,
195193
)
196194
}),
197195

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

220218
func preprocessSketchCommand(ctx *types.Context) types.BareCommand {
221219
return func(ctx *types.Context) error {
222-
return ctx.Builder.PreprocessSketch(ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset)
220+
return ctx.Builder.PreprocessSketch(ctx.SketchLibrariesDetector.IncludeFolders())
223221
}
224222
}
225223

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

233-
var _err error
234231
commands := []types.Command{
235232
containerBuildOptions(ctx),
236233

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

241238
types.BareCommand(func(ctx *types.Context) error {
242-
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
243-
return _err
239+
return ctx.Builder.PrepareSketchBuildPath()
244240
}),
245241

246242
findIncludes(ctx),

Diff for: legacy/builder/types/context.go

-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,4 @@ type Context struct {
4444
CoreObjectsFiles paths.PathList
4545
LibrariesObjectFiles paths.PathList
4646
SketchObjectFiles paths.PathList
47-
48-
// C++ Parsing
49-
LineOffset int
5047
}

0 commit comments

Comments
 (0)