Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] <GetImportedLibraries/> perf improvements #2930

Merged
merged 2 commits into from
Apr 8, 2019
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
44 changes: 25 additions & 19 deletions src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Mono.Cecil;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.Text.RegularExpressions;

namespace Xamarin.Android.Tasks
{
Expand Down Expand Up @@ -36,28 +32,34 @@ public class GetImportedLibraries : Task

public override bool Execute ()
{
Log.LogDebugMessage ("GetImportedLibraries Task");
Log.LogDebugMessage (" TargetDirectory: {0}", TargetDirectory);
if (!Directory.Exists (TargetDirectory)) {
Log.LogDebugMessage ("Target directory was not found");
return true;
}
// there could be ./AndroidManifest.xml and bin/AndroidManifest.xml, which will be the same. So, ignore "bin" ones.

var manifestDocuments = new List<ITaskItem> ();
foreach (var f in Directory.EnumerateFiles (TargetDirectory, "AndroidManifest.xml", SearchOption.AllDirectories)) {
var directory = Path.GetFileName (Path.GetDirectoryName (f));
if (IgnoredManifestDirectories.Contains (directory))
continue;
manifestDocuments.Add (new TaskItem (f));
var nativeLibraries = new List<ITaskItem> ();
var jarFiles = new List<ITaskItem> ();
foreach (var file in Directory.EnumerateFiles (TargetDirectory, "*", SearchOption.AllDirectories)) {
if (file.EndsWith (".so", StringComparison.OrdinalIgnoreCase)) {
if (MonoAndroidHelper.GetNativeLibraryAbi (file) != null)
nativeLibraries.Add (new TaskItem (file));
} else if (file.EndsWith (".jar", StringComparison.OrdinalIgnoreCase)) {
jarFiles.Add (new TaskItem (file));
} else if (file.EndsWith (".xml", StringComparison.OrdinalIgnoreCase)) {
if (Path.GetFileName (file) == "AndroidManifest.xml") {
// there could be ./AndroidManifest.xml and bin/AndroidManifest.xml, which will be the same. So, ignore "bin" ones.
var directory = Path.GetFileName (Path.GetDirectoryName (file));
if (IgnoredManifestDirectories.Contains (directory))
continue;
manifestDocuments.Add (new TaskItem (file));
}
}
}

ManifestDocuments = manifestDocuments.ToArray ();
NativeLibraries = Directory.GetFiles (TargetDirectory, "*.so", SearchOption.AllDirectories)
.Where (p => MonoAndroidHelper.GetNativeLibraryAbi (p) != null)
.Select (p => new TaskItem (p)).ToArray ();
Jars = Directory.GetFiles (TargetDirectory, "*.jar", SearchOption.AllDirectories).Select (p => new TaskItem (p)).ToArray ();
Log.LogDebugTaskItems (" NativeLibraries: ", NativeLibraries);
Log.LogDebugTaskItems (" Jars: ", Jars);
Log.LogDebugTaskItems (" ManifestDocuments: ", ManifestDocuments);
NativeLibraries = nativeLibraries.ToArray ();
Jars = jarFiles.ToArray ();

if (!string.IsNullOrEmpty (CacheFile)) {
var document = new XDocument (
Expand All @@ -70,6 +72,10 @@ public override bool Execute ()
document.SaveIfChanged (CacheFile);
}

Log.LogDebugTaskItems (" NativeLibraries: ", NativeLibraries);
Log.LogDebugTaskItems (" Jars: ", Jars);
Log.LogDebugTaskItems (" ManifestDocuments: ", ManifestDocuments);

return true;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1462,14 +1462,15 @@ because xbuild doesn't support framework reference assemblies.
</PropertyGroup>

<Target Name="_BuildLibraryImportsCache"
Inputs="$(MSBuildProjectFullPath);@(_ReferencePath);@(_ReferenceDependencyPaths);$(_AndroidBuildPropertiesCache);$(_AndroidLibraryProjectImportsCache)"
Outputs="$(_AndroidLibraryImportsCache).stamp">
<GetImportedLibraries TargetDirectory="$(_AndroidLibrayProjectIntermediatePath)"
Inputs="$(_AndroidLibraryProjectImportsCache)"
Outputs="$(_AndroidStampDirectory)_BuildLibraryImportsCache.stamp">
<GetImportedLibraries
TargetDirectory="$(_AndroidLibrayProjectIntermediatePath)"
CacheFile="$(_AndroidLibraryImportsCache)">
</GetImportedLibraries>
<Touch Files="$(_AndroidLibraryImportsCache).stamp" AlwaysCreate="True" />
<Touch Files="$(_AndroidStampDirectory)_BuildLibraryImportsCache.stamp" AlwaysCreate="True" />
<ItemGroup>
<FileWrites Include="$(_AndroidLibraryImportsCache).stamp" />
<FileWrites Include="$(_AndroidStampDirectory)_BuildLibraryImportsCache.stamp" />
</ItemGroup>
</Target>

Expand Down Expand Up @@ -3220,7 +3221,6 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="$(_AndroidBuildPropertiesCache)" />
<Delete Files="$(_AdbPropertiesCache)" />
<Delete Files="$(_AndroidLibraryImportsCache)" />
<Delete Files="$(_AndroidLibraryImportsCache).stamp" />
<Delete Files="$(_AndroidStaticResourcesFlag)" />
<Delete Files="$(_AndroidLibraryProjectImportsCache)" />
<Delete Files="$(_AndroidLibrayProjectAssemblyMapFile)" />
Expand Down