Граф коммитов

144 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge df523c8b18 Merge remote-tracking branch 'origin/xcode11' into d16-3. 2019-09-17 08:30:12 +02:00
Rolf Bjarne Kvinge 303aa0a649 Merge remote-tracking branch 'origin/xcode11' into master-xcode11 2019-09-13 18:35:18 +02:00
Rolf Bjarne Kvinge f6e0531197 Merge xcode11 into d16-3. 2019-09-12 08:29:02 +02:00
Rolf Bjarne Kvinge 3ee1329e0e
[generator] Handle inheriting the same member from multiple protocols. Fixes #6366. (#6961)
* [generator] Handle inheriting the same member from multiple protocols. Fixes #6366.

Fixes https://github.com/xamarin/xamarin-macios/issues/6366.

* Update xtro.
2019-09-11 05:12:43 -07:00
Rolf Bjarne Kvinge cce789d481
[generator] Handle subclasses of NSObject as ref/out parameters in third-party libraries. Fixes #6828. (#6829) (#6847)
For third-party libraries we need to look up the base type using the BaseType attribute.

Fixes https://github.com/xamarin/xamarin-macios/issues/6828.
2019-08-26 07:14:26 -07:00
Rolf Bjarne Kvinge 4e70034b96
[generator] Handle subclasses of NSObject as ref/out parameters in third-party libraries. Fixes #6828. (#6829)
For third-party libraries we need to look up the base type using the BaseType attribute.

Fixes https://github.com/xamarin/xamarin-macios/issues/6828.
2019-08-26 01:06:13 -07:00
Rolf Bjarne Kvinge d4192a59f0
[xcode11] Remove the WatchKit framework from iOS while keeping API stability. Fixes #6492. (#6503)
* [WatchKit] Remove this framework for iOS while keeping backwards compatibility. Fixes #6492.

* Copy all generated sources and modify them to throw PlatformNotSupported exceptions.
* Adjust some existing source code to also throw PlatformNotSupported exceptions.
* Sprinkle Obsolete attributes generously.
* Stop generating code for the WatchKit framework for iOS.

Fixes https://github.com/xamarin/xamarin-macios/issues/6492.

* [introspection] Adjust test.

* [mtouch] Don't link with WatchKit, and show a warning if we detect code that want to use WatchKit.

* [xtro] Remove WatchKit for iOS.

* [introspection] Don't check obsoleted NSString fields for null.

There's probably a reason the field was obsoleted.

* [introspection] Add exception for the WatchKit framework.

* [xtro] Ignore obsolete enums.

There's probably a reason they're obsoleted.

In particular it solves a confusion between WKWebKit.WKErrorCode and
WatchKit.WKErrorCode: for iOS, the latter is obsoleted, and this way we always
process the former instead.

* [mtouch] Adjust wording for MT4178 to be more accurate.

* [WatchKit] Make more API obsolete/hidden.

Two classes managed to slip past the first time.

* [tests] Adjust test after WatchKit removal.
2019-08-14 17:46:55 +02:00
Alex Soto 7bf95d97b0
[generator] Add support for [Native] enums inside [StrongDictionaries] (#6763) 2019-08-13 18:36:36 -04:00
monojenkins 0443822a3f [xcode11] [Generator] Do not used harcoded 'error' var name, use the one in the declaration. (#6637) 2019-07-24 13:28:07 +02:00
Manuel de la Pena 2648b2ecec
[Generator] Do not used harcoded 'error' var name, use the one in the declaration. (#6620) 2019-07-24 01:03:10 +02:00
Rolf Bjarne Kvinge a495077533
[xcode11] Stop building/shipping 32-bit Xamarin.Mac bits. Partial fix for #6300. (#6393)
This includes:

* 32-bit version of Xamarin.Mac.dll and OpenTK.dll
* XamMac.dll and XamMac.CFNetwork.dll
* 32-bit versions of the runtime libraries (libxammac.a and friends).
* 32-bit version of the partial static library for Xamarin.Mac.
* Classic support in the generator.

We still ship a few Classic files so that Visual Studio for Mac continue to detect that Xamarin.Mac is installed (otherwise VSfM won't open Classic projects, which makes it impossible to use the migration wizard).

This makes our build slightly faster.

Partial fix for #6300.
2019-07-15 10:19:24 -07:00
Rolf Bjarne Kvinge f9d39c640b
Merge pull request #6164 from monojenkins/backport-pr-6159-to-d16-2
[d16-2] [Metal] Sprinkle [return: Release] on all 'new*' selectors. Fixes #5941.
2019-06-19 17:29:43 +02:00
Rolf Bjarne Kvinge 14cac96c90
[d16-2] Bump VSMac to 8.1.0.2742 to fix msbuild issues (#6279) (#6361)
* Bump VSMac to 8.1.0.2742 to fix msbuild issues (#6279)

* Bump VSMac to 8.1.0.2742 to fix msbuild issues

This is required to get the support for the msbuild `ToolsVersion`
change from `15.0` to `Current`.

* [tests][msbuild] Fix Binding resources test with updated msbuild

Test failure with updated msbuild and vsmac 8.1:

```
Xamarin.iOS.Tasks.NativeReferencesNoEmbedding("iPhone").ShouldNotUnnecessarilyRebuildBindingProject(True)
     Binding project build did not create package?
  Expected: True
  But was:  False

at Xamarin.iOS.Tasks.NativeReferencesNoEmbedding.ShouldNotUnnecessarilyRebuildBindingProject (System.Boolean framework) [0x000a0] in <74b8f7d8a53e40109916d305bb4d7403>:0
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo cul
ture) [0x0006a] in <0519fa732e8845b6a809ce9180f541db>:0
```

The test builds the project multiple times. Before the 3rd build, the project
file's timestamp is updated and expects that the binding package will be
rebuilt. But it is not, because the target `_CreateBindingResourcePackage`
doesn't depend on that project file. So, add that to the target inputs.

* [nuget] Use xibuild to run nuget

Fix errors seen during `nuget restore` for tests:

```
Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xammac_tests/xammac_tests.csproj(213,3): error MSB4024: The imported project file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets" could not be loaded. Could not find file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets"
```

* [xibuild] Fix incorrect mscorlib.dll being used (#6068)

* [xibuild] Fix incorrect mscorlib.dll being used

The `GuiUnit_NET_4_5` project, when built with `xibuild` uses the wrong `mscorlib.dll`.

From https://github.com/xamarin/xamarin-macios/issues/5760#issuecomment-472457202 :

```
- mscorlib.dll is being used from mono/4.5 and the other system assemblies are from mono/4.5-api
- GuiNet* project is built with xibuild

What is happening here is:

	xibuild sets[1] `SetToolsetProperty ("TargetFrameworkRootPath", FrameworksDirectory + Path.DirectorySeparatorChar);`
	which points to `/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks`.
	This causes $(FrameworkPathOverride) to be set[2] to `/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETFramework/v4.5`,
	but that doesn't have a mscorlib.dll, so it gets reset[3] to /Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5/.

	If we don't set TargetFrameworkRoothPath, then we get `FrameworkPathOverride = /Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5-api`,
	causing `_ExplicitReference=/Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5-api/mscorlib.dll`(correct one) to be used.
```

Fixes https://github.com/xamarin/xamarin-macios/issues/5760

1. https://github.com/xamarin/xamarin-macios/blob/master/tools/xibuild/Main.cs#L209
2. https://github.com/mono/msbuild/blob/xplat-master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L79
3. https://github.com/mono/msbuild/blob/xplat-master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L84

* Revert "Workaround https://github.com/xamarin/xamarin-macios/issues/5760 in generator csproj"

This reverts commit 9bd927bb7f.

The previous commit for xibuild removes the need for this.

* [xibuild] Handle "incorrectly" cased msbuild property names  (#6202)

msbuild property names are case insensitive. While generating the custom
app.config, in `SetToolsetProperty(..)` we try to update the property if
it already exists. But the name lookup was case sensitive, thus causing
the lookup to fail, resulting in two entries for the same property name
differing only in case. Eg. `MSBuildSDKsPath` vs `MSBuildSdksPath`.

Fixed to ignore case.

Fixes https://github.com/mono/mono/issues/14765 .
2019-06-19 17:28:01 +02:00
Ankit Jain e271d5e18d Bump VSMac to 8.1.0.2742 to fix msbuild issues (#6279)
* Bump VSMac to 8.1.0.2742 to fix msbuild issues

This is required to get the support for the msbuild `ToolsVersion`
change from `15.0` to `Current`.

* [tests][msbuild] Fix Binding resources test with updated msbuild

Test failure with updated msbuild and vsmac 8.1:

```
Xamarin.iOS.Tasks.NativeReferencesNoEmbedding("iPhone").ShouldNotUnnecessarilyRebuildBindingProject(True)
     Binding project build did not create package?
  Expected: True
  But was:  False

at Xamarin.iOS.Tasks.NativeReferencesNoEmbedding.ShouldNotUnnecessarilyRebuildBindingProject (System.Boolean framework) [0x000a0] in <74b8f7d8a53e40109916d305bb4d7403>:0
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo cul
ture) [0x0006a] in <0519fa732e8845b6a809ce9180f541db>:0
```

The test builds the project multiple times. Before the 3rd build, the project
file's timestamp is updated and expects that the binding package will be
rebuilt. But it is not, because the target `_CreateBindingResourcePackage`
doesn't depend on that project file. So, add that to the target inputs.

* [nuget] Use xibuild to run nuget

Fix errors seen during `nuget restore` for tests:

```
Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xammac_tests/xammac_tests.csproj(213,3): error MSB4024: The imported project file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets" could not be loaded. Could not find file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets"
```
2019-06-19 07:07:26 +02:00
Rolf Bjarne Kvinge 614de0b077
[tests] Set environment variables so that the in-process generator finds the locally built platform assemblies. (#6178)
When running the in-process generator, we need to set the same environment
variables as we already do when running the out-of-process generator, so that
the generator looks for the platform assemblies in the local install directory
(and not the system one).
2019-05-30 14:19:26 -07:00
Rolf Bjarne Kvinge ff86152ecc [generator] Fix generation of ReturnRelease code for third-party bindings. (#6135)
Don't use internal platform API (the Selector.Release field), and make sure
the void_objc_msgSend function exists in the binding.
2019-05-30 07:12:38 +02:00
Rolf Bjarne Kvinge 50149daa1f
[generator] Fix generation of ReturnRelease code for third-party bindings. (#6135)
Don't use internal platform API (the Selector.Release field), and make sure
the void_objc_msgSend function exists in the binding.
2019-05-27 23:08:45 -07:00
Rolf Bjarne Kvinge e12243698d
[tests] Use msbuild, not xibuild, to build the generator tests. (#6136)
The generator tests is a standard C# library, and can use the system msbuild
just fine.

Fixes this build problem when building the tests using the command line:

    xamarin-macios/external/mono/external/ikvm/reflect/Emit/ILGenerator.cs(119,20): error CS0433: The type 'Stack<T>' exists in both 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
2019-05-27 22:35:10 -07:00
Ankit Jain 7dddfb657c [xibuild] Fix incorrect mscorlib.dll being used (#6068)
* [xibuild] Fix incorrect mscorlib.dll being used

The `GuiUnit_NET_4_5` project, when built with `xibuild` uses the wrong `mscorlib.dll`.

From https://github.com/xamarin/xamarin-macios/issues/5760#issuecomment-472457202 :

```
- mscorlib.dll is being used from mono/4.5 and the other system assemblies are from mono/4.5-api
- GuiNet* project is built with xibuild

What is happening here is:

	xibuild sets[1] `SetToolsetProperty ("TargetFrameworkRootPath", FrameworksDirectory + Path.DirectorySeparatorChar);`
	which points to `/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks`.
	This causes $(FrameworkPathOverride) to be set[2] to `/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETFramework/v4.5`,
	but that doesn't have a mscorlib.dll, so it gets reset[3] to /Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5/.

	If we don't set TargetFrameworkRoothPath, then we get `FrameworkPathOverride = /Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5-api`,
	causing `_ExplicitReference=/Library/Frameworks/Mono.framework/Versions/5.22.0/lib/mono/4.5-api/mscorlib.dll`(correct one) to be used.
```

Fixes https://github.com/xamarin/xamarin-macios/issues/5760

1. https://github.com/xamarin/xamarin-macios/blob/master/tools/xibuild/Main.cs#L209
2. https://github.com/mono/msbuild/blob/xplat-master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L79
3. https://github.com/mono/msbuild/blob/xplat-master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L84

* Revert "Workaround https://github.com/xamarin/xamarin-macios/issues/5760 in generator csproj"

This reverts commit 9bd927bb7f.

The previous commit for xibuild removes the need for this.
2019-05-17 09:12:05 -07:00
Rolf Bjarne Kvinge ef0d7a1718
[generator] Show proper errors when failing to compile something. (#6003)
* [mtouch/mmp] Split out the RunCommand[Async] methods to a separate file so that the generator can reuse more easily.

* [generator] Show proper errors when failing to compile something.

* Fix grammar
2019-05-07 13:40:59 +02:00
Rolf Bjarne Kvinge e3bafafff0 [tests] Add tests for out/ref parameters. 2019-04-30 14:29:24 +00:00
Rolf Bjarne Kvinge b51aaf4b8b [tests] Add tests for out/ref parameters. 2019-04-26 11:20:15 +02:00
Alexander Köplinger 99ea097abf Merge remote-tracking branch 'upstream/master' into mono-2019-02 2019-04-24 23:28:00 +02:00
Rolf Bjarne Kvinge 09701f4c19
[tests] Fix bgen test to compile by adding missing using. (#5932) 2019-04-23 16:26:38 +01:00
Rolf Bjarne Kvinge adb57537b5
[bgen] Show an error if trying to bind an array of selectors. (#5923) 2019-04-23 06:29:03 +01:00
Alexander Köplinger 9bd927bb7f Workaround https://github.com/xamarin/xamarin-macios/issues/5760 in generator csproj 2019-04-16 17:59:23 +02:00
Rolf Bjarne Kvinge 09f3fce5f2 [tests][bgen] Capture stdout/stderr per thread.
Otherwise tests running in parallel interfere with the output of eachother.
2019-04-11 08:35:21 +02:00
Rolf Bjarne Kvinge 3d9826ae5f [tests][bgen] Specify an output assembly for tests, so that we don't use the current directory.
Using the current directory won't work for in-process bgen tests.
2019-04-11 08:34:36 +02:00
Rolf Bjarne Kvinge ff82af4576 [bgen] Make it possible to run the tests using an in-process generator.
This means referencing the generator project, and create an array of the
arguments (since Main takes an array of strings) instead of a quoted string.
2019-04-11 08:32:58 +02:00
Alex Soto d2a4ecfcaa
[generator] Fix CMSampleBuffer usage in 3rd party bindings (#5707)
Fixes xamarin/xamarin-macios#5692

3rd party bindings cannot use the `.ctor(IntPtr, bool)` of
`CMSampleBuffer` because it is `private`, they must use
`Runtime.GetINativeObject<T> (IntPtr, bool)` instead.
2019-03-04 08:13:34 -05:00
Alexander Köplinger d8b97ad15e Fix NUnit.ConsoleRunner version in Makefiles (#5610)
It was updated to 3.9.0 in https://github.com/xamarin/xamarin-macios/pull/5538 but a few hardcoded 3.5.0 in the Makefiles were missed
2019-02-15 07:38:21 +01:00
Rolf Bjarne Kvinge 6af4f139c2
[tests] Use latest version of NUnit for test projects to get support for parallelized tests. (#5538)
* [tests] Use latest version of NUnit for test projects to get support for parallelized tests.

* [xharness] Automatically find the correct nunit-console executable for NUnit tests.
2019-02-04 15:22:00 +01:00
Sebastien Pouliot 1c881549a3
[generator] Warn if [NullAllowed] is used on methods. Fixes #4416 (#5464)
The `[NullAllowed]` attribute should not be allowed on methods but it
could break existing binding projects.

Historically it was used on property setters. However using the attribute
on _other_ methods can be misleading, e.g. should it apply to all
parameters, the return value... and its presence/action can be
misinterpreted in code reviews leading to binding bugs.

reference: https://github.com/xamarin/xamarin-macios/issues/5416
2019-01-24 08:57:46 -05:00
Sebastien Pouliot 91250bb615
[generator] Fix BI0000 when no argument semantics are present on a property. Fixes #5444 (#5451)
This can happen if a `[Wrap]` is used on the property getter (and setter)
instead of directly on the property.

In such condition we can safely assume that no dirty check is needed and
can continue with, unmodified, generation (using the wrapped content).

reference: https://github.com/xamarin/xamarin-macios/issues/5444
2019-01-22 09:52:39 -05:00
Ankit Jain f865694f86 Move tests to use new tool xibuild and thus fix msbuild tests (#5128)
* xibuild: New wrapper tool to run msbuild or managed executables

MSBuild supports fallback paths for projects imported using
`$(MSBuildExtensionsPath)`, but these must be specified explicitly in
the app.config of the main executable. There was a PR to allow use of
properties for this in the app.config, but that was not accepted
upstream.

This is required for being able to:

1. build projects with msbuild against the in-tree XI/XM build output
2. and to run nunit tests against the same.

For this we introduce a new tool, `xibuild`, based on XA's `xabuild`.
This supports the fallback paths to be specified via the environment variable
`MSBuildExtensionsPathFallbackPathsOverride`[1].
It essentially operates in 3 modes:

1. `xibuild -c /path/to/foo.exe`
	Generates /path/to/foo.exe.config with the fallback paths inserted into that.

2. `xibuild -- /v:diag /path/to/project.csproj`
	Runs msbuild with the arguments after `--` with a custom app.config based on
	`MSBuild.dll.config`, with the fallback paths correctly inserted.
	This is in a temporary file and the original config file is not touched.

3. `xibuild -t -- /path/to/managed_tool.exe args`
	Generates `/path/to/managed_tool.exe.config` based on `MSBuild.dll.config` with
	the fallback paths inserted, and runs `managed_tool.exe` with the arguments.
	The default is to overwrite the config file.
	But there is also a switch to merge it with an existing config file.

--
1. Value of the environment variable $MSBuildExtensionsPathFallbackPathsOverride
is prepended to any existing list of search paths in `MSBuild.dll.config`, IOW,
it takes precedence. So, the order of lookup becomes:

  - Value of the property `$(MSBuildExtensionsPath)`
  - Value of the environment variable `$MSBuildExtensionsPathFallbackPathsOverride`
  - /Library/Frameworks/Mono.framework/External/xbuild on macOS

* Integrate use of `xibuild` with the tests

Update all uses of `msbuild` and invocations of tools like nunit that
might depend on using the in-tree builds to use `xibuild`.

* xibuild: Move help descriptions to OptionSet itself.
2018-11-16 14:24:35 -05:00
Vincent Dondain eec95e881c Merge branch 'd15-8' into xcode10-rebase-15.8 2018-08-13 21:04:56 -04:00
Manuel de la Pena 41fe079f9b [Generator] Ensure the correct error is raised when an Export is missing on a Property. (#4604)
The generator had a small bug in which we would get a NRE when a
property missed a Export attribute and had no WrapAttr. The issue is due
to the fact that an || is being used and does not shortcut when the
attribute is missing. In that case, the first Get check would pass and a
second attempt would happen with the set. In the case the set is missing,
we would get a NRE. The correct way is to ensure that we do have the get
and the set BEFORE the attr is checked.

The added test shows an example of the issue.
2018-08-09 16:06:14 -04:00
Alex Soto 02e8a2d7a3
[generator] Fixes WrapAttribute usage with interface protocols (#3885) (#4210)
* [generator] Fixes WrapAttribute usage with interface protocols

Fixes xamarin/xamarin-macios#3869

We need to support the scenario where `WrapAttribute` is used
to wrap an interface protocol type declaration like:

```csharp

	[Wrap ("WeakDelegate")]
	[NullAllowed]
	ICLSDataStoreDelegate Delegate { get; set; }

	[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
	NSObject WeakDelegate { get; set; }

```

We generated invalid code for the setter that needed an explicit cast
and ended up with a CS0266 compiler error:

Bad generated code:

```csharp

[CompilerGenerated]
public ICLSDataStoreDelegate Delegate {
	get {
		return WeakDelegate as ICLSDataStoreDelegate;
	}
	set {
		WeakDelegate = value;
	}
}

```

Good generated code:

```csharp

[CompilerGenerated]
public ICLSDataStoreDelegate Delegate {
	get {
		return WeakDelegate as ICLSDataStoreDelegate;
	}
	set {
		var rvalue = value as NSObject;
		if (value != null && rvalue == null)
			throw new ArgumentException ("The object passed of type " + value.GetType () + " does not derive from NSObject");
		WeakDelegate = rvalue;
	}
}

```
2018-06-11 10:26:30 -07:00
Chris Hamons c0da0f78a6
Teach bmac to handle reletive references, in particular -r:System.Drawing (#4028)
- "Relative", or non-absolute pathed, references such as -r:System.Drawing were
not working in the code generator after the mcs->csc conversion
- The older "sdk" option fixed this up for us.
- We detect these and convert them to full references to the relevant SDK
- Add tests to cover this case
2018-05-04 11:02:39 -05:00
Chris Hamons 3ec08c0e9a [generator] More correctly handle XM System TargetFramework and Syste… (#3980)
* [generator] More correctly handle XM System TargetFramework and System.Drawing references

- https://github.com/xamarin/xamarin-macios/issues/3948

* Add else throws for imposible conditions that one day not be impossible

* 1043 instead of exception. Remove duplication
2018-05-03 07:31:47 +02:00
Rolf Bjarne Kvinge b1c5ebf326
[generator] Register models with unique names to not match platform types. Fixes #3875. (#3879) (#3888)
* Move Registrar.SanitizeName to StringUtils.SanitizeObjectiveCName.

* [generator] Register models with unique names to not match platform types. Fixes #3875.

* [NSObject] Don't compare against a non-existent protocol.

* [generator] Make it possible to register models like before if the binding developer wishes it.

* [src] Make sure to not declare ObjC classes Apple already defines.

Fixes these warnings at startup:

    Class DOMNodeFilter is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944a788) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9958). One of the two will be used. Which one is undefined.
    Class WebOpenPanelResultListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e4c8) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9a98). One of the two will be used. Which one is undefined.
    Class WebPolicyDecisionListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e838) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9ae8). One of the two will be used. Which one is undefined.
    Class MTLCaptureScope is implemented in both /System/Library/Frameworks/Metal.framework/Versions/A/Metal (0x7fffa806f1d0) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aa858). One of the two will be used. Which one is undefined.
    Class JSExport is implemented in both /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore (0x7fffa7eb4f60) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aaa38). One of the two will be used. Which one is undefined.
2018-04-06 19:58:20 +02:00
Alex Soto 318f583280
[generator] Fixes WrapAttribute usage with interface protocols (#3885)
* [generator] Fixes WrapAttribute usage with interface protocols

Fixes xamarin/xamarin-macios#3869

We need to support the scenario where `WrapAttribute` is used
to wrap an interface protocol type declaration like:

```csharp

	[Wrap ("WeakDelegate")]
	[NullAllowed]
	ICLSDataStoreDelegate Delegate { get; set; }

	[NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
	NSObject WeakDelegate { get; set; }

```

We generated invalid code for the setter that needed an explicit cast
and ended up with a CS0266 compiler error:

Bad generated code:

```csharp

[CompilerGenerated]
public ICLSDataStoreDelegate Delegate {
	get {
		return WeakDelegate as ICLSDataStoreDelegate;
	}
	set {
		WeakDelegate = value;
	}
}

```

Good generated code:

```csharp

[CompilerGenerated]
public ICLSDataStoreDelegate Delegate {
	get {
		return WeakDelegate as ICLSDataStoreDelegate;
	}
	set {
		var rvalue = value as NSObject;
		if (value != null && rvalue == null)
			throw new ArgumentException ("The object passed of type " + value.GetType () + " does not derive from NSObject");
		WeakDelegate = rvalue;
	}
}

```
2018-04-06 12:42:14 -05:00
Rolf Bjarne Kvinge cbed456d31
[generator] Register models with unique names to not match platform types. Fixes #3875. (#3879)
* Move Registrar.SanitizeName to StringUtils.SanitizeObjectiveCName.

* [generator] Register models with unique names to not match platform types. Fixes #3875.

* [NSObject] Don't compare against a non-existent protocol.

* [generator] Make it possible to register models like before if the binding developer wishes it.

* [src] Make sure to not declare ObjC classes Apple already defines.

Fixes these warnings at startup:

    Class DOMNodeFilter is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944a788) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9958). One of the two will be used. Which one is undefined.
    Class WebOpenPanelResultListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e4c8) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9a98). One of the two will be used. Which one is undefined.
    Class WebPolicyDecisionListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e838) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9ae8). One of the two will be used. Which one is undefined.
    Class MTLCaptureScope is implemented in both /System/Library/Frameworks/Metal.framework/Versions/A/Metal (0x7fffa806f1d0) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aa858). One of the two will be used. Which one is undefined.
    Class JSExport is implemented in both /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore (0x7fffa7eb4f60) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aaa38). One of the two will be used. Which one is undefined.
2018-04-06 17:24:07 +02:00
Chris Hamons 1d72f45dfd
Binding project must use csc not mcs (#3795)
- Fix XM and XI binding projects to use csc instead of mcs
- Add BindingProjectTest to verify csc not mcs for XM
- In non-msbuild use cases, removing -sdk params requires adding System/mscorlib so btouch now knows to add those references.
- Obsolete a few arguments to btouch
2018-03-27 14:31:27 -05:00
Alex Soto dca6d79881
[generator] Teach generator about WrapAttribute on Getters and Setters (#3388)
* [generator] Teach generator about WrapAttribute on Getters and Setters

https://bugzilla.xamarin.com/show_bug.cgi?id=57870

`WrapAttribute` can now be used in property getters and setters,
this allows to Wrap virtually anything the way you need, for example
smart enums, consider the following API definition:

```csharp
// Smart enum.
enum PersonRelationship {
	[Field (null)]
	None,

	[Field ("FMFather", "__Internal")]
	Father,

	[Field ("FMMother", "__Internal")]
	Mother
}
```

```csharp
// Property definition.

[Export ("presenceType")]
NSString _PresenceType { get; set; }

PersonRelationship PresenceType {
	[Wrap ("PersonRelationshipExtensions.GetValue (_PresenceType)")]
	get;
	[Wrap ("_PresenceType = value.GetConstant ()")]
	set;
}
```

* Fix Feedback

* Fix doc error

* Update error message
2018-02-05 21:14:08 -06:00
Rolf Bjarne Kvinge f905427739
[tests] Share supporting code between the mtouch and mmp tests. (#3374)
* [tests] Share supporting code between the mtouch and mmp tests.

Create a new class 'BundlerTool', which now contains most of the code in
MTouchTool that's also applicable to mmp (and the new MmpTool class).

This will make it easier to share tests between the mtouch and mmp tests.

Some tweaks are still probably required, but this should get us most of the
way.

* [tests] Fix generator tests after changes in shared test code.

* [tests] Add new file to the MSBuild/XM tests.
2018-02-02 07:09:04 +01:00
Alex Soto 76dcf100b3 [generator] Support [Async] inside categories, fixes bugzilla #57531 (#3229)
https://bugzilla.xamarin.com/show_bug.cgi?id=57531

Adds support for [Async] inside categories.
2018-01-16 08:41:25 -05:00
Chris Hamons 4c5161a446
Create classic snapshot of bgen and update tests/scripts (#3153)
Previous PMCS removal changes froze XamMac.BindingAttributes.dll but not bgen.exe which causes interesting issues when we make changes there and run classic XM tests.

This can be seen here: #3147

This PR freezes bgen-classic in macios-binaries (which will need to be added to master and bumped before this goes in) and update various scripts/tests.
2018-01-03 15:41:49 -06:00
Chris Hamons 734850d416
Remove PMCS processing of availability attributes (#3096)
- XamarinPreprocessorVisitor handled processing/generating availability
  attributes but needs to be removed as it depends on PMCS
- Because processing was handled at a preprocessor/token level before and
  now inside generator.cs a number of changes were needed avoid checking
  in a million line diff (literally)
- This commit creates a "shadow" set of availability attributes, with
  the desired names [Mac] [Watch] [NoTV], etc when not in existence before
- Instead of adding hundreds of using statements to force resolution of these
  shadow types, I abuse C# type resolution by storing them in the root
  (not namespaced) so they are resolved first.
- generator-attributes-manager was taught how to process the multitude of
  old-style attributes and how to generate the new-style attributes
- Generator's bug57070 is no longer valid, since we _can_ and do convert [iOS]
2017-12-22 13:03:21 -06:00
Alex Soto f8d7c54a0f [generator] Disallow the use of [Async] when the signature contains ref/out parameters, fixes bug 58792. (#3059)
When a method signature contains any ref/out parameters
it is a hint that this method is not a candidate to be
used with [Async] we now error BI1062 in the generator.

The reason of an error instead of a warning is that we
currently generate not compilable code when ref/out is
used on the method signature or in the signature of the
delegate (completion handler), it is very unlikely we are
breaking someone now that we emit an error instead of broken
code.

* Fix Anchor and Clarify the addition of BI1117 Warning into docs/website/generator-errors.md

BI1117 Warning documentation was missing from docs/website/generator-errors.md
so I added it.
2017-12-18 09:21:23 -05:00
Rolf Bjarne Kvinge dd95d17b5f
[generator] Properly set the IsDirectBinding value. (#3063)
* [generator] Properly set the IsDirectBinding value.

Properly set the IsDirectBinding value to false for models and synthetic types.

This also means we can now stop excluding models when testing if the
IsDirectBinding value is correct.

Also set IsDirectBinding value to true for sealed wrapper types, since those
will always be direct bindings since they can't be subclassed.

https://gist.github.com/rolfbjarne/24028bf944db848fed4083c460d0ec71

* [tests] Add introspection exclusion for XM.

* [introspection] Add back exclusions for Classic, since we can't modify/fix Classic assemblies anymore.

* [generator] Print the correct protocol name with the protocol attribute.

Fixes this test failure:

    [FAIL] Foundation.NSUrlDownloadDelegate : ConformsToProtocol(null) failed

because our binding code claimed that our `NSUrlDownloadDelegate` class
implemented the `NSUrlDownloadDelegate` protocol, but since the
`NSUrlDownloadDelegate` protocol doesn't exist (it's `NSURLDownloadDelegate` -
different case), we'd verify against a null protocol (and return true from
`ConformsToProtocol(null)`, which would fail the test).

* [xtro] Only treat interfaces as protocols.

Unfortunately we add [Protocol] to [Model]s as well as on interfaces, but we
must not process those in xtro, since they don't correspond with the actual protocol.
2017-12-01 15:18:20 +01:00
Rolf Bjarne Kvinge efebe2b73b
[tests] Port the makefile-based generator tests to NUnit. (#3019)
* [tests][generator] Port bindas1048error to NUnit.

* [tests][generator] Port bindas1049error to NUnit.

* [tests][generator] Port bindas1050modelerror to NUnit.

* [tests][generator] Port bindas1050protocolerror to NUnit.

* [tests][generator] Port bug42855 to NUnit.

* [tests][generator] Port bug57070 to NUnit.

* [tests][generator] Port bug52570classinternal to NUnit.

* [tests][generator] Port bug52570methodinternal to NUnit.

* [tests][generator] Port bug52570allowstaticmembers to NUnit.

* [tests][generator] Port protocol-duplicate-abstract-error to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-length to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-out to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-type to NUnit.

* [tests][generator] Port protocol-duplicate-method-diff-return to NUnit.

* [tests][generator] Port warnaserror to NUnit.

* [tests][generator] Port nowarn to NUnit.

* [tests][generator] Add support for inspecting/asserting the generated content.

* [tests][generator] Port some Xamarin.Mac tests to NUnit.

Ported:

* bmac_smoke
* bmac-with-hyphen-in-name
* property-redefination-mac
* NSApplicationPublicEnsureMethods
* protocol-duplicate-abstract

* [tests][generator] Point bgen to our local installation.

* [tests][generator] Port the bug31788 test to a unit test.

* [generator] Make the 'bgen' helper target more complete.

* [tests][generator] Port non-custom iOS tests to unit tests.

* [tests][generator] Add new test.

* [tests][generator] Port the forum54078 test to a unit test.

* [tests][generator] Port the desk63279 test to a unit test.

* [tests][generator] Port the desk79124 test to a unit test.

* [tests][generator] Port the multiple-api-definitions tests to unit tests.

* [generator] Use mono code style.

* [tests][generator] Port the bug29493 test to a unit test.

* [tests][generator] Port the classNameCollision test to a unit test.

* [tests][generator] Port the bi1036 test to a unit test.

* [tests][generator] Port the bug37527 test to a unit test.

Also fix BI1112 and BI1113 to show up as errors in the console output (since
they're exceptions they're already treated as errors and would cause bgen to
fail).

* [tests][generator] Port the bug27986 test to a unit test.

* [tests][generator] Port the bug35176 test to a unit test.

* [tests][generator] Port the bi1046 test to a unit test.

* [tests][generator] Port the virtualwrap test to a unit test.

* [tests][generator] Port the bug42742 test to a unit test.

* [tests][generator] Port the noasyncinternalwrapper test to a unit test.

* [tests][generator] Port the noasyncwarningcs0219 test to a unit test.

* [tests][generator] Port the bug53076 test to a unit test.

* [tests][generator] Port the bug53076withmodel test to a unit test.

* [tests][generator] Port the fieldenumtests test to a unit test.

* [tests][generator] Port the smartenumwithframework test to a unit test.

* [tests][generator] Port the forcedtype test to a unit test.

* [tests][generator] Port the bug46292 test to a unit test.

* [tests][generator] Build tests with MSBuild.

There's no need to use xbuild for these tests.

* [tests][generator] Remove dead code.

* [xharness] Don't run the makefile-based generator tests anymore.

Since there aren't any makefile-based generator tests anymore, they've all
been ported to NUnit tests.

* [tests][generator] Make the bug39614 test do what it was supposed to do: make sure a namespace isn't required (but recommended).
2017-11-20 14:55:16 +01:00
Rolf Bjarne Kvinge e8d16c925b
[mtouch/mmp/bgen] Add support for response files. (#2808)
* [mtouch/mmp/bgen] Add support for response files.

This is the first part of the fix for #56501.

https://bugzilla.xamarin.com/show_bug.cgi?id=56501

* [tests] Make sure no single argument starting with a '@' is passed to mtouch unless it's a response file.

--assembly-build-target takes arguments starting with '@', for instance:

    --assembly-build-target @all=framework

which does not work anymore, because that's interpreted as a response file
(mtouch tries to read the file '@all=framework', which obviously doesn't
exist).

The fix is simple, don't put a space between the two arguments:

    --assembly-build-target=@all=framework

* Add --root-assembly to mtouch/mmp and make the MSBuild tasks use this new option.

This makes it possible to pass root assemblies starting with `@` to mtouch/mmp
without getting mistaken for response files.

* [msbuild] Always use the command-line option that takes an equals or colon.

Always use the command-line option that takes an equals or colon instead of a
space.

Do either of these:

    --foo=something
    --foo:something

instead of this:

    --foo something

so that `something` can start with an at (`@`) sign without being mistaken for
a response file.

* [msbuild] Fix tests according to recent task changes.
2017-11-16 16:02:34 +01:00
Bernhard Urban 20182800a1
[runtime] integrate mono 2017-10 (#2905)
* Update the function name used to initialize libmono-profiler-log, its called mono_profiler_init_log () now.

* [builds] Pass --with-cross-offsets= to crosstv's configure.

* Bump mono to 2017-08.

* Bump mono to 2017-08.

* Force disable 'futimens' and 'utimensat' so that we build with Xcode 9.

This is also needed to build with Xcode 8.3 on High Sierra.

* Remove old AppleTls implementation.

* Bump mono.

* Bump mono to 2017-08.

* Bump mono to 2017-08

* Reenable link-keep-resources-2 test

- This reverts commit 76b759ef22.
- 2017-08 has linker fix

* Bump mono to 2017-10

* Revert "Bump mono to 2017-10"

This reverts commit bb7832724e.

* Bump system mono to 2017-10

* Bump embedded mono to 2017-10

* [runtime] reflect eglib move

9be68f8952

* bump mono

* [btouch] remove Security.Tls usage from test

* [mtouch tests] update the function name used to initialize libmono-profiler-log, its called mono_profiler_init_log () now.

see
ea4e4a9ef6

fixes:

```
1) Failed : Xamarin.MTouch.Profiling(tvOS)
  _mono_profiler_startup_log
  Expected: collection containing "_mono_profiler_startup_log"
  But was:  < "_mono_profiler_init_log" >
at Xamarin.MTouch.Profiling (Xamarin.Profile profile) [0x00106] in <511889694a624cc9a50e0e9b259b05c5>:0

2) Failed : Xamarin.MTouch.Profiling(watchOS)
  _mono_profiler_startup_log
  Expected: collection containing "_mono_profiler_startup_log"
  But was:  < "_xamarin_get_block_descriptor", "_mono_profiler_init_log" >
at Xamarin.MTouch.Profiling (Xamarin.Profile profile) [0x00106] in <511889694a624cc9a50e0e9b259b05c5>:0
```

* [mmptest] update log profiler options.

826558a4af
deprecated the dash prefix for the mlpd path.

`noallocs` or `nocalls` are not needed, neither of them are default anymore.

* [mmptest] fix link-keep-resources-2 test to cope with more corlib resources.

another corlib resource (mscorlib.xml) was added:

https://github.com/mono/mono/commit/11e95169e787#diff-2d1c64decd91d9a6e8842ab0f0e9438d

* Revert "[mmptest] fix link-keep-resources-2 test to cope with more corlib resources."

This reverts commit 350eb3c174.

* [XHarness] Add the Mono.Data.Tds tests.

* Address comments from rolf in the review.

* [mmp regresssion tests] bump mono linker, so mscorlib.xml gets stripped

the test was failing in that way:

> Executing link-keep-resources-2...
> [FAIL]	i18n 4/2 data files present: charinfo.nlp, collation.core.bin, collation.tailoring.bin, mscorlib.xml

also update the output, because it's actually expected at least three
elements.

fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=59277

* bump mono

fixes crash in tvOS: https://github.com/mono/mono/pull/5812

* bump mono for updated BCL tests

see https://github.com/mono/mono/pull/5820

* [mono] set 2017-10 branch in .gitmodules

* [macos] Fix guiunit error on clean builds by depending on correct copy (#2912)

* [macos] Fix guiunit error on clean builds by depending on correct copy

- From a clean build making a BCL test would error due to the non-mobile guiunit not being built
- This was because the Makefile-mac.inc target was incorrect
- This was because xharness assumed that non variation based targets were always Modern
- However, BCL tests are Full, not Modern

* Code review change

* Swap to var to reduce diff

* Revert changes in the paths for GuiUnit.

* [XHarness] Add the System.IO.Compression bcl tests. (#2918)

* [XHarness] Add the System.IO.Compression bcl tests.

*  [XHarness] Add bcl tests for System.IO.Compression.FileSystem. (#2924)

* [XHarness] Add the System.IO.Compression bcl tests.

* Ensure that resources are correctly copied in the bundles.

* [XHarness] Add bcl tests for System.IO.Compression.FileSystem.

* As per review, make the Mac test app name match the tests that are ran.

* [XHarness] Add Mono.CSharp tests on ios. (#2927)

* [XHarness] Add Mono.CSharp tests on ios.

* Bump mono to bring changes in the mono.csharp tests.

* [xtro-sharpie] fix TypeDefinition access due to Cecil change

* Bump mono

* bump mono

fixes
- https://bugzilla.xamarin.com/show_bug.cgi?id=60480
- https://bugzilla.xamarin.com/show_bug.cgi?id=60482

* bump mono

more fixes around conflicting paths when tests are run in parallel.

* Bump for mono/mono@2017-10
2017-11-14 21:30:08 +01:00
Alex Soto 21a56a5f27
[generator] Improve BI1014 - include name of unsupported field and update valid types on docs, fixes bug 57094. (#3001)
* [generator] Improve BI1014 - include name of unsupported field and update valid types on docs, fixes bug 57094.

https://bugzilla.xamarin.com/show_bug.cgi?id=57094

* Implement feedback

* fix error message

* More feedback
2017-11-14 08:46:46 -06:00
Alex Soto b197eab50e
[generator] Fix slightly incorrect error message when trying to use ref/out parameters with BindAs attributes, fixes 57804. (#2997)
https://bugzilla.xamarin.com/show_bug.cgi?id=57804
2017-11-13 14:21:18 -06:00
Alex Soto ee19c79feb
[Generator] BindAs attribute for smart enums of an array of nullable values generates code that doesn't compile, Fixes bug 57797 (#2954)
* [Generator] BindAs attribute for smart enums of an array of nullable values generates code that doesn't compile, Fixes bug 57797

https://bugzilla.xamarin.com/show_bug.cgi?id=57797

We now correctly compiles the array nullabe types

* Disable Nullable array types in BindAs until we add registrar support
2017-11-13 10:54:21 -06:00
Alex Soto 8e92d2a350
[Generator] BindAs attribute for smart enum to multidimensional array generates code that doesn't compile, Fixes Bug 57795 (#2948)
https://bugzilla.xamarin.com/show_bug.cgi?id=57795

We now error out with "BI1048 Unsupported type Foo[,] decorated with [BindAs]"
2017-11-02 08:34:10 -06:00
Rolf Bjarne Kvinge 40d9cb9bf1 Merge remote-tracking branch 'origin/master' into bindas-registrar-support 2017-09-26 10:58:35 +02:00
Rolf Bjarne Kvinge cd542a0845 [generator] Remove non-IKVM code. (#2769) 2017-09-25 14:37:51 -04:00
Rolf Bjarne Kvinge a979a10412 Merge remote-tracking branch 'origin/master' into bindas-registrar-support 2017-09-22 10:50:07 +02:00
Alex Soto dc1b5746eb [generator] Fix smart enum FieldAttribute LibraryName generation (#2376)
This fix is needed by PDFKit because it is a remapped framework[0],
the current code generates incorrect FieldAttribute on smart enums
because it uses `fa.LibraryName` as first option and this causes
remmaped frameworks have incorrect LibraryName generated for example
if a Field uses `+CoreImage` as `LibraryName` the following incorrect
code is generated:

```
	[Field ("First", "+CoreImage")]
	internal unsafe static IntPtr First {
		get {
			fixed (IntPtr *storage = &values [0])
				return Dlfcn.CachePointer (Libraries.+CoreImage.Handle, "First", storage);
		}
	}
```

[0]: f5956d6cc1/src/generator.cs (L5985)
2017-07-26 18:09:42 -05:00
Rolf Bjarne Kvinge 871c055308 [generator] Add unit test project, and port a few tests over from the makefile tests. (#2299) (#2304) 2017-07-11 08:52:24 +02:00
Alex Soto 81e1340865 [generator] Persist BindAs attribute information in generated code.
Persisting BindAs attributes is required for the registrars to be able to
handle methods with BindAs attributes correctly.

Generator diff: https://gist.github.com/rolfbjarne/0fafbce9373ff1f407839a20ea5e72e9
2017-07-04 07:31:13 +02:00
Alex Soto 3c5221b214 [generator] Add enum support for [FieldAttribute], Fixes 57537 and 57535. (#2230)
* [ObjCRuntime] Add GetUInt32/SetUInt32/SetNInt/SetNUInt/SetNFloat to Dlfcn

https://bugzilla.xamarin.com/show_bug.cgi?id=57535
https://bugzilla.xamarin.com/show_bug.cgi?id=57537

This commit is part of the fix for the above bugs, we lacked
GetUInt32/SetUInt32/SetNInt/SetNUInt/SetNFloat in Dlfcn and we
have code inside generator that relies on the methods to be
available 0a316951a3/src/generator.cs (L6090-L6095)

* [generator] Add enum and uint support to FieldAttribute

Fixes:
* https://bugzilla.xamarin.com/show_bug.cgi?id=57535
* https://bugzilla.xamarin.com/show_bug.cgi?id=57537

New Features:
* Added Smart Enum support to [Field]
* Added [Native] enum support to [Field]
* Added enum support to [Field]
* Added uint support to [Field]

Also fixed a bug in Smart Enums support when computing the library name
taking into account third party bindings and some special cases, this is
needed because we ended up generating invalid code when Smart Enum support
was used in third party bindings.

Also added Field Enum generation test.

* Implement PR feedback and added [Get/Set]UInt64 to Dlfcn and [Field] support for it too.
2017-06-20 13:46:00 -05:00
Rolf Bjarne Kvinge bc75388fbc [generator] Improve error reporting for api definition that uses the deprecated availability attributes. Fixes #57070. (#2166)
https://bugzilla.xamarin.com/show_bug.cgi?id=57070
2017-06-02 18:31:10 +02:00
Alex Soto 43e220df7f [generator] Keep [NotImplemented] info so it is usable in 3rd party bindings. Fixes bug 52664 (#2131)
* [generator] Keep [NotImplemented] info so it is usable in 3rd party bindings. Fixes bug 52664

https://bugzilla.xamarin.com/show_bug.cgi?id=52664

Currently we do not keep the [NotImplemented](0) information and the
generator gets a little confused because it will not find an Export
inside the getters/setters of properties and there is no way to tell
if this was intentional or not. We now keep the [NotImplemented]
and also add some null checks in the generator where needed.

Reenabled tests disabled in 9f036b218a

[0]: https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-c-libraries/#Objective-C_Mutable_Pattern_and_Properties

* [generator] Implement feedback

* Added quote method
* Teach linker about NotImplementedAttribute

* [generator] Improve Quote method

* [generator] Fix quote now for realsssss
2017-05-25 14:42:25 -05:00
Alex Soto b75f8eda31 [generator] Create CVPixelBuffer using GetINativeObject so its usable from 3rd party bindings (#2111)
* [generator] Create CVPixelBuffer using GetINativeObject so its usable from 3rd party bindings

Complements https://bugzilla.xamarin.com/show_bug.cgi?id=52665
and PR #2102

CVPixelBuffer was created using the internal handle ctor, this
did not allow 3rd party bindings to bind it correctly since it
generated not compilable code.

We now use Runtime.GetINativeObject<CVPixelBuffer> (ptr, false); just
like the base ctor https://git.io/vHvLj.

* [tests] Add IntPtr.Zero check and fix link in code

* [generator] Make comment easier to find
2017-05-19 11:10:22 -05:00
Alex Soto 9621842016 [generator] Deriving from certain protocol interfaces generates uncompilable code. Fixes bug 52665 (#2102)
Some namespaces are missing on generated files, causing error CS0246
The type or namespace name `Foo` could not be found.

While fixing this another error arose, by enabling the following test

[Protocol] interface C140 : ICIImageProcessorInput {}

some codepaths leads to CVPixelBuffer creation which our code
tries to invoke the handle ctor and fails to find it because it
is internal. This will be fixed in a different commit.
2017-05-18 12:42:57 -04:00
Alex Soto ed505623be [tests] Fix RequiredMethodAsync test (#1931)
When merging https://github.com/xamarin/xamarin-macios/pull/1913 I
forgot to fix RequiredMethodAsync test, we now expect one instance of
a RequiredMethodAsync as an extension method
2017-03-29 11:12:56 +02:00
Alex Soto 28ad23d142 [generator] Remove [Async] members from [Model] classes, fixes bug 53076.
https://bugzilla.xamarin.com/show_bug.cgi?id=53076

When [Async] was used on a member of a [Model][Protocol][Basetype]
interface the ModelClass ended up with additional FooAsync methods that
are not really part of the Model.

This commit removed any instances of FooAsync members from model classes
and also fixes any breaking changes in the currently bound classes.

Added test case using Model.

build diff:
https://gist.github.com/dalexsoto/75cb8424f2462bd6b513049f00bba6a8
2017-03-25 00:35:36 -06:00
Alex Soto 340ade8c68 [generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076

We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.

Lets take the following API definition

```csharp
[Protocol]
interface MyFooProtocol {

	[Abstract]
	[Async]
	[Export ("requiredMethod:completion:")]
	void RequiredMethod (int arg1, Action<NSError> err);

	[Async]
	[Export ("optional:completion:")]
	void OptionalMethod (int arg1, Action<NSError> err);
}
```

This generates:

```csharp
public static partial class MyFooProtocol_Extensions {
	[CompilerGenerated]
	public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}

	[CompilerGenerated]
	public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		This.OptionalMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

	[CompilerGenerated]
	public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		This.RequiredMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

}
```

Adds unit test

Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 00:25:45 -06:00
Alex Soto 155e414e9c [generator] Disable CS0219 when using AsyncAttribute to avoid warning
Currently we get a CS2019 warning whenever we use AsyncAttribute
because we ignore the `result` variable on methods whose return
type is != `void` which is the expected behaviour.

This is specially more annoying on third party bindings,
the generated code did not disable this warning so you get
an "unfixable" warning on the generated code and the user
has no way to fix this on their own.

We now disable and restore CS2019 in the generated code as needed.
Nobody likes warnings that are not their fault.

Added unit test.

Build diff:

https://gist.github.com/dalexsoto/6f57d3f84b039b9fda863e2f8cfcf365
2017-03-24 21:08:40 -06:00
Alex Soto 577d0119df [generator] Remove Async members from internal BaseWrapper derived types
Currently we generate FooAsync members inside internal BaseWrapper
derived types used by protocol support. This generated Async members
are useles so we remove them to avoid extra metadata.

Old generated code

```csharp
internal sealed class MyFooDelegateWrapper : BaseWrapper, IMyFooDelegate {
	[Preserve (Conditional = true)]
	public MyFooDelegateWrapper (IntPtr handle, bool owns)
		: base (handle, owns)
	{
	}

	[Export ("stringMethod:completion:")]
	[CompilerGenerated]
	public unsafe void StringMethod (int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (this.Handle, Selector.GetHandle ("stringMethod:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}

	[CompilerGenerated]
	public unsafe Task StringMethodAsync (int arg1)
	{
		var tcs = new TaskCompletionSource<bool> ();
		StringMethod(arg1, (obj_) => {
			if (obj_ != null)
				tcs.SetException (new NSErrorException(obj_));
			else
				tcs.SetResult (true);
		});
		return tcs.Task;
	}

}
```

new generated code:

```csharp
internal sealed class MyFooDelegateWrapper : BaseWrapper, IMyFooDelegate {
	[Preserve (Conditional = true)]
	public MyFooDelegateWrapper (IntPtr handle, bool owns)
		: base (handle, owns)
	{
	}

	[Export ("stringMethod:completion:")]
	[CompilerGenerated]
	public unsafe void StringMethod (int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
	{
		if (err == null)
			throw new ArgumentNullException ("err");
		BlockLiteral *block_ptr_err;
		BlockLiteral block_err;
		block_err = new BlockLiteral ();
		block_ptr_err = &block_err;
		block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);

		global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (this.Handle, Selector.GetHandle ("stringMethod:completion:"), arg1, (IntPtr) block_ptr_err);
		block_ptr_err->CleanupBlock ();

	}
}
```

Added unit test.

build diff for this change:

https://gist.github.com/dalexsoto/eeaefc9d86e37b0c5ce5fe6d5d091383
2017-03-24 17:40:55 -06:00
Rolf Bjarne Kvinge d942fcff14 [tests][generator] Simplify mac tests a bit and fix new tests when using IKVM-based bgen.
Simplify mac tests by using different variables for the various flavors of mac
generators, and use these new flavors so that all tests pass when using the
IKVM-based bgen.
2017-03-22 16:22:33 +01:00
Rolf Bjarne Kvinge 8a29f0deae Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-22 14:11:00 +01:00
Alex Soto ebcb4ac034 [generator] Fix bug 52573 - Add nowarn and warnaserror to btouch/bmac (#1882)
https://bugzilla.xamarin.com/show_bug.cgi?id=52573

* Added nowarn and warnaserror to btouch/bmac
* Throw a BI0026 if bad args and added error to doc
* Added generator tests
2017-03-22 07:52:24 -05:00
Alex Soto 818c20b19a [generator] The [Advice] attribute doesn't make it to the generated code. Fixes #42742 (#1887)
* [generator] Fix bug 42742 The advice attribute doesn't make it to the generated code

https://bugzilla.xamarin.com/show_bug.cgi?id=42742

The Advice attribute used in our bindings was not making
into the generated code. This fixes it.

Also added unit test for it

* [generator] Merged PrintFooAttributes into one

Merged PrintPlatformAttributes, PrintPreserveAttribute and
PrintAdviceAttribute into a single method PrintAttributes.
This is due to sometimes we call three times in a row the same method:

```csharp
PrintPlatformAttributes (pi.GetGetMethod ());
PrintPreserveAttribute (pi.GetGetMethod ());
PrintAdviceAttribute (pi.GetGetMethod ());
```

We now do

```csharp
PrintAttributes (pi, platform:true, preserve:true, advice:true);
```

Also removed a not used instance (internal field) of AdviceAttribute
2017-03-21 09:20:05 -06:00
Rolf Bjarne Kvinge 001790ff4e Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-16 19:09:33 +01:00
Alex Soto 78052430ab [generator] Fixes bug 52570 - [generator] warn when [Static] is used in a [Category] (#1862)
https://bugzilla.xamarin.com/show_bug.cgi?id=52570

In some cases you will find **static** members inside categories like in the following example:

```objc
@interface FooObject (MyFooObjectExtension)
+ (BOOL)boolMethod:(NSRange *)range;
@end
```

This will lead to an **incorrect** Category C# interface definition:

```csharp
[Category]
[BaseType (typeof (FooObject))]
interface FooObject_Extensions {

	// Incorrect Interface definition
	[Static]
	[Export ("boolMethod:")]
	bool BoolMethod (NSRange range);
}
```

This is incorrect because in order to use the `BoolMethod` extension you need an instance of `FooObject` but you are binding an ObjC **static** extension, this is a side effect due to the fact of how C# extension methods are implemented.

The only way to use the above definitions is by the following ugly code:

```csharp
(null as FooObject).BoolMethod (range);
```

The recommendation to avoid this is to inline the `BoolMethod` definition inside the `FooObject` interface definition itself, this will allow you to call this extension like it is intended `FooObject.BoolMethod (range)`.

```csharp
[BaseType (typeof (NSObject))]
interface FooObject {

	[Static]
	[Export ("boolMethod:")]
	bool BoolMethod (NSRange range);
}
```

We will issue a warning (BI1117) whenever we find a `[Static]` member inside a `[Category]` definition. If you really want to have `[Static]` members inside your `[Category]` definitions you can silence the warning by using `[Category (allowStaticMembers: true)]` or by decorating either your member or `[Category]` interface definition with `[Internal]`.
2017-03-14 13:03:13 -06:00
Rolf Bjarne Kvinge a719e1f480 Merge remote-tracking branch 'origin/master' into generator-ikvm 2017-03-14 17:59:45 +01:00
Alex Soto 0ada7dedce [generator] Fixes bug 42855 generator should report an error for [Protocol] without a [Model] that specify a [BaseType] (#1859)
https://bugzilla.xamarin.com/show_bug.cgi?id=42855

We had some logic to catch this but we did not do anything with it.
We now error out with BI1060 whenever we find [Model] but no [BaseType]
added test case.

I am using BI1060 because Rolf reserved today the missing ones in PR
https://github.com/xamarin/xamarin-macios/pull/1849
2017-03-10 09:52:32 -06:00
Rolf Bjarne Kvinge 1d5f432d4f [tests][generator] Add support for running tests with the IKVM-based generator. 2017-03-09 12:47:57 +01:00
Rolf Bjarne Kvinge 88c276e0aa [tests][generator] Port XI/Classic tests to XI/Unified. (#1745)
* [tests][generator] Port XI/Classic tests to XI/Unified.

* [tests][generator] Comment out code triggering previously unknown bugs.

These tests makes the generator fail:

    error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
    System.NullReferenceException: Object reference not set to an instance of an object
      at Generator.GetSetterExportAttribute (System.Reflection.PropertyInfo pinfo) [0x0002e] in /work/maccore/master/xamarin-macios/src/generator.cs:1981
      at Generator.Go () [0x007e3] in /work/maccore/master/xamarin-macios/src/generator.cs:2162
      at BindingTouch.Main2 (System.String[] args) [0x010b2] in /work/maccore/master/xamarin-macios/src/btouch.cs:435
      at BindingTouch.Main (System.String[] args) [0x0001d] in /work/maccore/master/xamarin-macios/src/btouch.cs:77
      at System.Environment.get_StackTrace () [0x00000] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Environment.cs:321
      at ErrorHelper.ShowInternal (System.Exception e) [0x000dc] in /work/maccore/master/xamarin-macios/src/error.cs:200
      at ErrorHelper.Show (System.Exception e) [0x00027] in /work/maccore/master/xamarin-macios/src/error.cs:151
      at BindingTouch.Main (System.String[] args) [0x0002b] in /work/maccore/master/xamarin-macios/src/btouch.cs:79

This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52664.

* [tests][generator] Comment out code triggering previously unknown bugs.

This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52665.
2017-02-22 16:47:11 +01:00
Rolf Bjarne Kvinge 00874dc1e7 [tests][generator] 'virtualwrap' is a custom test, so put it in the corresponding variable. (#1743)
Fixes this warning:

    Makefile:163: warning: overriding commands for target `virtualwrap'
    Makefile:40: warning: ignoring old commands for target `virtualwrap'
2017-02-22 14:23:45 +01:00
Alex Soto a021c0cd3c [generator] Have WrapAttribute generate virtual members (#1707)
* [generator] Have WrapAttribute generate virtual members

WrapAttribute now has a boolean optional parameter named isVirtual,
this instructs the generator to add the virtual keyword to generated
members.

This is useful when fixing breaking changes so we can keep the wrong
signature generated instead of having manual code files.

* [docs] Add docs about virtual to WrapAttribute
2017-02-16 17:24:40 -06:00
Alex Soto 1799c2f489 [generator] Add BindAs support (#1476)
* [generator] Add BindAs support for NSValue and NSNumber
https://trello.com/c/RYCPEnkh

The intent of BindAs attribute is to have a binding definition as

	[return: BindAs (typeof (bool?))]
	[Export ("boolMethod:")]
	NSNumber BoolMethod (int arg1);

and our generator outputs

	[Export ("boolMethod:")]
	public virtual global::System.Nullable<bool> BoolMethod (int arg1) { ...  }

So we internally do the NSNumber <-> bool conversion, this also
applies to properties, parameters and methods.

* [generator] Fix a small formating issue

* [tests] Add BindAsAttribute generator tests

* [generator] Implement @spouliot's feedback

* [tests] Add BI1048 and BI1049 error tests for [BindAs]

* [generator] Implement Rolf's suggestion to avoid almost all string comparisons in [BindAs] for types

* [generator] Add BindAs support for smart enums and arrays with tests

* [generator] Some code clean up and implementation of PR feedback

* [generator] Add Protocol|Model checks and tests also a NRE check in NSArray creator

BindAs attribute cannot be used in Protocol|Model interfaces

* [generator] Add NSNumber <-> Enum support

* [docs] add BindAs documentation

* [docs] Implement documentation feedback for BindAs
2017-01-25 07:14:55 +01:00
Sebastien Pouliot ee046ee034 [generator] Copy [Obsolete] attributes on smart enums. Fixes #46292 (#1104)
Covers attributes on the type itself and on its members.

Reference:
* https://bugzilla.xamarin.com/show_bug.cgi?id=46292
2016-11-02 23:18:59 -04:00
Sebastien Pouliot e55385637f [generator] Allow identical (numeric) values in smart enums. Fixes #46285 (#1102)
Considering the following binding code:

    public enum HMAccessoryCategoryType {
        [Field ("HMAccessoryCategoryTypeGarageDoorOpener")]
        DoorOpener,

        GarageDoorOpener = DoorOpener,
    }

We must

1. Ensure that `HMAccessoryCategoryType.DoorOpener.GetConstant () ==
	HMAccessoryCategoryType.GarageDoorOpener.GetConstant ()`;

This is done by using the numeric value of the enum member (instead of the name)

2. Ensure that `HMAccessoryCategoryTypeExtensions.GetValue ("HMAccessoryCategoryTypeGarageDoorOpener")`
   always return the same enum value, i.e. it can **not** change between
   XI versions (e.g. due to reflection ordering) as it could break
   comparison code;

This is done by only adding a map to the member that has a [Field] and
means that:

2.1. the _favorite_ enum member should be the one with the [Field]; and

2.2. a [Field] value can only be used once per enum (or else we report
     an BI1046 error). This also solve the duplicate code generation for
	 the constant loading code;

Reference:
* https://bugzilla.xamarin.com/show_bug.cgi?id=46285
2016-11-02 21:46:04 -04:00
Alex Soto ff326bdfdb [generator] ForcedType is now only valid on parameters, properties and return value
https://bugzilla.xamarin.com/show_bug.cgi?id=37175
https://bugzilla.xamarin.com/show_bug.cgi?id=44322

* ForcedType is now only valid on parameters, properties and return value
* Added generator test
* Fixed bindings accordingly
* Fixed docs
2016-09-26 03:57:57 -05:00
Alex Soto e397849108 [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates (#817)
* [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates
https://bugzilla.xamarin.com/show_bug.cgi?id=43579

Bug Description:
Generator will emit invalid code when using the same name (overload)
in a method inside a @delegate (protocol) that is decorated
either with EventArgs or DelegateName

-----------------------------------------------------------------

This commit introduces a new attribute named DelegateApiNameAttribute
which mimics the EventNameAttribute but for delegate properties in
host classes

It is used to specify the delegate property name that will be created when
the generator creates the delegate property on the host
class that holds events and delegates.

This is really useful when you have two overload methods that makes
sense to keep them named as is but you want to expose them in the host class
with a better given name.

example:
 interface SomeDelegate {
     [Export ("foo"), DelegateApiName ("Confirmation"), DelegateName ("Func<bool>"), DefaultValue (false)]
     bool Confirm (Some source);
 }

 Generates propety in the host class:
	Func<bool> Confirmation { get; set; }

This also introduces two new BIXXXX errors:
- BI1043 Repeated overload {mi.Name} and no [DelegateApiNameAttribute]
provided to generate property name on host class.
- BI1044 Repeated name '{apiName.Name}' provided in [DelegateApiNameAttribute].

Which provides an error instead of generating invalid C# code.

Generator test included :D

* [docs] Added DelegateApiNameAttribute and IgnoredInDelegateAttribute docs

Also added Protocol where Model was used in our docs so we do not
misslead customers about it
2016-09-14 08:20:08 -04:00
Manuel de la Pena 90c7eab95e [Fix] Ensure that strong dictionaries can work with templated dictionaries as property types. 2016-06-13 12:13:48 +02:00
Rolf Bjarne Kvinge 4a714f3c43 Make logic not depend on the checkout directory being named 'xamarin-macios'. (#129) 2016-06-06 12:18:52 +02:00
Rolf Bjarne Kvinge ecfdea9508 [tests] Import 2016-05-26 15:06:52 +02:00