Skip to content

Commit

Permalink
Merge branch 'master' into merge-generator-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Mar 31, 2020
2 parents b48a8b9 + 63fcc22 commit b98d435
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
50 changes: 19 additions & 31 deletions src/generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3002,18 +3002,22 @@ void GenerateEventArgsFile ()
if (probe_presence)
print ("return value != IntPtr.Zero;");
else {
var et = propertyType.GetElementType ();
bool is_property_array_wrapped_type = propertyType.IsArray && IsWrappedType (et);
bool is_property_wrapped_type = IsWrappedType (propertyType);

if (null_allowed)
print ("if (value == IntPtr.Zero)\n\treturn null;");
else if (propertyType.IsArray)
print ("if (value == IntPtr.Zero)\n\treturn new {0} [0];", RenderType (propertyType.GetElementType ()));
else
print ("if (value == IntPtr.Zero)\n\treturn Array.Empty<{0}> ();", RenderType (et));
else if (!is_property_wrapped_type && !is_property_array_wrapped_type)
print ("if (value == IntPtr.Zero)\n\treturn default({0});", RenderType (propertyType));

var fullname = propertyType.FullName;

if (propertyType.IsArray && IsWrappedType (propertyType.GetElementType ())) {
print ("return NSArray.ArrayFromHandle<{0}> (value);", RenderType (propertyType.GetElementType ()));
} else if (IsWrappedType (propertyType)){
if (is_property_array_wrapped_type) {
print ("return NSArray.ArrayFromHandle<{0}> (value);", RenderType (et));
} else if (is_property_wrapped_type) {
print ("return Runtime.GetNSObject<{0}> (value);", RenderType (propertyType));
} else if (propertyType == TypeManager.System_Double)
print (GenerateNSNumber ("", "DoubleValue"));
Expand Down Expand Up @@ -4715,20 +4719,18 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_

string var_name = null;

if (wrap == null) {
// [Model] has properties that only throws, so there's no point in adding unused backing fields
if (!is_model && DoesPropertyNeedBackingField (pi) && !is_interface_impl && !minfo.is_static && !DoesPropertyNeedDirtyCheck (pi, export)) {
var_name = string.Format ("__mt_{0}_var{1}", pi.Name, minfo.is_static ? "_static" : "");
// [Model] has properties that only throws, so there's no point in adding unused backing fields
if (!is_model && DoesPropertyNeedBackingField (pi) && !is_interface_impl && !minfo.is_static && !DoesPropertyNeedDirtyCheck (pi, export)) {
var_name = string.Format ("__mt_{0}_var{1}", pi.Name, minfo.is_static ? "_static" : "");

print_generated_code ();
print_generated_code ();

if (minfo.is_thread_static)
print ("[ThreadStatic]");
print ("{1}object {0};", var_name, minfo.is_static ? "static " : "");
if (minfo.is_thread_static)
print ("[ThreadStatic]");
print ("{1}object {0};", var_name, minfo.is_static ? "static " : "");

if (!minfo.is_static && !is_interface_impl){
instance_fields_to_clear_on_dispose.Add (var_name);
}
if (!minfo.is_static && !is_interface_impl){
instance_fields_to_clear_on_dispose.Add (var_name);
}
}

Expand Down Expand Up @@ -4759,21 +4761,7 @@ void GenerateProperty (Type type, PropertyInfo pi, List<string> instance_fields_
use_underscore ? "_" : "");
indent++;

if (wrap != null) {
if (pi.CanRead) {
PrintPlatformAttributes (pi);
PrintPlatformAttributes (pi.GetGetMethod ());
print ("get {{ return {0} as {1}; }}", wrap, FormatType (pi.DeclaringType, GetCorrectGenericType (pi.PropertyType)));
}
if (pi.CanWrite) {
PrintPlatformAttributes (pi);
PrintPlatformAttributes (pi.GetSetMethod ());
print ("set {{ {0} = value; }}", wrap);
}
indent--;
print ("}\n");
return;
} else if (minfo.has_inner_wrap_attribute) {
if (minfo.has_inner_wrap_attribute) {
// If property getter or setter has its own WrapAttribute we let the user do whatever their heart desires
if (pi.CanRead) {
PrintAttributes (pi, platform: true);
Expand Down
52 changes: 35 additions & 17 deletions tests/xharness/TestImporter/Templates/Managed/XamariniOSTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class XamariniOSTemplate : ITemplatedProject {
string WatchAppTemplatePath => Path.Combine (OutputDirectoryPath, "templates", "watchOS", "App").Replace ("/", "\\");
string WatchExtensionTemplatePath => Path.Combine (OutputDirectoryPath, "templates", "watchOS", "Extension").Replace ("/", "\\");

bool srcGenerated = false;
object srcGeneratedLock = new object ();

Stream GetTemplateStream (string templateName)
{
var resources = GetType ().Assembly.GetManifestResourceNames ();
Expand Down Expand Up @@ -229,24 +232,39 @@ internal static string GetPListPath (string rootDir, WatchAppType appType)
}
}

public async Task GenerateSource (string srcOuputPath)
// this method could be async, since we could be using async IO. The problem is that it might be called
// several times. The File and the Directory classes are not smart, and there is a possibility that we
// stop the thread between the Directory.Exist and the Directory.Delete. A nice way to solve this would be
// to set the src to get a AsyncLazy<bool> and generate the source only once on the first run, but AsyncLazy
// got move to target .netcore 5.0 (https://github.com/dotnet/runtime/issues/27510) yet we want to fix issue
// https://github.com/xamarin/xamarin-macios/issues/8240 so for the time being we lock, check, and generate
// if needed, which is better than:
//
// * Have a thread issue.
// * Generate the src EVERY SINGLE TIME for a list of projects.
public void GenerateSource (string srcOuputPath)
{
// mk the expected directories
if (Directory.Exists (srcOuputPath))
Directory.Delete (srcOuputPath, true); // delete, we always want to add the embeded src
BuildSrcTree (srcOuputPath);
// the code is simple, we are going to look for all the resources that we know are src and will write a
// copy of the stream in the designated output path
var resources = GetType ().Assembly.GetManifestResourceNames ().Where (a => a.StartsWith (srcResourcePrefix));

// we need to be smart, since the resource name != the path
foreach (var r in resources) {
var path = CalculateDestinationPath (srcOuputPath, r);
// copy the stream
using (var sourceReader = GetType ().Assembly.GetManifestResourceStream (r))
using (var destination = File.Create (path)) {
await sourceReader.CopyToAsync (destination);
lock (srcGeneratedLock) {
if (srcGenerated)
return;
// mk the expected directories
if (Directory.Exists (srcOuputPath))
Directory.Delete (srcOuputPath, true); // delete, we always want to add the embedded src
BuildSrcTree (srcOuputPath);
// the code is simple, we are going to look for all the resources that we know are src and will write a
// copy of the stream in the designated output path
var resources = GetType ().Assembly.GetManifestResourceNames ().Where (a => a.StartsWith (srcResourcePrefix));

// we need to be smart, since the resource name != the path
foreach (var r in resources) {
var path = CalculateDestinationPath (srcOuputPath, r);
// copy the stream
using (var sourceReader = GetType ().Assembly.GetManifestResourceStream (r))
using (var destination = File.Create (path)) {
sourceReader.CopyTo (destination);
}
}
srcGenerated = true;
}
}

Expand Down Expand Up @@ -314,7 +332,7 @@ string GenerateIncludeFilesNode (string projectName, (string FailureMessage, Lis
public async Task<GeneratedProjects> GenerateTestProjectsAsync (IEnumerable<(string Name, string [] Assemblies, string ExtraArgs, double TimeoutMultiplier)> projects, Platform platform)
{
// generate the template c# code before we create the diff projects
await GenerateSource (Path.Combine (OutputDirectoryPath, "templates"));
GenerateSource (Path.Combine (OutputDirectoryPath, "templates"));
var result = new GeneratedProjects ();
switch (platform) {
case Platform.WatchOS:
Expand Down
5 changes: 3 additions & 2 deletions tools/siminstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static int Main (string [] args)
var versionNode = downloadable.SelectSingleNode ("key[text()='version']/following-sibling::string");
var sourceNode = downloadable.SelectSingleNode ("key[text()='source']/following-sibling::string");
var identifierNode = downloadable.SelectSingleNode ("key[text()='identifier']/following-sibling::string");
var fileSizeNode = downloadable.SelectSingleNode ("key[text()='fileSize']/following-sibling::integer");
var fileSizeNode = downloadable.SelectSingleNode ("key[text()='fileSize']/following-sibling::integer|key[text()='fileSize']/following-sibling::real");
var installPrefixNode = downloadable.SelectSingleNode ("key[text()='userInfo']/following-sibling::dict/key[text()='InstallPrefix']/following-sibling::string");

var version = versionNode.InnerText;
Expand All @@ -191,7 +191,8 @@ public static int Main (string [] args)
var name = Replace (nameNode.InnerText, dict);
var source = Replace (sourceNode.InnerText, dict);
var installPrefix = Replace (installPrefixNode.InnerText, dict);
var fileSize = long.Parse (fileSizeNode.InnerText);
double.TryParse (fileSizeNode?.InnerText, out var parsedFileSize);
var fileSize = (long) parsedFileSize;

var installed = false;
var updateAvailable = false;
Expand Down

5 comments on commit b98d435

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Test run, Test run' 🔥

Build succeeded
✅ Packages:

API Diff (from stable)
API Diff (from PR only) (no change)
ℹ️ Generator Diff (please review changes)
🔥 Test run failed 🔥

Test results

2 tests failed, 183 tests passed.

Failed tests

  • mmptest/macOS/Debug: Failed (Execution failed with exit code 1)
  • MTouch tests/NUnit: Failed (Execution failed with exit code 4)

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on iOS on Azure DevOps(iOS): Html Report 🔥

Test results

1 tests failed, 149 tests passed.

Failed tests

  • mscorlib Part 1/iOS Unified 64-bits - device/Release: TimedOut

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ Device tests passed on TvOS on Azure DevOps(TvOS): Html Report

🎉 All 150 tests passed 🎉

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🚧 Experimental DDFun pipeline

🔥 Device tests completed (Failed) on iOS-DDFun on Azure DevOps(iOS-DDFun) 🔥

Test results

1 tests failed, 149 tests passed.

Failed tests

  • [xUnit] Mono SystemXunit/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on iOS32b on Azure DevOps(iOS32b): Html Report 🔥

Test results

14 tests failed, 147 tests passed.

Failed tests

  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - device/Debug: TimedOut
  • [xUnit] Mono SystemCoreXunit Part 1/iOS Unified 32-bits - device/Debug: TimedOut
  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): TimedOut
  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - device/Release: UseThumb: TimedOut
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): TimedOut
  • [xUnit] Mono BCL tests group 5/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: UseThumb: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): BuildFailure
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): TimedOut
  • [xUnit] Mono SystemCoreXunit Part 1/iOS Unified 32-bits - device/Release: UseThumb: TimedOut
  • [xUnit] Mono SystemCoreXunit Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): TimedOut
  • [xUnit] Mono SystemXunit/iOS Unified 32-bits - device/Release: TimedOut

Please sign in to comment.