Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/oracle: describe operation doesn't work with import "C" statements #13971

Open
bruno-medeiros opened this issue Jan 15, 2016 · 2 comments
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@bruno-medeiros
Copy link

Take this source for file /devel/go-workspace/src/foo/foo.go:

package main

/*
#include <time.h>
#include <stdlib.h>
*/
import "C"
import "fmt"

func Random() int {
    return int(C.rand())
}

func Seed() {
    C.srand(C.uint(C.time(nil)))
}

func main() {
  Seed()
  fmt.Print(Random())
}

Then trying to run oracle describe doesn't work:
oracle -pos=/devel/go-workspace/src/foo/foo.go:#8,#8 describe ___
This results in error:
oracle: no buildable Go source files in /devel/go-workspace/src/foo

@gopherbot
Copy link

CL https://golang.org/cl/37856 mentions this issue.

@joegrasse
Copy link

@alandonovan @ianlancetaylor Looks like there has been a CL submitted but no progress since then. Just curious what the status is on this?

FrankReh added a commit to FrankReh/tools that referenced this issue Mar 13, 2018
The logic in guru for collecting files for the definition and describe
modes had expressly avoided go files that included the import "C"
statement (known as cgo files) by setting CgoEnabled to false.

Cgo files normally get handed off to the cgo command, requiring a temp
directory and separate processes, which is much more time consuming than
having the go files parsed directly by the loader.

With this change, the cgo files are collected but then they are moved to
the go files list so the expensive cgo processing is avoided and the cgo
files are parsed along with the normal go files.

Guru already set a loader AllowErrors flag to get as much of the ASTs
returned as possible.  Failures in cgo file parsing due to cgo not
having been run is not expected to make the guru results worse.  The
only extra time should be due to extra files now being parsed, generally
making the guru search more complete.

Adds a testdata/cgo/cgo.go test case.

Fixes golang/go#13971
Fixes golang/go#15710
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
zchee pushed a commit to zchee/golang-tools that referenced this issue Aug 14, 2021
The logic in guru for collecting files for the definition and describe
modes had expressly avoided go files that included the import "C"
statement (known as cgo files) by setting CgoEnabled to false.

Cgo files normally get handed off to the cgo command, requiring a temp
directory and separate processes, which is much more time consuming than
having the go files parsed directly by the loader.

With this change, the cgo files are collected but then they are moved to
the go files list so the expensive cgo processing is avoided and the cgo
files are parsed along with the normal go files.

Guru already set a loader AllowErrors flag to get as much of the ASTs
returned as possible.  Failures in cgo file parsing due to cgo not
having been run is not expected to make the guru results worse.  The
only extra time should be due to extra files now being parsed, generally
making the guru search more complete.

Adds a testdata/cgo/cgo.go test case.  Increases the go test time for
guru about 2%.  Because the testdata/lib package is used, the other
referrers golden files are modified.  (The cgo test case could use its
own version of the library, thereby keeping other referrers unaffected.)

Fixes golang/go#13971
Fixes golang/go#15710

Change-Id: I2962bdf2cda48e12a42ca187db97ef2cd760370c
zchee pushed a commit to zchee/golang-tools that referenced this issue Jun 23, 2023
The logic in guru for collecting files for the definition and describe
modes had expressly avoided go files that included the import "C"
statement (known as cgo files) by setting CgoEnabled to false.

Cgo files normally get handed off to the cgo command, requiring a temp
directory and separate processes, which is much more time consuming than
having the go files parsed directly by the loader.

With this change, the cgo files are collected but then they are moved to
the go files list so the expensive cgo processing is avoided and the cgo
files are parsed along with the normal go files.

Guru already set a loader AllowErrors flag to get as much of the ASTs
returned as possible.  Failures in cgo file parsing due to cgo not
having been run is not expected to make the guru results worse.  The
only extra time should be due to extra files now being parsed, generally
making the guru search more complete.

Adds a testdata/cgo/cgo.go test case.  Increases the go test time for
guru about 2%.  Because the testdata/lib package is used, the other
referrers golden files are modified.  (The cgo test case could use its
own version of the library, thereby keeping other referrers unaffected.)

Fixes golang/go#13971
Fixes golang/go#15710

Change-Id: I2962bdf2cda48e12a42ca187db97ef2cd760370c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants