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.
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
1818import (
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+
2832func 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}
0 commit comments