You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When C source code compiled by CGo produces warnings, swag init treats these errors as fatal, and doc generation fails.
To Reproduce go.mod:
moduleswag-1232go1.18
main.go:
package main
// #pragma GCC warning "test"import"C"funcmain() {}
Then generate Swagger documentations with dependency parsing:
$ swag init --parseDependency
2022/07/05 18:04:08 Generate swagger docs....
2022/07/05 18:04:08 Generate general API Info, search dir:./
2022/07/05 18:04:08 pkg /.../swag-1232 cannot find all dependencies, <nil>
# swag-1232
./main.go:3:14: warning: test [-W#pragma-messages]
Expected behavior
I would expect the Swagger documentation to be generated successfully, instead of failing due to the C compilation warning.
Your swag version
$ swag --version
swag version v1.8.3
This does not occur in swag v1.8.2 or earlier.
Your go version
$ go version
go version go1.18.3 darwin/arm64
Desktop (please complete the following information):
OS: macOS 12.4
Browser: n/a
Version: n/a
Additional context
As of #1108, released in swag v1.8.3, swag init invokes go list under the hood. When CGo is enabled, that command will invoke the C compiler to evaluate C source; the C compiler, in turn, sends compilation errors and warnings to stderr. However, swag init treats any output to stderr by that command as fatal:
I think the most straightforward solution here is to disable CGo for the invocation of go list by setting the CGO_ENABLED environment variable to 0. I don't think this would break any existing API documentation, because swag init doesn't seem to understand the C pseudo-package anyway:
$ swag init
2022/07/05 18:21:58 Generate swagger docs....
2022/07/05 18:21:58 Generate general API Info, search dir:./
2022/07/05 18:21:58 ParseComment error in file /.../main.go :cannot find type definition: C.int
This extends to the inclusion of CGo types embedded within Go structs.
I think this issue is separate from #1232. In that issue, go list failed to find any source files; here, go list runs successfully, and produces the expected dependency descriptions, but also includes extraneous output.
The text was updated successfully, but these errors were encountered:
Another possible solution would be to remove the stderr checking, and rely on the error checking of cmd.Wait() to catch a non-zero exit status from the go list invocation. Conventionally, output to stderr shouldn't be considered fatal by itself, just informative, unless accompanied by a non-zero exit status.
I'm happy to implement either solution. Just let me know which direction you'd like me to go.
Describe the bug
When C source code compiled by CGo produces warnings,
swag init
treats these errors as fatal, and doc generation fails.To Reproduce
go.mod
:main.go
:Then generate Swagger documentations with dependency parsing:
Expected behavior
I would expect the Swagger documentation to be generated successfully, instead of failing due to the C compilation warning.
Your swag version
This does not occur in swag v1.8.2 or earlier.
Your go version
Desktop (please complete the following information):
Additional context
As of #1108, released in swag v1.8.3,
swag init
invokesgo list
under the hood. When CGo is enabled, that command will invoke the C compiler to evaluate C source; the C compiler, in turn, sends compilation errors and warnings to stderr. However,swag init
treats any output to stderr by that command as fatal:swag/golist.go
Lines 25 to 27 in bd21bb0
I think the most straightforward solution here is to disable CGo for the invocation of
go list
by setting theCGO_ENABLED
environment variable to0
. I don't think this would break any existing API documentation, becauseswag init
doesn't seem to understand theC
pseudo-package anyway:This extends to the inclusion of CGo types embedded within Go structs.
I think this issue is separate from #1232. In that issue,
go list
failed to find any source files; here,go list
runs successfully, and produces the expected dependency descriptions, but also includes extraneous output.The text was updated successfully, but these errors were encountered: