go-xml
go-xml copied to clipboard
Allow wsdlgen to take build tags
A useful feature of go-bindata is its ability to take an argument with go build tags to add to the generated file.
My specific use-case for this is that I have two WSDL files - one from the production server and the other from the staging server, each with its hard-coded server URL in it.
I would like to be able to use go generate like this:
//go:generate wsdlgen -pkg $GOPACKAGE -tags !release -o generated__staging.go staging.xml
//go:generate wsdlgen -pkg $GOPACKAGE -tags release -o generated__production.go production.xml
I tried to do it like this, but it doesn't work:
//go:generate wsdlgen -pkg $GOPACKAGE -c "Code generated by wsdlgen. DO NOT EDIT.\n+build !release" -o generated__staging.go staging.xml
//go:generate wsdlgen -pkg $GOPACKAGE -c "Code generated by wsdlgen. DO NOT EDIT.\n+build release" -o generated__production.go production.xml
The reason it doesn't work is that whitespace matters. There must be a blank line between the build flags and the package declaration, as noted here.
To distinguish build constraints from package documentation, a series of build constraints must be followed by a blank line.
I would be happy to submit a PR for this if you are interested.
This is a good idea. I'm happy to accept a PR.
You might want to take a look at GenAST: https://github.com/droyo/go-xml/blob/73105c9af91535f13c9f89e0d72d81ea3dbce725/xsdgen/xsdgen.go#L229-L230 . You'll want to fish a tags argument from the CLI through to hear and prepend the appropriate *ast.Comment to file.Comments, I think.
Alternatively you could do this just by modifying the string produced in GenSource.
I've been surveying how other tools do it and it seems that most of them just output the string directly instead of trying to deal with the AST. That's what I did in #107 and that's what I plan to do for this one as well.