-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: add license and generated code headers to generated resource files #696
Conversation
…utogenerated code warning to generated files
->withApacheLicense($currentYear) | ||
->withGeneratedCodeWarning() | ||
->withBlock($codeBlock) | ||
->toCode() . ";"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am adding the ;
manually here but I am not particularly fond of this.
My first attempt was to add this to the return
method on AST
but that function is used in different places. I am using the PhpFile
class which has the ability to use a codeblock but any PhpBlock
class implements the ShouldNotApplySemicolonInterface
which the AST::toPhp
method checks to decide wether or not add a semicolon.
We could create a EndPhpBlock
or FinalPhpBlock
class that does not implements the interface perhaps?
AST::file(null)
->withBlock(new EndPhpBlock($string))
Add a method that internally forces a semicolon while calling the toPhp
method?
AST::file(null)
->withBlock(new PhpBlock($string))
->withSemiColon()
perhaps a method on the PhpClass
to "finalize" the class? But perhaps the word for "Final" might be confused by a Final class. Ready perhaps? that adds a ;
to the end?
AST::file(null)
->withBlock(new PhpBlock())
->ready()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting...I don't want to mess with PhpBlock
too much, especially if it is already opinionated about semicolons. Given how choosy the AST
is about semicolons altogether, I think this might be a reasonable solution to keep it how it is...or do what you suggested with a new EndPhpBlock
...maybe LastPhpBlock
? It just wraps a Block
and tacks on the ;
in toCode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I poked around a bit more today to see if adding the extra PHP class would help but after debugging and poking further turns out that in this case, it is actually not using the phpBlock
class, but just a regular AST
class and the toPhp
method just calls toCode
on an AST instance:
elseif ($x instanceof AST) {
return $x->toCode();
}
So the semicolon interface does nothing in this case lol. I think it would be best to have a way to add a semicolon codewise but for now let's keep it like it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the semicolon interface does nothing in this case lol. I think it would be best to have a way to add a semicolon codewise but for now let's keep it like it is.
Nice code spelunking! I agree, simple enough for now. Maybe file a priority: p3
type: cleanup
bug to look at this?
Note: I changed the title to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will also need to update the Bazel integration test Golden files. Those can be updated locally via the instructions in DEVELOPMENT.md
When updating the integration test golden files you will need to rotate the bazel cache key in the secrets. It isn't really a "secret" just where this value is stored, which indicates we want a full rebuild of the bazel workspace.
This is documented here: https://github.com/googleapis/gapic-generator-php/blob/main/DEVELOPMENT.md#rotating-the-bazel-cache-key. You may or may not have perms for this, lmk if you don't. I've rotated and rerun the build for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the MODULE bazel files - these are created by buildifier or something when you open a WORKSPACE or BUILD.bazel file. We don't support bzlmod yet.
Maybe we should add these to the .gitignore....
07493ea
to
81bae38
Compare
@noahdietz |
Not really, unless we worry about folks forgetting that we are ignoring them if we eventually add bzlmod support haha. Let's just add it! This PR or another is fine. |
@noahdietz |
Change the
ResourcesGenerator
class to make use of theAST::file()
method to add the required comments. I also added some comments for discussion on this PR to add them in a different PR if we come with a more elegant solution.Fixes #643