Skip to content

Commit e3f80ff

Browse files
committed
Moved RunCTags out of legacy package
1 parent 1b25b0b commit e3f80ff

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

legacy/builder/ctags_runner.go renamed to arduino/builder/preprocessor/ctags.go

Lines changed: 14 additions & 13 deletions
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,22 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
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+
2832
func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte, []byte, error) {
2933
ctagsBuildProperties := properties.NewMap()
3034
ctagsBuildProperties.Set("tools.ctags.path", "{runtime.tools.ctags.path}")
@@ -48,13 +52,10 @@ func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte,
4852
if err != nil {
4953
return nil, nil, err
5054
}
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
55+
stdout, stderr, err := proc.RunAndCaptureOutput(context.Background())
56+
57+
// Append ctags arguments to stderr
58+
args := fmt.Sprintln(strings.Join(parts, " "))
59+
stderr = append([]byte(args), stderr...)
60+
return stdout, stderr, err
6061
}

legacy/builder/container_add_prototypes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
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/types"
2425
"github.com/pkg/errors"
2526
)
@@ -60,7 +61,7 @@ func PreprocessSketchWithCtags(ctx *types.Context) error {
6061
return err
6162
}
6263

63-
ctagsStdout, ctagsStderr, err := RunCTags(targetFilePath, ctx.BuildProperties)
64+
ctagsStdout, ctagsStderr, err := preprocessor.RunCTags(targetFilePath, ctx.BuildProperties)
6465
if ctx.Verbose {
6566
ctx.WriteStderr(ctagsStderr)
6667
}

legacy/builder/test/ctags_runner_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
bldr "github.com/arduino/arduino-cli/arduino/builder"
24+
"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
2425
"github.com/arduino/arduino-cli/legacy/builder"
2526
"github.com/arduino/arduino-cli/legacy/builder/types"
2627
paths "github.com/arduino/go-paths-helper"
@@ -53,7 +54,7 @@ func ctagsRunnerTestTemplate(t *testing.T, sketchLocation *paths.Path) []byte {
5354
NoError(t, target.Parent().MkdirAll())
5455
NoError(t, target.WriteFile([]byte(source)))
5556

56-
ctagsOutput, _, err := builder.RunCTags(target, ctx.BuildProperties)
57+
ctagsOutput, _, err := preprocessor.RunCTags(target, ctx.BuildProperties)
5758
NoError(t, err)
5859

5960
return ctagsOutput

0 commit comments

Comments
 (0)