Bug 55536 - [btouch] Enabling --process-enums on a project with StructsAndEnums.cs set as ObjcBindingCoreSource give build error
Summary: [btouch] Enabling --process-enums on a project with StructsAndEnums.cs set as...
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
Version: XI 10.10 (d15-2)
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Vincent Dondain [MSFT]
Depends on:
Reported: 2017-04-24 20:16 UTC by Vincent Dondain [MSFT]
Modified: 2017-04-25 15:11 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Test case (465.24 KB, application/zip)
2017-04-25 15:11 UTC, Alex Soto [MSFT]

Description Vincent Dondain [MSFT] 2017-04-24 20:16:04 UTC
This is the project I could reproduce this bug with: https://developer.xamarin.com/samples/monotouch/InfColorPicker/

Repro steps:

- Open InfColorPickerBinding.sln
- Go the the binding project project's options > Objective C Binding Build > Select "Process enums as bindings instead of external types".
- Re-build.

You should get the following build error:

`obj/Debug/ios/InfColorPicker/InfComponentIndex.g.cs(38,14,38,31): error CS0101: The namespace 'InfColorPicker' already contains a definition for 'InfComponentIndex'`


Change `StructsAndEnums.cs` build action to: "ObjcBindingApiDefinition".

Environment used: https://gist.github.com/VincentDondain/2aac9232a19b989303317bf432449613
Comment 1 Alex Soto [MSFT] 2017-04-24 22:52:13 UTC
I can confirm this happens with latest xamarin-macios/master @ dce730ddb7bdf8d7c2d3d460b0f141ede125a84e
Comment 2 Sebastien Pouliot 2017-04-25 13:26:01 UTC
@Vincent please attach build logs whenever you're quoting from them.

This looks like a sample issue. By default the same enum can be put inside both "API definition" (because it won't be generated) and in the manual `StructsAndEnums.cs` file. Once compiled together you end up with a single (non generated) enum type.

Now if you enable enum processing then the enum from "API definition" will be generated and will collide with the same one from the manual file.

The proposed workaround might compile (in this case) but is likely not producing the same final API (missing all structs). In fact "one does not simply" enable --process-enums and expect identical output ;-) You need to update/move enums inside the bindings project.

The fix is to either:

1. Correct the sample (if there's some value to enabling enum processing on it) to work when processing enums;

2. Leave the sample as is, since it works with older versions of XI;
Comment 3 Vincent Dondain [MSFT] 2017-04-25 15:06:00 UTC
Oops indeed, forgot the build output: https://gist.github.com/VincentDondain/3734cd926fb17bb84a9d91387fb3229f

"Now if you enable enum processing then the enum from "API definition" will be generated and will collide with the same one from the manual file."

^ that would have been my assumption too however the enum isn't defined twice it's only defined once in `StructsAndEnums.cs`

I believe this was Alex's question too when I asked him but that's why he confirmed the bug.
Comment 4 Alex Soto [MSFT] 2017-04-25 15:11:45 UTC
Created attachment 21764 [details]
Test case

Project to repro

> InfColorPicker/InfColorPickerBinding/InfColorPickerBinding.sln

Note You need to log in before you can comment on or make changes to this bug.