Skip to content

Fix C++ cleanup in Grpc.Tools#22895

Merged
jtattermusch merged 3 commits intogrpc:masterfrom
Falco20019:grpc-tools-fix-cpp-cleanup
Jun 5, 2020
Merged

Fix C++ cleanup in Grpc.Tools#22895
jtattermusch merged 3 commits intogrpc:masterfrom
Falco20019:grpc-tools-fix-cpp-cleanup

Conversation

@Falco20019
Copy link
Copy Markdown
Contributor

The result of Protobuf_ExpectedOutputs in Protobuf_PrepareClean and Protobuf_PrepareCompile is different for out-of-path protos if no ProtoRoot was given.

This is, because _Protobuf_SelectFiles is setting ProtoRoot=%(RelativeDir) when building, but this is not set when cleaning up.

This PR extracts the logic of settings the ProtoRoot from _Protobuf_SelectFiles into _Protobuf_SetProtoRoot and ensures, that the same files are expected for creation and cleanup. Since we are not filling a new item group but updating an existing one, we had to use update logic instead of include logic. Otherwise we would end up with Protobuf having the same item twice, once without ProtoRoot and once with the set ProtoRoot.

CC @jtattermusch @kkm000

@jtattermusch jtattermusch self-assigned this May 8, 2020
@jtattermusch jtattermusch self-requested a review May 8, 2020 13:51
@jtattermusch jtattermusch added lang/C# release notes: yes Indicates if PR needs to be in release notes kokoro:run labels May 8, 2020
Copy link
Copy Markdown
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

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

I have trouble following the logic changes and making sure this doesn't break anything.
We really need to come up with some simple way of testing the .targets file, the lack of tests is making accepting any Grpc.Tools change difficult.

@Falco20019 Falco20019 requested a review from jtattermusch May 25, 2020 06:29
@Falco20019
Copy link
Copy Markdown
Contributor Author

@jtattermusch @JunTaoLuo I updated the PR to use Protobuf_Rooted as intermediate item group and only split up the original logic from Protobuf_Compile into Protobuf_Rooted and Protobuf_Compile. This increases the data overhead as a new item group is necessary. But at least it's easier to follow and fixes the bug without introducing new logic.


All ExpectedOutputs will be removed. -->
<Target Name="Protobuf_PrepareClean" Condition=" '@(Protobuf)' != '' ">
<Target Name="Protobuf_PrepareClean" Condition=" '@(Protobuf_Rooted)' != '' ">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here, I think it would make sense for Protobuf_PrepareClean to depend on _Protobuf_SetProtoRoot, especially since this target isn't prefixed with _ which generally signals that it could be called independently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! I will change it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you still going to address this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See #22895 (comment)

We have two options how to fix it but both have downsides and would change either the current behavior or would by asymmetrical to how creation is currently done which feels a bit strange. Would be good to @JunTaoLuo‘s opinion on the two suggestions. (Or three, since keeping it this way is also one.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's leave as is for now and if needed, we can address in a followup PR.

Copy link
Copy Markdown

@JunTaoLuo JunTaoLuo left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me.

@Falco20019
Copy link
Copy Markdown
Contributor Author

Falco20019 commented May 27, 2020

@JunTaoLuo I looked into having Protobuf_PrepareClean depend on _Protobuf_SetProtoRoot. It seems that Condition is checked before DependsOnTargets. So adding it to Protobuf_PrepareClean currently didn't work as it will skip it.

I see two options here on how to solve it:

  1. Split Protobuf_PrepareClean to use a sub-task:
  <Target Name="Protobuf_PrepareClean"
          Condition=" '@(Protobuf)' != '' "
          DependsOnTargets=" _Protobuf_SetProtoRoot;
                             _Protobuf_PrepareClean" />
							 
  <Target Name="_Protobuf_PrepareClean" Condition=" '@(Protobuf_Rooted)' != '' ">
    <!-- Predict expected names. -->
    <ProtoCompilerOutputs Condition=" '$(Language)' == 'C#' "
                          Protobuf="@(Protobuf_Rooted)"
                          Generator="$(Protobuf_Generator)">
      <Output TaskParameter="PossibleOutputs" ItemName="Protobuf_ExpectedOutputs" />
    </ProtoCompilerOutputs>
  </Target>
  1. Use @(Protobuf) as Condition as this is the real condition for the whole target.
  <Target Name="Protobuf_PrepareClean"
          DependsOnTargets=" _Protobuf_SetProtoRoot"
          Condition=" '@(Protobuf)' != '' ">
    <!-- Predict expected names. -->
    <ProtoCompilerOutputs Condition=" '$(Language)' == 'C#' "
                          Protobuf="@(Protobuf_Rooted)"
                          Generator="$(Protobuf_Generator)">
      <Output TaskParameter="PossibleOutputs" ItemName="Protobuf_ExpectedOutputs" />
    </ProtoCompilerOutputs>
  </Target>

We have the same issue with Protobuf_PrepareCompile and Protobuf_Compile. Protobuf_PrepareCompile is expecting @(Protobuf_Compile) to be set, which is only done through _Protobuf_SelectFiles relying on _Protobuf_SetProtoRoot. So we might want to also apply whatever fix we use for Protobuf_PrepareClean there too.

Both ways would change the current behavior. So if someone is calling the target already with manually setting @(Protobuf_Compile) for Protobuf_PrepareCompile, this would be a breaking change. So maybe keeping _Protobuf_SetProtoRoot in Protobuf_Compile and Protobuf_Clean would be less intrusive.

@Falco20019
Copy link
Copy Markdown
Contributor Author

@JunTaoLuo @jtattermusch Any more input on this? Thanks for the valuable feedback so far!

@jtattermusch
Copy link
Copy Markdown
Contributor

Adhoc distribtest run: sponge/ec2617f6-ed25-4bca-a3b6-cc1ddcc1df08

@jtattermusch
Copy link
Copy Markdown
Contributor

@Falco20019 can you update the PR description to match the reality? (right now it seems out of data). Also, why is this called "fix C++ cleanup"? - there doesn't seem anything that's specific to C++ codegen in this change.

Copy link
Copy Markdown
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

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

I think with some very minor nits (see my new comments), this is looking good now.
Thanks for improving the clarity of the change, following what it does is now much easier.

I'll approve once the distribtests pass and my last comments are addressed.

@Falco20019
Copy link
Copy Markdown
Contributor Author

@Falco20019 can you update the PR description to match the reality? (right now it seems out of data). Also, why is this called "fix C++ cleanup"? - there doesn't seem anything that's specific to C++ codegen in this change.

It fixes the root that was missing for C++ cleanup. Right now, since the root was not set, the expected files are wrong and cleanup is not working for C++. So this really only is a fix for C++ as that’s the only language using the proto root in the expected output. I want to use the same logic also for C#. To be more precise, currently for creation the root is set through ProtoCompile, but for cleanup it was not, so the result was different for creation and cleanup.

@jtattermusch
Copy link
Copy Markdown
Contributor

Another adhoc run (this time with rebased code to avoid an unrelated artifact breakage).
https://sponge.corp.google.com/invocation?id=57315f8b-7c14-413e-9443-c3a0d50a99ad&searchFor=

@jtattermusch
Copy link
Copy Markdown
Contributor

The distribtests have passed: sponge/580024b2-08f1-472e-bc7a-3ba0f3aba111

Copy link
Copy Markdown
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

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

LGTM.

@jtattermusch jtattermusch merged commit 900699c into grpc:master Jun 5, 2020
@Falco20019 Falco20019 deleted the grpc-tools-fix-cpp-cleanup branch June 29, 2020 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/C# release notes: yes Indicates if PR needs to be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants