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

Allow wsdlgen to take build tags #106

Open
kohenkatz opened this issue May 25, 2020 · 2 comments
Open

Allow wsdlgen to take build tags #106

kohenkatz opened this issue May 25, 2020 · 2 comments

Comments

@kohenkatz
Copy link
Contributor

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.

@droyo
Copy link
Owner

droyo commented May 25, 2020

This is a good idea. I'm happy to accept a PR.

You might want to take a look at GenAST:

go-xml/xsdgen/xsdgen.go

Lines 229 to 230 in 73105c9

func (code *Code) GenAST() (*ast.File, error) {
var file ast.File
. 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.

@kohenkatz
Copy link
Contributor Author

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.

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

No branches or pull requests

2 participants