@@ -142,6 +142,15 @@ func Build(pkgName, outpath string, options *compileopts.Options) error {
142142 return err
143143 }
144144
145+ if options .PrintJSON {
146+ b , err := json .MarshalIndent (config , "" , " " )
147+ if err != nil {
148+ handleCompilerError (err )
149+ }
150+ fmt .Printf ("%s\n " , string (b ))
151+ return nil
152+ }
153+
145154 return builder .Build (pkgName , outpath , config , func (result builder.BuildResult ) error {
146155 if outpath == "" {
147156 if strings .HasSuffix (pkgName , ".go" ) {
@@ -1213,13 +1222,13 @@ func main() {
12131222 llvmFeatures := flag .String ("llvm-features" , "" , "comma separated LLVM features to enable" )
12141223 cpuprofile := flag .String ("cpuprofile" , "" , "cpuprofile output" )
12151224
1216- var flagJSON , flagDeps , flagTest * bool
1217- if command == "help" || command == "list" || command == "info" {
1218- flagJSON = flag .Bool ( "json" , false , "print data in JSON format" )
1225+ var flagJSON , flagDeps , flagTest bool
1226+ if command == "help" || command == "list" || command == "info" || command == "build" {
1227+ flag .BoolVar ( & flagJSON , "json" , false , "print data in JSON format" )
12191228 }
12201229 if command == "help" || command == "list" {
1221- flagDeps = flag .Bool ( "deps" , false , "supply -deps flag to go list" )
1222- flagTest = flag .Bool ( "test" , false , "supply -test flag to go list" )
1230+ flag .BoolVar ( & flagDeps , "deps" , false , "supply -deps flag to go list" )
1231+ flag .BoolVar ( & flagTest , "test" , false , "supply -test flag to go list" )
12231232 }
12241233 var outpath string
12251234 if command == "help" || command == "build" || command == "build-library" || command == "test" {
@@ -1296,6 +1305,7 @@ func main() {
12961305 Programmer : * programmer ,
12971306 OpenOCDCommands : ocdCommands ,
12981307 LLVMFeatures : * llvmFeatures ,
1308+ PrintJSON : flagJSON ,
12991309 }
13001310 if * printCommands {
13011311 options .PrintCommands = printCommand
@@ -1532,7 +1542,7 @@ func main() {
15321542 fmt .Fprintln (os .Stderr , err )
15331543 os .Exit (1 )
15341544 }
1535- if * flagJSON {
1545+ if flagJSON {
15361546 json , _ := json .MarshalIndent (struct {
15371547 GOROOT string `json:"goroot"`
15381548 GOOS string `json:"goos"`
@@ -1571,13 +1581,13 @@ func main() {
15711581 os .Exit (1 )
15721582 }
15731583 var extraArgs []string
1574- if * flagJSON {
1584+ if flagJSON {
15751585 extraArgs = append (extraArgs , "-json" )
15761586 }
1577- if * flagDeps {
1587+ if flagDeps {
15781588 extraArgs = append (extraArgs , "-deps" )
15791589 }
1580- if * flagTest {
1590+ if flagTest {
15811591 extraArgs = append (extraArgs , "-test" )
15821592 }
15831593 cmd , err := loader .List (config , extraArgs , flag .Args ())
0 commit comments