mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
ba048f7ce4
commit
f135106ec7
3 changed files with 11 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ FILE_PREFIXES="anonunion issue8478"
|
||||||
RM=
|
RM=
|
||||||
for FP in $FILE_PREFIXES
|
for FP in $FILE_PREFIXES
|
||||||
do
|
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"
|
RM="${RM} ${FP}_defs.go"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -326,6 +326,9 @@ The following options are available when running cgo directly:
|
||||||
Write out input file in Go syntax replacing C package
|
Write out input file in Go syntax replacing C package
|
||||||
names with real values. Used to generate files in the
|
names with real values. Used to generate files in the
|
||||||
syscall package when bootstrapping a new target.
|
syscall package when bootstrapping a new target.
|
||||||
|
-srcdir directory
|
||||||
|
Find the Go input files, listed on the command line,
|
||||||
|
in directory.
|
||||||
-objdir directory
|
-objdir directory
|
||||||
Put all generated files in directory.
|
Put all generated files in directory.
|
||||||
-importpath string
|
-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.
|
// 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 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 objDir = flag.String("objdir", "", "object directory")
|
||||||
var importPath = flag.String("importpath", "", "import path of package being built (for comments in generated files)")
|
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")
|
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.
|
// Use the beginning of the md5 of the input to disambiguate.
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
for _, input := range goFiles {
|
for _, input := range goFiles {
|
||||||
|
if *srcDir != "" {
|
||||||
|
input = filepath.Join(*srcDir, input)
|
||||||
|
}
|
||||||
f, err := os.Open(input)
|
f, err := os.Open(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalf("%s", err)
|
fatalf("%s", err)
|
||||||
|
|
@ -267,6 +271,9 @@ func main() {
|
||||||
|
|
||||||
fs := make([]*File, len(goFiles))
|
fs := make([]*File, len(goFiles))
|
||||||
for i, input := range goFiles {
|
for i, input := range goFiles {
|
||||||
|
if *srcDir != "" {
|
||||||
|
input = filepath.Join(*srcDir, input)
|
||||||
|
}
|
||||||
f := new(File)
|
f := new(File)
|
||||||
f.ReadGo(input)
|
f.ReadGo(input)
|
||||||
f.DiscardCgoDirectives()
|
f.DiscardCgoDirectives()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue