Commit f135106e authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent ba048f7c
......@@ -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
......
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment