Skip to content

Commit 3eac673

Browse files
committed
Moved RunCTags out of legacy package
1 parent 91770d8 commit 3eac673

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

Diff for: legacy/builder/ctags_runner.go renamed to arduino/builder/preprocessor/ctags.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of arduino-cli.
22
//
3-
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
44
//
55
// This software is released under the GNU General Public License version 3,
66
// which covers the main part of arduino-cli.
@@ -13,18 +13,23 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package builder
16+
package preprocessor
1717

1818
import (
19-
"bytes"
19+
"context"
20+
"fmt"
2021
"strings"
2122

2223
"github.com/arduino/arduino-cli/executils"
24+
"github.com/arduino/arduino-cli/i18n"
2325
"github.com/arduino/go-paths-helper"
24-
properties "github.com/arduino/go-properties-orderedmap"
26+
"github.com/arduino/go-properties-orderedmap"
2527
"github.com/pkg/errors"
2628
)
2729

30+
var tr = i18n.Tr
31+
32+
// RunCTags performs a run of ctags on the given source file. Returns the ctags output and the stderr contents.
2833
func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte, []byte, error) {
2934
ctagsBuildProperties := properties.NewMap()
3035
ctagsBuildProperties.Set("tools.ctags.path", "{runtime.tools.ctags.path}")
@@ -48,13 +53,10 @@ func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte,
4853
if err != nil {
4954
return nil, nil, err
5055
}
51-
stdout := &bytes.Buffer{}
52-
stderr := &bytes.Buffer{}
53-
proc.RedirectStdoutTo(stdout)
54-
proc.RedirectStderrTo(stderr)
55-
if err = proc.Run(); err != nil {
56-
return nil, nil, err
57-
}
58-
_, _ = stderr.WriteString(strings.Join(parts, " "))
59-
return stdout.Bytes(), stderr.Bytes(), err
56+
stdout, stderr, err := proc.RunAndCaptureOutput(context.Background())
57+
58+
// Append ctags arguments to stderr
59+
args := fmt.Sprintln(strings.Join(parts, " "))
60+
stderr = append([]byte(args), stderr...)
61+
return stdout, stderr, err
6062
}

Diff for: legacy/builder/container_add_prototypes.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
bldr "github.com/arduino/arduino-cli/arduino/builder"
27+
"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
2728
"github.com/arduino/arduino-cli/arduino/sketch"
2829
"github.com/arduino/arduino-cli/legacy/builder/types"
2930
"github.com/arduino/go-paths-helper"
@@ -66,7 +67,7 @@ func PreprocessSketchWithCtags(ctx *types.Context) error {
6667
return err
6768
}
6869

69-
ctagsStdout, ctagsStderr, err := RunCTags(targetFilePath, ctx.BuildProperties)
70+
ctagsStdout, ctagsStderr, err := preprocessor.RunCTags(targetFilePath, ctx.BuildProperties)
7071
if ctx.Verbose {
7172
ctx.WriteStderr(ctagsStderr)
7273
}

Diff for: legacy/builder/test/ctags_runner_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
bldr "github.com/arduino/arduino-cli/arduino/builder"
23+
"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
2324
"github.com/arduino/arduino-cli/legacy/builder"
2425
paths "github.com/arduino/go-paths-helper"
2526
"github.com/stretchr/testify/require"
@@ -39,7 +40,7 @@ func ctagsRunnerTestTemplate(t *testing.T, sketchLocation *paths.Path) []byte {
3940
target := ctx.BuildPath.Join("ctags_target.cpp")
4041
NoError(t, target.WriteFile([]byte(source)))
4142

42-
ctagsOutput, _, err := builder.RunCTags(target, ctx.BuildProperties)
43+
ctagsOutput, _, err := preprocessor.RunCTags(target, ctx.BuildProperties)
4344
NoError(t, err)
4445

4546
return ctagsOutput

0 commit comments

Comments
 (0)