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

gopackagesdriver includes non-Go files as GoFiles and CompiledGoFiles #3326

Closed
michaelarusso opened this issue Oct 19, 2022 · 2 comments · Fixed by #3327
Closed

gopackagesdriver includes non-Go files as GoFiles and CompiledGoFiles #3326

michaelarusso opened this issue Oct 19, 2022 · 2 comments · Fixed by #3327

Comments

@michaelarusso
Copy link
Contributor

What version of rules_go are you using?

0.34.0

What version of gazelle are you using?

0.26.0

What version of Bazel are you using?

5.3.2

Does this issue reproduce with the latest releases of all the above?

n/a

What operating system and processor architecture are you using?

macOS Monterey / M1

Any other potentially useful information about your toolchain?

n/a

What did you do?

Using gopackagesdriver.sh with the following contents:

#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"

This causes parse errors with the gopls language server causing go-to functionality to fail in VsCode. See golang/go#56208.

When running echo {} | ./tools/gopackagesdriver.sh file=path/to/file/with/problem.go, C source files are included in the GoFiles and CompiledGoFiles.

An example is when gocv pkg (https://github.com/hybridgroup/gocv) is used. Here is the output for one file where this issue appears:

{
  "ID": "@io_gocv_x_gocv//:gocv",
  "Name": "gocv",
  "PkgPath": "gocv.io/x/gocv",
  "GoFiles": [
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/asyncarray.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn_ext.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/gocv.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui_gocv.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_colorcodes.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_colorcodes_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/mat_noprofile.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio_string.go"
  ],
  "CompiledGoFiles": [
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/asyncarray.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/calib3d_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/core_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn_ext.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/dnn_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/features2d_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/gocv.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui_gocv.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/highgui_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgcodecs.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_colorcodes.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_colorcodes_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/imgproc_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/mat_noprofile.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/objdetect.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/photo_string.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/svd.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/version.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/video.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.cpp",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.go",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio.h",
    "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/external/io_gocv_x_gocv/videoio_string.go"
  ],
  "ExportFile": "/<usr>/.cache/bazel/_bazel_russomichael/0961bbf0241ac3833db3822167eb7327/execroot/__main__/bazel-out/k8-fastbuild/bin/external/io_gocv_x_gocv/gocv.x",
  "Imports": {
    "errors": "@io_bazel_rules_go//stdlib:errors",
    "fmt": "@io_bazel_rules_go//stdlib:fmt",
    "image": "@io_bazel_rules_go//stdlib:image",
    "image/color": "@io_bazel_rules_go//stdlib:image/color",
    "reflect": "@io_bazel_rules_go//stdlib:reflect",
    "runtime": "@io_bazel_rules_go//stdlib:runtime",
    "strconv": "@io_bazel_rules_go//stdlib:strconv",
    "sync": "@io_bazel_rules_go//stdlib:sync",
    "unsafe": "@io_bazel_rules_go//stdlib:unsafe"
  }
}

What did you expect to see?

Only .go files in the GoFiles and CompiledGoFiles list and not .h or .cpp files, with the non-Go files potentially in an OtherFiles list.

What did you see instead?

.h and .cpp files included GoFiles and CompiledGoFiles lists.

@fmeum
Copy link
Member

fmeum commented Oct 19, 2022

Thanks for the report, that does indeed look incorrect.

The logic that collects these files lives in https://github.com/bazelbuild/rules_go/blob/223e03fbbc74c5cfb3821d7db5aafa759555abad/go/tools/gopackagesdriver/aspect.bzl#L53.

@michaelarusso Given that you seem to have everything set up to test this locally, would you be interested in playing with these filters to make them work and submit a PR? I could review the PR and help out if you get stuck.

@michaelarusso
Copy link
Contributor Author

@fmeum Yeah I can take a first attempt at fixing this. Thanks for the pointer of where the logic is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants