Skip to content

Commit

Permalink
clang: Add verbose flag to show the direct clang invocation (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jun 2, 2021
1 parent b809e57 commit 5fb446c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func Start(args ProgramArgs) (err error) {
fmt.Println("Running clang preprocessor...")
}

pp, comments, includes, err := preprocessor.Analyze(args.inputFiles, args.clangFlags)
pp, comments, includes, err := preprocessor.Analyze(args.inputFiles, args.clangFlags, args.verbose)
if err != nil {
return err
return fmt.Errorf("issue running preprocessor: %w", err)
}

if args.verbose {
Expand Down
14 changes: 9 additions & 5 deletions preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func (e *entity) isSame(x *entity) bool {
}

// Analyze - separation preprocessor code to part
func Analyze(inputFiles, clangFlags []string) (pp []byte,
func Analyze(inputFiles, clangFlags []string, verbose bool) (pp []byte,
comments []program.Comment, includes []program.IncludeHeader, err error) {

var allItems []entity

allItems, err = analyzeFiles(inputFiles, clangFlags)
allItems, err = analyzeFiles(inputFiles, clangFlags, verbose)
if err != nil {
return
}
Expand Down Expand Up @@ -161,11 +161,11 @@ func Analyze(inputFiles, clangFlags []string) (pp []byte,
}

// analyzeFiles - analyze single file and separation preprocessor code to part
func analyzeFiles(inputFiles, clangFlags []string) (items []entity, err error) {
func analyzeFiles(inputFiles, clangFlags []string, verbose bool) (items []entity, err error) {
// See : https://clang.llvm.org/docs/CommandGuide/clang.html
// clang -E <file> Run the preprocessor stage.
var out bytes.Buffer
out, err = getPreprocessSources(inputFiles, clangFlags)
out, err = getPreprocessSources(inputFiles, clangFlags, verbose)
if err != nil {
return
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func analyzeFiles(inputFiles, clangFlags []string) (items []entity, err error) {

// See : https://clang.llvm.org/docs/CommandGuide/clang.html
// clang -E <file> Run the preprocessor stage.
func getPreprocessSources(inputFiles, clangFlags []string) (out bytes.Buffer, err error) {
func getPreprocessSources(inputFiles, clangFlags []string, verbose bool) (out bytes.Buffer, err error) {
// get temp dir
dir, err := ioutil.TempDir("", "c2go-union")
if err != nil {
Expand Down Expand Up @@ -254,6 +254,10 @@ func getPreprocessSources(inputFiles, clangFlags []string) (out bytes.Buffer, er
args = append(args, unionFileName) // All inputFiles

var outFile bytes.Buffer
if verbose {
fmt.Println("executing clang:")
fmt.Println("clang", strings.Join(args, " "))
}
cmd := exec.Command("clang", args...)
cmd.Stdout = &outFile
cmd.Stderr = &stderr
Expand Down

1 comment on commit 5fb446c

@WNora
Copy link

@WNora WNora commented on 5fb446c Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pp, comments, includes, err := preprocessor.Analyze(args.inputFiles, args.clangFlags, args.verbose)
if err != nil {
	return fmt.Errorf("issue running preprocessor: %w", err)

Please sign in to comment.