Skip to content

Commit

Permalink
Merge branch 'main' into blazor-hang
Browse files Browse the repository at this point in the history
* main:
  Bump to google/bundletool@f17ce94a (dotnet#8135)
  [Xamarin.Android.Build.Tasks] Handle IOException in Aapt2Daemon (dotnet#8130)
  [tests] don't set `/uses-sdk@android:targetSdkVersion=34` by default (dotnet#8138)
  • Loading branch information
grendello committed Jun 23, 2023
2 parents 944b73b + 6e375d5 commit 2c74196
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<XAPlatformToolsPackagePrefix Condition=" '$(HostOS)' == 'Darwin' "></XAPlatformToolsPackagePrefix>
<XAPlatformToolsVersion>34.0.1</XAPlatformToolsVersion>
<XAIncludeProprietaryBits Condition="'$(XAIncludeProprietaryBits)' == ''">False</XAIncludeProprietaryBits>
<XABundleToolVersion Condition="'$(XABundleToolVersion)' == ''">1.8.1</XABundleToolVersion>
<XABundleToolVersion Condition="'$(XABundleToolVersion)' == ''">1.15.1</XABundleToolVersion>
<XAPackagesDir Condition=" '$(XAPackagesDir)' == '' And '$(NUGET_PACKAGES)' != ''">$(NUGET_PACKAGES)</XAPackagesDir>
<XAPackagesDir Condition=" '$(XAPackagesDir)' == '' And '$(HostOS)' == 'Windows'">$(userprofile)\.nuget\packages</XAPackagesDir>
<XAPackagesDir Condition=" '$(XAPackagesDir)' == '' And '$(HostOS)' != 'Windows'">$(HOME)/.nuget/packages</XAPackagesDir>
Expand Down
8 changes: 0 additions & 8 deletions Documentation/release-notes/bundletool-1.8.1.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override bool Execute ()
DaemonMaxInstanceCount = maxInstances;
else
DaemonMaxInstanceCount = Math.Min (DaemonMaxInstanceCount, maxInstances);
daemon = Aapt2Daemon.GetInstance (BuildEngine4, GenerateFullPathToTool (),
daemon = Aapt2Daemon.GetInstance (BuildEngine4, LogDebugMessage, GenerateFullPathToTool (),
DaemonMaxInstanceCount, GetRequiredDaemonInstances (), registerInDomain: DaemonKeepInDomain);
return base.Execute ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,28 +650,6 @@ public void AarContentExtraction ([Values (false, true)] bool useAapt2)
}
}

[Test]
[Category ("DotNetIgnore")] // n/a in .NET 5+
public void CheckTargetFrameworkVersion ([Values (true, false)] bool isRelease)
{
var proj = new XamarinAndroidApplicationProject () {
IsRelease = isRelease,
TargetSdkVersion = null,
MinSdkVersion = null,
};
proj.SetProperty ("AndroidUseLatestPlatformSdk", "False");
using (var builder = CreateApkBuilder ()) {
builder.GetTargetFrameworkVersionRange (out var _, out string firstFrameworkVersion, out var _, out string lastFrameworkVersion, out string[] _);
proj.SetProperty ("TargetFrameworkVersion", firstFrameworkVersion);
if (!Directory.Exists (Path.Combine (TestEnvironment.MonoAndroidFrameworkDirectory, firstFrameworkVersion)))
Assert.Ignore ("This is a Pull Request Build. Ignoring test.");
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"Output Property: TargetFrameworkVersion={firstFrameworkVersion}"), $"TargetFrameworkVerson should be {firstFrameworkVersion}");
Assert.IsTrue (builder.Build (proj, parameters: new [] { $"TargetFrameworkVersion={lastFrameworkVersion}" }), "Build should have succeeded.");
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"Output Property: TargetFrameworkVersion={lastFrameworkVersion}"), $"TargetFrameworkVersion should be {lastFrameworkVersion}");
}
}

#pragma warning disable 414
public static object [] GeneratorValidateEventNameArgs = new object [] {
new object [] { false, true, string.Empty, string.Empty },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,8 @@ module Xamarin.Android.Tests
public void DesignTimeBuildHasAndroidDefines ()
{
var proj = new XamarinAndroidApplicationProject ();
var didParse = int.TryParse (proj.TargetSdkVersion, out int apiLevel);
Assert.IsTrue (didParse, $"Unable to parse {proj.TargetSdkVersion} as an int.");
var androidDefines = new List<string> ();
for (int i = 1; i <= apiLevel; ++i) {
for (int i = 1; i <= XABuildConfig.AndroidDefaultTargetDotnetApiLevel; ++i) {
androidDefines.Add ($"!__ANDROID_{i}__");
}
proj.Sources.Add (new BuildItem ("Compile", "IsAndroidDefined.cs") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,16 @@ public void ModifyManifest ([Values (true, false)] bool isRelease)
<_Permissions Include=""&lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt;"" />
</ItemGroup>
<Target Name=""_Foo"">
<XmlPeek Query=""/manifest/*"" XmlInputPath=""$(IntermediateOutputPath)android\AndroidManifest.xml"">
<Output TaskParameter=""Result"" ItemName=""_XmlNodes"" />
</XmlPeek>
<PropertyGroup>
<_ExistingXml>@(_XmlNodes, ' ')</_ExistingXml>
<_NewXml>@(_Permissions, ' ')</_NewXml>
</PropertyGroup>
<XmlPoke
XmlInputPath=""$(IntermediateOutputPath)android\AndroidManifest.xml""
Value=""@(_Permissions)""
Value=""$(_ExistingXml)$(_NewXml)""
Query=""/manifest""
Namespaces=""$(Namespace)""
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug"
MinSdkVersion = "19";
}
AndroidManifest = default_android_manifest;
if (Builder.UseDotNet) {
TargetSdkVersion = XABuildConfig.AndroidDefaultTargetDotnetApiLevel.ToString ();
} else {
if (!Builder.UseDotNet) {
TargetSdkVersion = AndroidSdkResolver.GetMaxInstalledPlatform ().ToString ();
}
LayoutMain = default_layout_main;
Expand Down Expand Up @@ -201,18 +199,22 @@ public void SetDefaultTargetDevice ()

public virtual string ProcessManifestTemplate ()
{
var uses_sdk = new StringBuilder ("<uses-sdk ");
var uses_sdk = new StringBuilder ();
if (!string.IsNullOrEmpty (MinSdkVersion)) {
uses_sdk.Append ("<uses-sdk ");
uses_sdk.Append ("android:minSdkVersion=\"");
uses_sdk.Append (MinSdkVersion);
uses_sdk.Append ("\" ");
}
if (!string.IsNullOrEmpty (TargetSdkVersion)) {
if (uses_sdk.Length == 0)
uses_sdk.Append ("<uses-sdk ");
uses_sdk.Append ("android:targetSdkVersion=\"");
uses_sdk.Append (TargetSdkVersion);
uses_sdk.Append ("\" ");
}
uses_sdk.Append ("/>");
if (uses_sdk.Length > 0)
uses_sdk.Append ("/>");

return AndroidManifest
.Replace ("${PROJECT_NAME}", ProjectName)
Expand Down
24 changes: 18 additions & 6 deletions src/Xamarin.Android.Build.Tasks/Utilities/Aapt2Daemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ internal class Aapt2Daemon : IDisposable

internal static object RegisterTaskObjectKey => TypeFullName;

public static Aapt2Daemon GetInstance (IBuildEngine4 engine, string aapt2, int numberOfInstances, int initalNumberOfDaemons, bool registerInDomain = false)
public static Aapt2Daemon GetInstance (IBuildEngine4 engine, Action<string> log, string aapt2, int numberOfInstances, int initalNumberOfDaemons, bool registerInDomain = false)
{
var area = registerInDomain ? RegisteredTaskObjectLifetime.AppDomain : RegisteredTaskObjectLifetime.Build;
var daemon = engine.GetRegisteredTaskObjectAssemblyLocal<Aapt2Daemon> (RegisterTaskObjectKey, area);
if (daemon == null)
{
daemon = new Aapt2Daemon (aapt2, numberOfInstances, initalNumberOfDaemons);
daemon = new Aapt2Daemon (aapt2, numberOfInstances, initalNumberOfDaemons, log);
engine.RegisterTaskObjectAssemblyLocal (RegisterTaskObjectKey, daemon, area, allowEarlyCollection: false);
}
return daemon;
Expand Down Expand Up @@ -66,6 +66,7 @@ public void Complete (bool result)
long jobsRunning = 0;
long jobId = 0;
int maxInstances = 0;
Action<string> logger = null;

public CancellationToken Token => tcs.Token;

Expand All @@ -86,10 +87,11 @@ public bool JobsRunning

public int CurrentInstances => daemons.Count;

public Aapt2Daemon (string aapt2, int maxNumberOfInstances, int initalNumberOfDaemons)
public Aapt2Daemon (string aapt2, int maxNumberOfInstances, int initalNumberOfDaemons, Action<string> log)
{
Aapt2 = aapt2;
maxInstances = maxNumberOfInstances;
logger = log;
for (int i = 0; i < initalNumberOfDaemons; i++) {
SpawnAapt2Daemon ();
}
Expand Down Expand Up @@ -271,9 +273,19 @@ private void Aapt2DaemonStart ()
{
// Ignore this error. It occurs when the Task is cancelled.
}
aapt2.StandardInput.WriteLine ("quit");
aapt2.StandardInput.WriteLine ();
aapt2.WaitForExit ((int)TimeSpan.FromSeconds (5).TotalMilliseconds);
try {
aapt2.StandardInput.WriteLine ("quit");
aapt2.StandardInput.WriteLine ();
aapt2.WaitForExit ((int)TimeSpan.FromSeconds (5).TotalMilliseconds);
} catch (IOException) {
// Ignore this error. It occurs when the Build it cancelled.
try {
logger?.Invoke ($"{nameof (Aapt2Daemon)}: Ignoring IOException. Build was cancelled.");
} catch {
// The Logger might not exist if the daemon exits after the logger has been
// collected.
}
}
}

bool IsAapt2Warning (string singleLine)
Expand Down
1 change: 0 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch ([Values (f
proj = new XamarinAndroidApplicationProject () {
IsRelease = isRelease,
SupportedOSPlatformVersion = "23",
TargetSdkVersion = null,
};
if (isRelease || !CommercialBuildAvailable) {
proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64");
Expand Down

0 comments on commit 2c74196

Please sign in to comment.