Skip to content

Conversation

@pgrawehr
Copy link

@pgrawehr pgrawehr commented Jan 17, 2020

GenApi now adds "// <autogenerated ... />" at the top of the generated file. Optionally, adding an user-defined header is supported as well. This will disable StyleCop (and other code analysis tools) from checking the generated file (which will usually fail).

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be optional. All generated files should include this header.

Also, this should be part of the GenApi tool itself, as opposed to being a separate flag passed in.

@sharwell
Copy link
Contributor

sharwell commented Jan 17, 2020

I'm withdrawing my objection to the implementation change. It should be possible to set this command line option through the build targets.

I maintain my objection to the rationale for the change. One case where this feature should not be used is for the situation described in the original post. If the tool is failing to generate the <auto-generated /> comment by default, then the tool has a bug that still needs to be addressed after this change is merged.

@pgrawehr
Copy link
Author

@sharwell : So you would suggest to change the tool itself to always add the autogenerated line at the top? For clients, that would even be less of a hassle then.

@sharwell
Copy link
Contributor

@pgrawehr I see two options here:

  1. Always add the comment (which would need to precede the header, otherwise if the header contains a blank line then the auto-generated comment would not be found)
  2. Implement the auto-generated comment as a default header that is used in cases where the --file-header argument is omitted (i.e. users who provide a custom file header would need to make sure it included this comment)

Each option has advantages and disadvantages. Option 2 seems particularly safe and addresses the needs of most users without requiring other changes.

@pgrawehr
Copy link
Author

Option 2 sounds ok for me. I'll try to provide something.

@sharwell
Copy link
Contributor

Awesome!

FWIW, historically this comment was generated with the following form:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     GenAPI Version: <Version>
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

The only part that the tools actually look for is the sequence <auto-generated, so you can decide whether to use the short form or the full form as the default.

@pgrawehr
Copy link
Author

Yea, I've seen this before - I've even seen it being translated to the user's language (I tend to have all tools, even compilers installed in german). So I might need to search for the matching resource.

@sharwell
Copy link
Contributor

sharwell commented Jan 17, 2020

📝 Translating the strings will cause problems in two cases:

  1. The generated code ends up in source control, e.g. when .resx is converted to the .Designer.cs file
  2. Attempting deterministic builds (the build now depends on the current culture)

💭 This may have been one of the reasons why the long comment was dropped. Not sure about that though.

@pgrawehr
Copy link
Author

That's also what I've observed before 👀
So better keep it simple. I've got no problems with that.

@pgrawehr
Copy link
Author

@sharwell Added code to always include a header in the file, unless the user specifies its own (and as long as it's C#)

@pgrawehr
Copy link
Author

@sharwell Any further work required? It would be good if this could be merged soon, as dotnet/iot depends on this working (or all the StyleCop stuff we've done over there will get broken again because the builds can't be enabled to fully test the rules)

@pgrawehr pgrawehr requested a review from sharwell February 11, 2020 09:11
@sharwell
Copy link
Contributor

@pgrawehr it looks fine to me, but I'm not a maintainer on this repository so someone else will need to do the final review and merge.

@pgrawehr pgrawehr changed the title Allow specifying a header file to be included in the generated source Add auto-generated header to GenApi output (user defined or automatic) Feb 27, 2020
@pgrawehr pgrawehr mentioned this pull request Mar 5, 2020
@dougbu
Copy link
Contributor

dougbu commented Mar 5, 2020

I think this looks fine though ASP.NET Core wouldn't use this because we use --header-file (for a license header). Suggest @ericstj as a "real" reviewer.

@ericstj
Copy link
Member

ericstj commented Mar 5, 2020

Looking...

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, if someone happens to be broken by this, they can always pass an empty header.

@ericstj ericstj merged commit ed8c23f into dotnet:master Mar 5, 2020
@pgrawehr pgrawehr deleted the HeaderFileArg branch March 6, 2020 07:10
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 this pull request may close these issues.

4 participants