Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\JdkInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.19606.1" IncludeAssets="none" />
<PackageReference Include="Microsoft.DotNet.GenAPI" Version="5.0.0-beta.19606.1" />
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.20078.1" IncludeAssets="none" />
<PackageReference Include="Microsoft.DotNet.GenAPI" Version="5.0.0-beta.20078.1" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason why to bump the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked to Santi the person responsible and he said they are making some perf improvements, so I decide to bump the version.

</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xa-prep-tasks\xa-prep-tasks.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,44 +142,41 @@ void ValidateApiCompat (string contractPath, bool validateAgainstReference)
File.Copy (implementationAssembly, Path.Combine (targetImplementationPathDirectory, assemblyToValidate), true);
}

using (var genApiProcess = new Process ()) {
for (int i = 0; i < 3; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

PR #4174 added support to re-execute Microsoft.DotNet.ApiCompat.exe if/when mono crashes. What are these more recent changes for? I don't see a rationale for these changes within the PR message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to created a new Process object to re-try instead of using the one already created. For some reason I was getting some odd behavior when re-running the process from the same Process object after the crash. When I was reading online, the recommendation was to dispose the object and use a new one.

using (var genApiProcess = new Process ()) {

genApiProcess.StartInfo.FileName = apiCompat;
genApiProcess.StartInfo.Arguments = $"\"{contractPathDirectory}\" -i \"{targetImplementationPathDirectory}\" ";
genApiProcess.StartInfo.FileName = apiCompat;
genApiProcess.StartInfo.Arguments = $"\"{contractPathDirectory}\" -i \"{targetImplementationPathDirectory}\" ";

// Verify if there is an exclusion list
var excludeAttributes = Path.Combine (ApiCompatibilityPath, $"api-compat-exclude-attributes.txt");
if (File.Exists (excludeAttributes)) {
genApiProcess.StartInfo.Arguments += $"--exclude-attributes {excludeAttributes} ";
}
// Verify if there is an exclusion list
var excludeAttributes = Path.Combine (ApiCompatibilityPath, $"api-compat-exclude-attributes.txt");
if (File.Exists (excludeAttributes)) {
genApiProcess.StartInfo.Arguments += $"--exclude-attributes {excludeAttributes} ";
}

genApiProcess.StartInfo.UseShellExecute = false;
genApiProcess.StartInfo.CreateNoWindow = true;
genApiProcess.StartInfo.RedirectStandardOutput = true;
genApiProcess.StartInfo.RedirectStandardError = true;
genApiProcess.EnableRaisingEvents = true;

var lines = new List<string> ();
var processHasCrashed = false;
void dataReceived (object sender, DataReceivedEventArgs args)
{
if (!string.IsNullOrWhiteSpace (args.Data)) {
lines.Add (args.Data.Trim ());

if (args.Data.IndexOf ("Native Crash Reporting") != -1) {
processHasCrashed = true;
genApiProcess.StartInfo.UseShellExecute = false;
genApiProcess.StartInfo.CreateNoWindow = true;
genApiProcess.StartInfo.RedirectStandardOutput = true;
genApiProcess.StartInfo.RedirectStandardError = true;
genApiProcess.EnableRaisingEvents = true;

var lines = new List<string> ();
var processHasCrashed = false;
void dataReceived (object sender, DataReceivedEventArgs args)
{
if (!string.IsNullOrWhiteSpace (args.Data)) {
lines.Add (args.Data.Trim ());

if (args.Data.IndexOf ("Native Crash Reporting") != -1) {
processHasCrashed = true;
}
}
}
}

genApiProcess.OutputDataReceived += dataReceived;
genApiProcess.ErrorDataReceived += dataReceived;

// Get api definition for previous Api
for (int i = 0; i < 3; i++) {
lines.Clear ();
processHasCrashed = false;
genApiProcess.OutputDataReceived += dataReceived;
genApiProcess.ErrorDataReceived += dataReceived;

// Get api definition for previous Api
compatApiCommand = $"CompatApi command: {genApiProcess.StartInfo.FileName} {genApiProcess.StartInfo.Arguments}";
Log.LogMessage (MessageImportance.High, compatApiCommand);

Expand All @@ -198,7 +195,8 @@ void dataReceived (object sender, DataReceivedEventArgs args)

if (processHasCrashed) {
if (i + 1 < 3) {
Log.LogWarning ($"Process has crashed.'{Environment.NewLine}Crash report:{Environment.NewLine}{String.Join (Environment.NewLine, lines)}");
Log.LogWarning ($"Process has crashed.");
Log.LogMessage (MessageImportance.High, String.Join (Environment.NewLine, lines));
Log.LogWarning ($"We will retry.");
continue;
} else {
Expand Down Expand Up @@ -328,13 +326,15 @@ Dictionary<string, HashSet<string>> LoadIssues (IEnumerable<string> content)
return issues;
}

void LogError(string errorMessage)
void LogError (string errorMessage)
{
var message = string.Empty;
if (!string.IsNullOrWhiteSpace (compatApiCommand)) {
Log.LogError ($"{compatApiCommand}{Environment.NewLine}{errorMessage}");
} else {
Log.LogError (errorMessage);
errorMessage = $"{compatApiCommand}{Environment.NewLine}{errorMessage}";
}

Log.LogMessage (MessageImportance.High, errorMessage);
Log.LogError (errorMessage);
}
}
}
8 changes: 6 additions & 2 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
Inputs="metadata;enumflags;map.csv;methodmap.csv;$(IntermediateOutputPath)mcw\api.xml"
Outputs="$(IntermediateOutputPath)mcw\Mono.Android.projitems">
<MakeDir Directories="$(IntermediateOutputPath)mcw" />
<PropertyGroup>
<_ApiVersions Condition="Exists('$(AndroidSdkDirectory)\platforms\android-$(AndroidApiLevel)\data\api-versions.xml')">"$(AndroidSdkDirectory)\platforms\android-$(AndroidApiLevel)\data\api-versions.xml"</_ApiVersions>
<_ApiVersions Condition="'$(_ApiVersions)'==''">"$(AndroidSdkDirectory)\platform-tools\api\api-versions.xml"</_ApiVersions>
</PropertyGroup>
<PropertyGroup>
<Generator>"$(XAInstallPrefix)xbuild\Xamarin\Android\generator.exe"</Generator>
<_GenFlags>--public --product-version=7</_GenFlags>
Expand All @@ -87,7 +91,7 @@
<_Fixup>--fixup=metadata</_Fixup>
<_Enums1>--preserve-enums --enumflags=enumflags --enumfields=map.csv --enummethods=methodmap.csv</_Enums1>
<_Enums2>--enummetadata=$(IntermediateOutputPath)mcw\enummetadata</_Enums2>
<_Versions>--apiversions="$(AndroidSdkDirectory)\platform-tools\api\api-versions.xml"</_Versions>
<_Versions>--apiversions=$(_ApiVersions)</_Versions>
<_Annotations>--annotations="$(AndroidSdkDirectory)\platform-tools\api\annotations.zip"</_Annotations>
<_Assembly>--assembly="Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"</_Assembly>
<_TypeMap>--type-map-report=$(IntermediateOutputPath)mcw\type-mapping.txt</_TypeMap>
Expand Down Expand Up @@ -173,7 +177,7 @@
Inputs="$(TargetPath);@(ApiCompatibilityFiles)"
Outputs="$(IntermediateOutputPath)CheckApiCompatibility.stamp">
<CheckApiCompatibility
ApiCompatPath="$(XamarinAndroidSourcePath)\packages\microsoft.dotnet.apicompat\5.0.0-beta.19606.1\tools\net472\"
ApiCompatPath="$(XamarinAndroidSourcePath)\packages\microsoft.dotnet.apicompat\5.0.0-beta.20078.1\tools\net472\"
ApiLevel="$(AndroidFrameworkVersion)"
LastStableApiLevel="$(AndroidLatestStableFrameworkVersion)"
TargetImplementationPath="$(OutputPath)"
Expand Down
Loading