- Layout loading `ViewSubclass`
- `ViewSubclass` applies theme attributes
- Fixed casing issues in JNI calls
- Java unit test verifies the right text comes out
- Included better references for Resource.designer.dll
- Resource.designer.dll runs through the linker (which should clean up
its references)
- Added an android theme with attributes
- Support for int[] resource fields
- Needs tests validating the attributes and theme works
- C# resource Ids need to be remapped to what is generated from Java in
the final APK
- This generates `Resource.designer.dll` which hooks into
`ResourceIdManager`
- Right now I have hardcoded C# code that gets our tests to pass
- [Activity] properly gets registered in manifest
- Cleaned up namespaces in tests
- Added a simple C# activity
- Wrote a test to launch an activity (not passing yet)
- Put master build of Xamarin.Android at external/Xamarin.Android (add
to ignore list)
- Use -xamarinPath parameter to point to it
- Convert -xamarinPath to absolute path in CLI.cs
- Remove `PortablePdbFiles` as it was removed with newer XA
- https://github.com/mono/Embeddinator-4000/issues/369
- Push ProcessedTypes into all post processing steps and add containing type info
- Improve duplicate detection by using "real" selector instead of hack
- More work to be done in other places, but at least removes the "temporary quasi-duplicate" code
- We don’t want developers to have to pull jna-4.4.0.jar into their
project
- This unzips it into our jar, so they just have to worry about a
single file
- Updated tests, so it is not using the jar from /external/jna
- Now uses `—compile` option on embeddinator instead of manually
calling `javac` and `jar`
- I like this a lot better because CI is actually testing the code I’ve
been modifying
- Hopefully this fixes the build
* [objc] Add NSDate <-> DateTime support.
DateTime v.s. NSDate
====================
From [NSDate's](https://developer.apple.com/reference/foundation/nsdate?language=objc) documentation:
> NSDate objects encapsulate a single point in time, independent of any particular calendrical system or time zone. Date objects are immutable, representing an invariant time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001).
Due to NSDate reference date, all conversions between it and DateTime must be done in UTC.
DateTime to NSDate
==================
When converting from `DateTime` to `NSDate` the DateTime's `Kind` property is taken into account.
| Kind | Results |
| ------------ | -------------------------------------------------------------------------------------------------- |
| Utc | Conversion is performed using the provided DateTime object as is. |
| Local | The result of calling `ToUniversalTime ()` in the provided DateTime object is used for conversion. |
| Unspecified | The provided DateTime object is assumed to be UTC, so same behavior as Kind == Utc. |
The conversion is done by using the following formula:
**TimeInterval** = DateTimeObjectTicks - NSDateReferenceDateTicks[dt] / [TicksPerSecond](https://msdn.microsoft.com/en-us/library/system.timespan.tickspersecond(v=vs.110).aspx)
Once we have the TimeInterval we use NSDate's [dateWithTimeIntervalSinceReferenceDate:](https://developer.apple.com/reference/foundation/nsdate/1591577-datewithtimeintervalsincereferen?language=objc) selector to create it.
NSDate to DateTime
==================
Going from NSDate to DateTime we assume we are getting a NSDate instance which's reference date is **00:00:00 UTC on 1 January 2001** and use the following formula:
**DateTimeTicks** = NSDateTimeIntervalSinceReferenceDate * [TicksPerSecond](https://msdn.microsoft.com/en-us/library/system.timespan.tickspersecond(v=vs.110).aspx) + NSDateReferenceDateTicks[dt]
Once we calculated the **DateTimeTicks** we use the following DateTime [constructor](https://msdn.microsoft.com/en-us/library/w0d47c9c(v=vs.110).aspx) setting its `kind` to `DateTimeKind.Utc`.
There are some considerations that you must be aware of, NSDate can be `nil` but a DateTime is a struct in .NET and by definition it can't be `null`. If you give a `nil` NSDate we will translate it to the default DateTime value which maps to `DateTime.MinValue`.
MinValue and MaxValue are also different, NSDate can support greater and lower boundaries than DateTime's so whenever you give a greater or lower value we will set it to DateTime's [MaxValue](https://msdn.microsoft.com/en-us/library/system.datetime.maxvalue(v=vs.110).aspx) or [MinValue](https://msdn.microsoft.com/en-us/library/system.datetime.minvalue(v=vs.110).aspx) respectively.
**dt**: NSDate reference date **00:00:00 UTC on 1 January 2001** => `new DateTime (year:2001, month:1, day:1, hour:0, minute:0, second:0, kind:DateTimeKind.Utc).Ticks;`
* [objc] Implement feedback
* Code was simplified a lot by just harcoding the following values
$ csharp -e 'DateTime.MaxValue.Ticks'
3155378975999999999
$ csharp -e 'DateTime.MinValue.Ticks'
0
$ csharp -e 'TimeSpan.TicksPerSecond'
10000000
// NSDate reference date 00:00:00 UTC on 1 January 2001
// https://developer.apple.com/reference/foundation/nsdate
define NSDateRefDateTicks 631139040000000000LL
define NetTicksPerSecond 10000000LL
define DateTimeMaxValueTicks 3155378975999999999LL
define DateTimeMinValueTicks 0LL
* Added a strongly defined type for DateTime (E4KDateTime) instead
of just using void*
* Fixed some issues in docs
* [objc] Remove unused members from DateTime linker support
* [objc] Fix variable scope issue when clang optimizes code
* [objc] Replace DateTime for DBNull in TypeMatchFailure test since we now implement DateTime support
Code was already present (copied from mtouch/mmp with ErrorHelper.cs) so
it's an easy and useful thing to expose.
Use `--nowarn` on UnitsNet sample to reduce the warnings that we cannot
fix (since we're using a binary downloaded from nuget)
Add unit tests for `--nowarn`. The one for `--warnaserror` did not work,
at least inside VSfM, due to bug #55801, resulting in:
> mono_os_mutex_lock: pthread_mutex_lock failed with "Invalid argument" (22)
This replace the older (not linker friendly) PR #251.
It brings, if required, `System.TimeSpan` inside your projects since
there is direct, good alternative, i.e. `NSTimeInterval` is just a
typedef on `double`.
* [mac] Link SDK is only supported for the modern profile
* [mac] Provide `--nolink` to mmp when the linker is not supported
The earlier problem (and test failures) is that, by default `mmp` (like
`mtouch`) does a **link all**.
It's easy to forget since we don’t normally use the command line (but
the UI of an IDE) to call `mmp`.
* Add multiple new platforms, one for each Xamarin.Mac flavor
(modern/full/system), and make these new platform values build a framework
using mmp.
* Add support for creating a framework for the existing `macOS` platform
(which does not include Xamarin.Mac).
* Rework testing significantly, adding unit tests for Xamarin.Mac framework support:
* Make managed.csproj a shared library project, and make another project
managed-*.csproj for each platform we support that references this
shared project.
* Add managed unit tests that runs the embeddinator on the corresponding
managed-*.csproj, generates an Xcode test project, and runs the tests in
the generated Xcode project. This is a replacement for a few identical
tests in tests/objc-cli/Makefile (and those are now removed).
* [objc] Document the various Objective-C platforms we can target.
* [objc] Add NSDecimalNumber ReturnType support
Array return type pending
* [objc] Implement feedback and added ReturnType array support
* Added linker.xml to mtouch so it keeps decimal.ToString(IFormatProvider)
* Moved nsdecimalnumber creation logic into its own method to reduce code
duplication. mono_embeddinator_get_nsdecimalnumber
* Added mono_embeddinator_get_decimal_class to cache its value
* Added MonoDecimal struct definition from
https://github.com/mono/mono/blob/master/mono/metadata/decimal-ms.h
needed by mono_array_get.
* Added ReturnType array support
* Moar tests!! 🐟🐈
* [objc] Fix link.xml identation and added a note about issue #301
* [objc] Move MonoDecimal to mono-support.h and fix feedback
* [objc] Add NSDecimal <-> decimal parameter[Array] support
* [objc] remove indentation fixes so it can be PR'ed separately
* [objc] implement feedback
* Add Quote to --xml path
* Reduced if nesting on decimal mono_array_set
* Renamed mono_embeddinator_get_monodecimal to mono_embeddinator_get_system_decimal
This is required so we can detect, fix or select duplicate members
correctly. The processor will have all the information and will give
a working set of Processed* instance to the generator (where no
validations will be needed)
note: known failures running tests (signatures are incorrect for members
with default values)
- drop all single arguments for compilation target (--dll, --shared, --static).
- use the right value names for --target.
- [tests] Update Static_Unsupported to use --target
* [objc][tests] Add objcgen warning and error tests. Fixes issue #104
* Adds support for testing error conditions in Xcode projects
see XcodeBuildErrorTest inside ObjCGenErrWarnTests.cs
* Adds a library to create warning conditions to test objcgen
and its correponding test (GenWarningTest inside ObjCGenErrWarnTests.cs).
* Fix atrocious spaces identation
* Fix more identation thanks to VS4Mac not honouring my settings...
* [objc][objcgentest] Add support for not finding a warning message
* Kill more spaces with 🔥 I mean tabs
* [objc][tests] Implemented feedback
* XcodeApp prop was made public in order for it to be accesible by tests
* Removed Xcode project usage and replaced it with clang
* Replaced manually created temp dirs by our shared
Xamarin.Cache.CreateTemporaryDirectory ();
* [objc] Use xcrun clang instead
* [objc] Add Array support for ReturnTypes
* byte [] to NSData
* string [] to NSArray<NSString *> *
* Foo [] to NSArray<Foo *> *
* numeric valueType [] to NSArray<NSNumber *> *
* [objc] Fix GetArrayTypeName, byte[] and memory allocation for temp array
We now use `mono_array_addr` to marshal byte[] to NSData.
Fixed GetArrayTypeName to return the correct type name.
Fixed a null case and added tests for readonly props.
Notes on temp array (__resarrbuf):
According to [Transitioning to ARC Release Notes](1) in order to
create a C array of retained pointers under ARC you must meet the
following conditions:
* The allocated memory must be zero-filled.
* You must set each element to nil before freeing.
* Don’t rely on the default variable qualifier to be __strong, it
is __autoreleasing.
* You should avoid memcpy/realloc.
So adjusted code to do so.
[0]: https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
* [objc] Fix feedback, add interface arr and parameters arr support
Also made ReturnArrayValue code smaller for NSNumber boxed types
* [objc] Fix implicit declaration of function x is invalid in c99
* [objc] Fix all the spaces!!
Embedding with Xamarin.iOS is different than doing it directly with mono.
This requires some methods to be defined, like the ones only used for
release (when `TOKENLOOKUP` is defined).
The integration with mtouch is also incomplete (for non-debug build) as
some steps (MdbSym) and SymbolStrip (only used in release by default)
causes FileNotFoundException (some state is not set correctly).
This PR is a fix for the former (headers), a workaround for the later
(mtouch invocation) and a Makefile change to make sure we always build
release/iOS on bots (because untested stuff never works, for long)
ref: https://github.com/mono/Embeddinator-4000/issues/237
In such case a warning will be displayed and nothing will be generated.
Test added so we can ensure such condition does not stop the generation
with an error.
Solve:
```
Generating binding code...
error EM0009: The feature `Returning type Nullable`1 from native code` is not currently supported by the tool
```
when a nullable type (not yet supported [1]) was used in extensions
methods.
[1] https://github.com/mono/Embeddinator-4000/issues/229
* Arguments should be at least 3 charactesr long
* Only add the parameter name to short arguments if there are multiple of the same type
* Method implementations also need the updated parameter names
* Fix spacing
* Use Extension for ExtendedName on parameters
* Fix indentation (spaces -> tabs) issues
* Move ObjCTypeToArgument dictionary to NameGenerator
* Move the ExtendedName extension method to a NameGenerator method
- c36d639770 removed need for exception but it was not removed
- Fixes https://github.com/mono/Embeddinator-4000/issues/207 from operator issues. Now hitting:
error EM0009: The feature `Returning type Nullable`1 from native code` is not currently supported by the tool
and add unit tests. This required a few other changes like:
* Getting the managed instance, if it exists, from a native instance is
moved to the support code (so it can be shared for multiple usages);
* Most (unless static) bound types now expose `xamarinGetGCHandle`, i.e.
not just the one where `isEqual:` is implemented);
* `xamarinGetGCHandle` exists only inside the implementation (.m), not
in the header (.h) file and is commented to be for internal uses only;
* EqualsHelper is modified to reuse the shared code;
This happens if there's no initialization. Previously the lack of a
public `.ctor()` meant we did not generate the code (nothing to call).
This was not correct (since it's valid in .net) so we detect the
condition and generate a simpler `init` method in such case.
Unit tests added (for the existing `Point` type that suffered, unnoticed,
from this)
* [objc] Don't generate code for types that inherit from NSObject, the static registrar does that.
* [objc] Find referenced platform assemblies.
* [objc] Copy the registrar.h file mtouch generated into the framework.
And also create an umbrella header that includes everything else, for easy
consumption by framework consumers.
* [objc] Add an initialization method for the generated registrar code.
* [tests][objc] Add tests for NSObject subclasses.
* [objc] Bump required XI version.
* [tests][objc] Rework the managed tests to use a shared project.
We now have the following structure:
* tests/managed/managed-shared.shproj: this is a shared project that contains
all the source code.
* tests/managed/generic/managed-generic.csproj: this is a project that builds
the shared projects for desktop, without referencing neither Xamarin.Mac nor
Xamarin.iOS.
* tests/managed/ios/managed-ios.csproj: this is a project that builds the
shared project for iOS.
This allow an .NET API to return an interface. That interface is defined
as a protocol in ObjC.
We also supply an internal `__*Wrapper` class so ObjC can call the
interface members.
Also fix virtual calls - the current code was calling the interface
itself, not the implementation for it.
Note: it's basic in the sense that it does not allow .NET to call back
into ObjC code (that conforms to the protocol).
* Detect any duplication based on the assembly (internal) name and also
it's sanitized (safe) name. Otherwise generated code won't work;
* Avoid recomputing the name (or safe name) whenever possible;
* Adjust unit tests for some code movement that ease reuse;
* Post-process steps to handle duplicate methods
- https://github.com/mono/Embeddinator-4000/issues/71
- https://github.com/mono/Embeddinator-4000/issues/144
* Fix duplicate ctors and improve post processing support
- ProcessedConstructor and ProcessedFieldInfo join Methods and Fields
- Not all are used, but now we are consistent
- Move a misplaced test
* Fix merge
* Add total hack to get test passing
* Fix double suffix issue
* Correctly handle duplicate methods by resolving against more than just name
- Foo () and Foo (int) do not conflict, even if names collide
- So use representation that takes number of arguments in mind
* Fix build
* Fix regression from merge
In general we don't encourage `null` since it's likely to get managed
`ArgumentNullException` which cannot be well handled on the ObjC side.
That's covered by:
> NS_ASSUME_NONNULL_BEGIN
Right now we lack any metadata to make this more precise :-(. However,
when possible, we can put specific annotations on some API, e.g.
1. Any managed exception in a `.ctor` (or the `.cctor`) will make the
corresponding `init*` method return `nil`, so we always mark them as
`nullable`.
2. `ref` and `out` on reference types can be `nullable`
3. Our custom support for `IComparable` and `IComparable<T>` is null safe
so mark it as such;
Warnings from our unit tests, which abuse `nil` since it knows the
managed code internals, now ignore those warnings (pragma)
Xamarin.iOS/Mac will need to customize this code, since it can't include the
system Mono headers, and it's a lot easier to customize the code if it's in a
single file.
This gets priority over the `IComparable` implementation, using
`System.Object`, if present.
We let the normal generation cover cses of `IComparable<T>` when `T` is
not the declaring type. E.g.
> public class X : IComparable<Y>, IComparable<Z> {}
* [objc] Don't use static state.
It confuses the tests suite, which may run multiple tests in the same process.
* [objc] Sanitize the generated names so that we don't print invalid Objective-C identifiers.
* [objc] Add support for non-generic `IComparable` interface
We cannot support the _normal_ `IComparable` signature
> Int32 CompareTo(System.Object)
because `System.Object` is not `NSObject`. It's also not the pattern used
in Apple frameworks.'
But we can easily match it to the common (Foundation) signature
> - (NSComparisonResult)compare:(NSSomething *)other;
Part of the fix for:
https://github.com/mono/Embeddinator-4000/issues/124
* [tests][objc] Add missing file
- For indexed properties with integral input types, we can expose those via "Indexed Subscripting":
(id)objectAtIndexedSubscript:(*IndexType*)idx;
(void)setObject:(id)obj atIndexedSubscript:(*IndexType*)idx;
The managed API could return `null` even if no exception occurred
so we tried to create an object with `mono_embeddinator_create_object (__result);`
and 💥 so we check now if `__result` is `null` and return `nil` instead.
Otherwise we might not be able to call methods, because clang will look for any matching selector in any type it knows about, which results compiler errors like:
```
In module 'XCTest' imported from /work/Embeddinator-4000/tests/objc-cli/libmanaged/Tests/Tests.m:1:
In module 'UIKit' imported from /Applications/Xcode83.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCUIElement.h:8:
/Applications/Xcode83.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:24:51: note: one possibility
@property(nonatomic,readonly) UIAccelerationValue x;
^
In file included from /work/Embeddinator-4000/tests/objc-cli/libmanaged/Tests/Tests.m:3:
../build/test-framework-ios-temp-dir/iPhoneSimulator/managed.framework/Headers/managed.h:323:39: note: also found
@property (nonatomic, readonly) float x;
^
/work/Embeddinator-4000/tests/objc-cli/libmanaged/Tests/Tests.m:171:13: error: multiple methods named 'y' found with mismatched result, parameter type or attributes
XCTAssert ([p2 y] == -2.0f, "y 2");
^~~~~~
```
So by declaring the proper type for variables, clang doesn't have to guess.
.NET .ctor are not inherited but `init*` methods are in ObjC, we now
mark as `NS_UNAVAILABLE` the ctors that are not available.
Also this commit introduces `objcgenerator-helpers.cs` which its main
intention is to move the small ObjC related functions like
`GetSignatures` or `GetUnavailableParentCtors` to avoid
polluting too much `objcgenerator.cs` readability
* [tests][objc] Build debug tests into a subdirectory as well.
This cleans up the current directory quite a bit.
Also modify the cli/perf tests a little bit to be able to run the
debug/release versions in parallel.
* [tests][objc] Don't fail to create directory if directory already exists.
* [tests][objc-cli] Make sure libmanaged.dylib is built before xctest.
Since the corresponding xcode project builds libmanaged.dylib if it's not
already built (by executing make), we may end up with two make process trying
to build the same target simultaneously, which breaks everything.
* Better name for setter only properties, e.g.
- [query set_Secret: 1];
+ [query setSecret: 1];
* Second method argument should be lowercased, e.g. `second`
[Methods_Parameters concatFirst:@"first" second:@"second"]
* Reduce some code duplication, to avoid fixing things multiple times, e.g.
* Unify the signatures generation for ObjC and Mono;
* Unify the parameter marshaling code (the one for methods was missing a lot)
* Simplify `ImplementMethod` arguments
* [objc][generator] Use metadata token lookup when building release
where release is non-debug.
https://github.com/mono/Embeddinator-4000/issues/82
* [tests] Run test-cli and perf-cli in release (non debug) mode
It's similar to XI/XM NSObjectFlag - we need a different road to call
the base classes without calling managed code twice (e.g. the Super
and Base tests for exceptions).
Note: `init` is not always exposed, so we cannot trust it blindly.
This allow the same "internal" `initWithSuper` to be re-used to return
instance of types being bound (e.g. a `+create` without a `-init`).
* [tests] [objc-cli] Improve a few Makefile targets to have correct dependencies.
* [objc] Generate a dealloc method that handles object destruction.
* [objc] Fix a memory leak when searching for assemblies.
`mono_embeddinator_search_assembly` returns a string that must be freed, so
free it.
* [objc][tests] Add leak tests.
* [tests][objc] Try running leaks with sudo if we don't have a controlling terminal.
Otherwise this happens on Jenkins:
> leaks[33383]: [fatal] unable to ask for permission to examine process; run tool using sudo, or without redirecting stdin and stderr.
* [objc] Fix chained init methods and avoid chaining dealloc.
In an init method we must only create the managed object if a derived class
hasn't already created it.
Also we must only dealloc once in the inheritance hierarchy.
This also handle the case of setter-only properties (generated as a
set* method).
Unit tests added for existing methods (previously not generated)
Replace PR https://github.com/mono/Embeddinator-4000/pull/63
E.g. `public class SuperUnique : Unique {}`
This raise an interesting issue (to be solved later) since ObjC and .NET
semantics differs for init*/.ctor. A test case (with a FIXME) is added.
and I now recall why headers were a bad idea:
./bindings.h:75:39: error: attempting to use the forward class 'Constructors_Unique' as superclass of 'Constructors_SuperUnique'
so the ordering of forwarders had to be altered a bit.
Also remove the NSAutoreleasePool code, the current code doesn't build with
ARC, and in any case it's the consumer's responsibility to ensure there's an
NSAutoreleasePool on the stack.
Remove the 'libmanaged' target from the Xcode test project, and instead link
with the libmanaged.dylib that the embeddinator compiles. This ensures we're
not compiling with different compiler flags in the Xcode project.
This also requires adding an rpath to the built library so that the test
executable can find it.
Also add makefile target to run the Xcode test project from the command line.
* EM0000 is now shown for unhandled exceptions - asking for a bug report
to be submitted;
* EM0001 is reported when the output directory cannot be found;
* EM1000 is reported when the generator throws a NotImplementedException,
no bug report is required, but contributions are welcome :)
This allows debugging the generated code with Xcode as well as
running the native unit tests with XCTest (which might not be the
best tool but it's good to support).
This commit requires a addition to mono_embeddinator so we can
override where the assemblies are loaded from - we cannot assume
they will be with the executable (e.g. plugin) and we hit this
case with Xcode unit tests.