Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(229)

Delta Between Two Patch Sets: src/pkg/go/build/build.go

Issue 8248043: code review 8248043: cmd/go: Add support for including C++ files in packages (Closed)
Left Patch Set: diff -r fb78cf8fd5b5 https://code.google.com/p/go Created 10 years, 12 months ago
Right Patch Set: diff -r e86ab7e59e50 https://code.google.com/p/go Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/godoc/index.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package build 5 package build
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3"} 294 // c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3"}
295 // and so on. 295 // and so on.
296 c.ReleaseTags = []string{"go1.1"} 296 c.ReleaseTags = []string{"go1.1"}
297 297
298 switch os.Getenv("CGO_ENABLED") { 298 switch os.Getenv("CGO_ENABLED") {
299 case "1": 299 case "1":
300 c.CgoEnabled = true 300 c.CgoEnabled = true
301 case "0": 301 case "0":
302 c.CgoEnabled = false 302 c.CgoEnabled = false
303 default: 303 default:
304 » » c.CgoEnabled = cgoEnabled[c.GOOS+"/"+c.GOARCH] 304 » » // golang.org/issue/5141
305 » » // cgo should be disabled for cross compilation builds
306 » » if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
307 » » » c.CgoEnabled = cgoEnabled[c.GOOS+"/"+c.GOARCH]
308 » » » break
309 » » }
310 » » c.CgoEnabled = false
305 } 311 }
306 312
307 return c 313 return c
308 } 314 }
309 315
310 func envOr(name, def string) string { 316 func envOr(name, def string) string {
311 s := os.Getenv(name) 317 s := os.Getenv(name)
312 if s == "" { 318 if s == "" {
313 return def 319 return def
314 } 320 }
(...skipping 25 matching lines...) Expand all
340 PkgRoot string // package install root directory ("" if unknown) 346 PkgRoot string // package install root directory ("" if unknown)
341 BinDir string // command install directory ("" if unknown) 347 BinDir string // command install directory ("" if unknown)
342 Goroot bool // package found in Go root 348 Goroot bool // package found in Go root
343 PkgObj string // installed .a file 349 PkgObj string // installed .a file
344 350
345 // Source files 351 // Source files
346 GoFiles []string // .go source files (excluding CgoFiles, TestGoF iles, XTestGoFiles) 352 GoFiles []string // .go source files (excluding CgoFiles, TestGoF iles, XTestGoFiles)
347 CgoFiles []string // .go source files that import "C" 353 CgoFiles []string // .go source files that import "C"
348 IgnoredGoFiles []string // .go source files ignored for this build 354 IgnoredGoFiles []string // .go source files ignored for this build
349 CFiles []string // .c source files 355 CFiles []string // .c source files
350 » CPPFiles []string // .cc or .cpp source files 356 » CXXFiles []string // .cc, .cpp and .cxx source files
351 » HFiles []string // .h source files 357 » HFiles []string // .h, .hh, .hpp and .hxx source files
352 SFiles []string // .s source files 358 SFiles []string // .s source files
353 SysoFiles []string // .syso system object files to add to archive 359 SysoFiles []string // .syso system object files to add to archive
354 SwigFiles []string // .swig files 360 SwigFiles []string // .swig files
355 SwigCXXFiles []string // .swigcxx files 361 SwigCXXFiles []string // .swigcxx files
356 362
357 // Cgo directives 363 // Cgo directives
364 CgoCPPFLAGS []string // Cgo CPPFLAGS directives
365 CgoCFLAGS []string // Cgo CFLAGS directives
366 CgoCXXFLAGS []string // Cgo CXXFLAGS directives
367 CgoLDFLAGS []string // Cgo LDFLAGS directives
358 CgoPkgConfig []string // Cgo pkg-config directives 368 CgoPkgConfig []string // Cgo pkg-config directives
359 CgoCFLAGS []string // Cgo CFLAGS directives
360 CgoLDFLAGS []string // Cgo LDFLAGS directives
361 369
362 // Dependency information 370 // Dependency information
363 Imports []string // imports from GoFiles, CgoFiles 371 Imports []string // imports from GoFiles, CgoFiles
364 ImportPos map[string][]token.Position // line information for Imports 372 ImportPos map[string][]token.Position // line information for Imports
365 373
366 // Test information 374 // Test information
367 TestGoFiles []string // _test.go files in package 375 TestGoFiles []string // _test.go files in package
368 TestImports []string // imports from TestGoFiles 376 TestImports []string // imports from TestGoFiles
369 TestImportPos map[string][]token.Position // line information for TestI mports 377 TestImportPos map[string][]token.Position // line information for TestI mports
370 XTestGoFiles []string // _test.go files outside pac kage 378 XTestGoFiles []string // _test.go files outside pac kage
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 ext := name[i:] 596 ext := name[i:]
589 597
590 if !ctxt.UseAllFiles && !ctxt.goodOSArchFile(name) { 598 if !ctxt.UseAllFiles && !ctxt.goodOSArchFile(name) {
591 if ext == ".go" { 599 if ext == ".go" {
592 p.IgnoredGoFiles = append(p.IgnoredGoFiles, name ) 600 p.IgnoredGoFiles = append(p.IgnoredGoFiles, name )
593 } 601 }
594 continue 602 continue
595 } 603 }
596 604
597 switch ext { 605 switch ext {
598 » » case ".go", ".c", ".cc", ".cpp", ".s", ".h", ".S", ".swig", ".sw igcxx": 606 » » case ".go", ".c", ".cc", ".cxx", ".cpp", ".s", ".h", ".hh", ".hp p", ".hxx", ".S", ".swig", ".swigcxx":
binet 2013/04/05 12:20:33 ditto: .cxx and perhaps .C too
599 // tentatively okay - read to make sure 607 // tentatively okay - read to make sure
600 case ".syso": 608 case ".syso":
601 // binary objects to add to package archive 609 // binary objects to add to package archive
602 // Likely of the form foo_windows.syso, but 610 // Likely of the form foo_windows.syso, but
603 // the name was vetted above with goodOSArchFile. 611 // the name was vetted above with goodOSArchFile.
604 p.SysoFiles = append(p.SysoFiles, name) 612 p.SysoFiles = append(p.SysoFiles, name)
605 continue 613 continue
606 default: 614 default:
607 // skip 615 // skip
608 continue 616 continue
(...skipping 22 matching lines...) Expand all
631 p.IgnoredGoFiles = append(p.IgnoredGoFiles, name ) 639 p.IgnoredGoFiles = append(p.IgnoredGoFiles, name )
632 } 640 }
633 continue 641 continue
634 } 642 }
635 643
636 // Going to save the file. For non-Go files, can stop here. 644 // Going to save the file. For non-Go files, can stop here.
637 switch ext { 645 switch ext {
638 case ".c": 646 case ".c":
639 p.CFiles = append(p.CFiles, name) 647 p.CFiles = append(p.CFiles, name)
640 continue 648 continue
641 » » case ".cc", ".cpp": 649 » » case ".cc", ".cpp", ".cxx":
binet 2013/04/05 12:20:33 ditto: .cxx and perhaps .C too.
642 » » » p.CPPFiles = append(p.CPPFiles, name) 650 » » » p.CXXFiles = append(p.CXXFiles, name)
643 » » » continue 651 » » » continue
644 » » case ".h": 652 » » case ".h", ".hh", ".hpp", ".hxx":
645 p.HFiles = append(p.HFiles, name) 653 p.HFiles = append(p.HFiles, name)
646 continue 654 continue
647 case ".s": 655 case ".s":
648 p.SFiles = append(p.SFiles, name) 656 p.SFiles = append(p.SFiles, name)
649 continue 657 continue
650 case ".S": 658 case ".S":
651 Sfiles = append(Sfiles, name) 659 Sfiles = append(Sfiles, name)
652 continue 660 continue
653 case ".swig": 661 case ".swig":
654 p.SwigFiles = append(p.SwigFiles, name) 662 p.SwigFiles = append(p.SwigFiles, name)
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return false // this one doesn't match 850 return false // this one doesn't match
843 } 851 }
844 } 852 }
845 } 853 }
846 } 854 }
847 } 855 }
848 return true // everything matches 856 return true // everything matches
849 } 857 }
850 858
851 // saveCgo saves the information from the #cgo lines in the import "C" comment. 859 // saveCgo saves the information from the #cgo lines in the import "C" comment.
852 // These lines set CFLAGS and LDFLAGS and pkg-config directives that affect 860 // These lines set CPPCFLAGS, CFLAGS, CXXFLAGS and LDFLAGS and pkg-config direct ives
853 // the way cgo's C code is built. 861 // that affect the way cgo's C code is built.
854 // 862 //
855 // TODO(rsc): This duplicates code in cgo. 863 // TODO(rsc): This duplicates code in cgo.
856 // Once the dust settles, remove this code from cgo. 864 // Once the dust settles, remove this code from cgo.
857 func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) error { 865 func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) error {
858 text := cg.Text() 866 text := cg.Text()
859 for _, line := range strings.Split(text, "\n") { 867 for _, line := range strings.Split(text, "\n") {
860 orig := line 868 orig := line
861 869
862 // Line is 870 // Line is
863 // #cgo [GOOS/GOARCH...] LDFLAGS: stuff 871 // #cgo [GOOS/GOARCH...] LDFLAGS: stuff
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 } 909 }
902 for _, arg := range args { 910 for _, arg := range args {
903 if !safeName(arg) { 911 if !safeName(arg) {
904 return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg) 912 return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg)
905 } 913 }
906 } 914 }
907 915
908 switch verb { 916 switch verb {
909 case "CFLAGS": 917 case "CFLAGS":
910 di.CgoCFLAGS = append(di.CgoCFLAGS, args...) 918 di.CgoCFLAGS = append(di.CgoCFLAGS, args...)
919 case "CPPFLAGS":
920 di.CgoCPPFLAGS = append(di.CgoCPPFLAGS, args...)
921 case "CXXFLAGS":
922 di.CgoCXXFLAGS = append(di.CgoCXXFLAGS, args...)
911 case "LDFLAGS": 923 case "LDFLAGS":
912 di.CgoLDFLAGS = append(di.CgoLDFLAGS, args...) 924 di.CgoLDFLAGS = append(di.CgoLDFLAGS, args...)
913 case "pkg-config": 925 case "pkg-config":
914 di.CgoPkgConfig = append(di.CgoPkgConfig, args...) 926 di.CgoPkgConfig = append(di.CgoPkgConfig, args...)
915 default: 927 default:
916 return fmt.Errorf("%s: invalid #cgo verb: %s", filename, orig) 928 return fmt.Errorf("%s: invalid #cgo verb: %s", filename, orig)
917 } 929 }
918 } 930 }
919 return nil 931 return nil
920 } 932 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 switch goarch { 1124 switch goarch {
1113 case "386": 1125 case "386":
1114 return "8", nil 1126 return "8", nil
1115 case "amd64": 1127 case "amd64":
1116 return "6", nil 1128 return "6", nil
1117 case "arm": 1129 case "arm":
1118 return "5", nil 1130 return "5", nil
1119 } 1131 }
1120 return "", errors.New("unsupported GOARCH " + goarch) 1132 return "", errors.New("unsupported GOARCH " + goarch)
1121 } 1133 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b