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

bond grpc generate warning CS2002 when have multiple bond files #1050

Closed
wuzhuoqing opened this issue May 29, 2020 · 3 comments · Fixed by #1051
Closed

bond grpc generate warning CS2002 when have multiple bond files #1050

wuzhuoqing opened this issue May 29, 2020 · 3 comments · Fixed by #1051
Labels

Comments

@wuzhuoqing
Copy link

wuzhuoqing commented May 29, 2020

Take sample project https://github.com/microsoft/bond-grpc-examples.
Move bond file into project and move the Result into separate bond and import in service bond.
Compile and cs2002 warning shows up. Cannot be suppressed by NoWarn.

Interesting it is only complains about *_grpc.cs but not *_types.cs

grpc_cs2002_warning.zip

Actually doesn't need to use import. Just have two bond files will also trigger the warnings.

@wuzhuoqing wuzhuoqing changed the title bond grpc generate warning CS2002 when use import bond grpc generate warning CS2002 when have multiple bond files May 30, 2020
@chwarr
Copy link
Member

chwarr commented May 30, 2020

I think I understand the bug. As a work around, try changing the csproj like this:

--- "D:\\temp\\orig.csproj"     2020-05-29 15:40:12.514273600 -0700
+++ ".\\calculator-service.csproj"      2020-05-29 17:30:32.195659900 -0700
@@ -1,9 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <AssemblyName>CalculatorService</AssemblyName>
-    <!-- gRPC needs to be enabled so that code generation will create the
-         gRPC .cs files. -->
-    <BondOptions>--grpc</BondOptions>
     <OutputType>Exe</OutputType>
     <ProjectGuid>{E8AB9839-2B85-4A55-AA4A-28E3B666B50A}</ProjectGuid>
     <RootNamespace>Bond.Grpc.Examples.Calculator</RootNamespace>
@@ -11,6 +8,9 @@
   </PropertyGroup>

   <ItemGroup>
+    <BondCodegen Update="*.bond">
+      <Options>--grpc</Options>
+    </BondCodegen>
   </ItemGroup>

   <ItemGroup>

For my notes: I think the bug is because the batching in _BondGen_Grpc_BondOptions uses %(BondCodegen.Identity) indead of %(_BondCodegenWithDefaultOptions.Identity), so there's a multiplication happening when this should just be a mapping.

      <_BondGen_Grpc_BondOptions
          Include="@(_BondCodegenWithDefaultOptions -> '$(_BondOutputDirectoryNormalized)%(FileName)_grpc.cs')"
          Condition="$(BondOptions.Contains('--grpc'))
                     AND !$(BondOptions.Contains('--grpc=false'))">
        <AutoGen>true</AutoGen>
        <DependentUpon>%(BondCodegen.Identity)</DependentUpon>
      </_BondGen_Grpc_BondOptions>

@chwarr chwarr added the bug label May 30, 2020
@wuzhuoqing
Copy link
Author

Thank you. Added msbuild diag log portion

Target "BondCompileCs: (TargetId:113)" in file ".nuget\packages\bond.csharp\9.0.0\build\Common.targets" from project "bond-grpc-examples\cs\calculator-service\calculator-service.csproj" (target "CoreCompile" depends on it):
                   Added Item(s): 
                       _BondGen_Structs_BondOptions=
                           obj/Release/netcoreapp3.0/calculator_types.cs
                                   AutoGen=true
                                   DependentUpon=calculator.bond
                   Added Item(s): 
                       _BondGen_Structs_BondOptions=
                           obj/Release/netcoreapp3.0/Result_types.cs
                                   AutoGen=true
                                   DependentUpon=Result.bond
                   Added Item(s): 
                       _BondGen_Grpc_BondOptions=
                           obj/Release/netcoreapp3.0/calculator_grpc.cs
                                   AutoGen=true
                                   DependentUpon=calculator.bond
                           obj/Release/netcoreapp3.0/Result_grpc.cs
                                   AutoGen=true
                                   DependentUpon=calculator.bond
                   Added Item(s): 
                       _BondGen_Grpc_BondOptions=
                           obj/Release/netcoreapp3.0/calculator_grpc.cs
                                   AutoGen=true
                                   DependentUpon=Result.bond
                           obj/Release/netcoreapp3.0/Result_grpc.cs
                                   AutoGen=true
                                   DependentUpon=Result.bond

chwarr added a commit to chwarr/bond that referenced this issue May 30, 2020
When a project has multiple .bond files in `@BondCodegen` and specified
`--grpc` in `$BondOptions`, the C# code generation targets erroneously
added the generated files to the `@Compile` item multiple times.

This was caused because the `@_BondGen_Grpc_BondOptions` item
incorrectly used `%(BondCodegen.Identity)` when populating
`%DependentUpon`. Since `@_BondGen_Grpc_BondOptions` and `@BondCodegen`
are different items, this multiplied them together. A mapping was
intended instead, so the fix is to use
`%_BondGen_Grpc_BondOptions.Identity`. (This was likely a copy/paste bug
when `--grpc` support was added to the targets.)

Fixes microsoft#1050
chwarr added a commit that referenced this issue May 30, 2020
When a project has multiple .bond files in `@BondCodegen` and specified
`--grpc` in `$BondOptions`, the C# code generation targets erroneously
added the generated files to the `@Compile` item multiple times.

This was caused because the `@_BondGen_Grpc_BondOptions` item
incorrectly used `%(BondCodegen.Identity)` when populating
`%DependentUpon`. Since `@_BondGen_Grpc_BondOptions` and `@BondCodegen`
are different items, this multiplied them together. A mapping was
intended instead, so the fix is to use
`%_BondGen_Grpc_BondOptions.Identity`. (This was likely a copy/paste bug
when `--grpc` support was added to the targets.)

Fixes #1050
@chwarr
Copy link
Member

chwarr commented May 30, 2020

Fixed in the master branch. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants