]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: add -srcdir option
authorIan Lance Taylor <iant@golang.org>
Sun, 30 Oct 2016 16:30:47 +0000 (12:30 -0400)
committerIan Lance Taylor <iant@golang.org>
Sun, 30 Oct 2016 19:14:08 +0000 (19:14 +0000)
This is convenient for direct use of `go tool cgo`. We can also use it
from the go tool to reduce the length of the file names that cgo
generates.

Update #17070.

Change-Id: I8466a0a2cc68a732d17d07319e303497715bac8c
Reviewed-on: https://go-review.googlesource.com/32354
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
misc/cgo/testgodefs/test.bash
src/cmd/cgo/doc.go
src/cmd/cgo/main.go

index 14235c05cb46ecb8e3c4cc3726a5935bad1ed0a9..a82ff9328fe46a205b948d05c6f523e750b03a54 100755 (executable)
@@ -12,7 +12,7 @@ FILE_PREFIXES="anonunion issue8478"
 RM=
 for FP in $FILE_PREFIXES
 do
-  go tool cgo -godefs ${FP}.go > ${FP}_defs.go
+  go tool cgo -godefs -srcdir . ${FP}.go > ${FP}_defs.go
   RM="${RM} ${FP}_defs.go"
 done
 
index e5d288167ecc2562486bed318eb03c665232757d..85441e61c04ce7c36d2e9c2d4ee55b06094a9052 100644 (file)
@@ -326,6 +326,9 @@ The following options are available when running cgo directly:
                Write out input file in Go syntax replacing C package
                names with real values. Used to generate files in the
                syscall package when bootstrapping a new target.
+       -srcdir directory
+               Find the Go input files, listed on the command line,
+               in directory.
        -objdir directory
                Put all generated files in directory.
        -importpath string
index 52cffd6520c251ba34ed057b486e871aa0351466..77b45a5aed76e209aa06dfe03935071b046b41c8 100644 (file)
@@ -178,6 +178,7 @@ var dynlinker = flag.Bool("dynlinker", false, "record dynamic linker information
 // constant values used in the host's C libraries and system calls.
 var godefs = flag.Bool("godefs", false, "for bootstrap: write Go definitions for C file to standard output")
 
+var srcDir = flag.String("srcdir", "", "source directory")
 var objDir = flag.String("objdir", "", "object directory")
 var importPath = flag.String("importpath", "", "import path of package being built (for comments in generated files)")
 var exportHeader = flag.String("exportheader", "", "where to write export header if any exported functions")
@@ -256,6 +257,9 @@ func main() {
        // Use the beginning of the md5 of the input to disambiguate.
        h := md5.New()
        for _, input := range goFiles {
+               if *srcDir != "" {
+                       input = filepath.Join(*srcDir, input)
+               }
                f, err := os.Open(input)
                if err != nil {
                        fatalf("%s", err)
@@ -267,6 +271,9 @@ func main() {
 
        fs := make([]*File, len(goFiles))
        for i, input := range goFiles {
+               if *srcDir != "" {
+                       input = filepath.Join(*srcDir, input)
+               }
                f := new(File)
                f.ReadGo(input)
                f.DiscardCgoDirectives()