From 5fb446c6c3cd59b8ed6e1c4e1e59a88fc7ce0974 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Wed, 2 Jun 2021 06:41:39 -0700 Subject: [PATCH] clang: Add verbose flag to show the direct clang invocation (#882) --- main.go | 4 ++-- preprocessor/preprocessor.go | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index c0288c54f..afb31e1dd 100644 --- a/main.go +++ b/main.go @@ -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 { diff --git a/preprocessor/preprocessor.go b/preprocessor/preprocessor.go index 1b009e045..2752fb556 100644 --- a/preprocessor/preprocessor.go +++ b/preprocessor/preprocessor.go @@ -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 } @@ -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 Run the preprocessor stage. var out bytes.Buffer - out, err = getPreprocessSources(inputFiles, clangFlags) + out, err = getPreprocessSources(inputFiles, clangFlags, verbose) if err != nil { return } @@ -210,7 +210,7 @@ func analyzeFiles(inputFiles, clangFlags []string) (items []entity, err error) { // See : https://clang.llvm.org/docs/CommandGuide/clang.html // clang -E 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 { @@ -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