From: Ian Lance Taylor Date: Sun, 30 Oct 2016 16:30:47 +0000 (-0400) Subject: cmd/cgo: add -srcdir option X-Git-Tag: go1.8beta1~450 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f135106ec7cf68b47a5b83a1c2b5dd7eda0d614c;p=gostls13.git cmd/cgo: add -srcdir option 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 TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- diff --git a/misc/cgo/testgodefs/test.bash b/misc/cgo/testgodefs/test.bash index 14235c05cb..a82ff9328f 100755 --- a/misc/cgo/testgodefs/test.bash +++ b/misc/cgo/testgodefs/test.bash @@ -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 diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index e5d288167e..85441e61c0 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -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 diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 52cffd6520..77b45a5aed 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -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()