Skip to content

Commit

Permalink
[Xamainr.Android.Build.Tasks] reduce task time (#2093)
Browse files Browse the repository at this point in the history
- simplify linq queries in ConvertResourceCases
  • Loading branch information
StephaneDelcroix authored and dellis1972 committed Aug 26, 2018
1 parent cce7d3d commit 508c1c1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Xamarin.Android.Build.Tasks/Tasks/ConvertResourcesCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,25 @@ void FixupResources (ITaskItem item, Dictionary<string, string> acwMap)
{
var resdir = item.ItemSpec;
// Find all the xml and axml files
var xmls = new[] { resdir }
.Concat (Directory.EnumerateDirectories (resdir, "*", SearchOption.AllDirectories)
.Except (Directory.EnumerateDirectories (resdir, "color*", SearchOption.TopDirectoryOnly))
.Except (Directory.EnumerateDirectories (resdir, "raw*", SearchOption.TopDirectoryOnly)))
.SelectMany (dir => Directory.EnumerateFiles (dir, "*.xml")
.Concat (Directory.EnumerateFiles (dir, "*.axml")));
var xmls = new List<string> ();
var colorDir = Path.Combine (resdir, "color");
var rawDir = Path.Combine (resdir, "raw");
foreach (var file in Directory.GetFiles (resdir, "*.*xml", SearchOption.AllDirectories)) {
if (file.StartsWith (colorDir, StringComparison.Ordinal) || file.StartsWith (rawDir, StringComparison.Ordinal))
continue;
var ext = Path.GetExtension (file);
if (ext != ".xml" && ext != ".axml")
continue;
xmls.Add (file);
}

var lastUpdate = DateTime.MinValue;
if (!string.IsNullOrEmpty (AndroidConversionFlagFile) && File.Exists (AndroidConversionFlagFile)) {
lastUpdate = File.GetLastWriteTimeUtc (AndroidConversionFlagFile);
}
Log.LogDebugMessage (" AndroidConversionFlagFile modified: {0}", lastUpdate);

var resourcedirectories = ResourceDirectories.Where (s => s != item).Select(s => s.ItemSpec).ToArray();
// Fix up each file
foreach (string file in xmls) {
var srcmodifiedDate = File.GetLastWriteTimeUtc (file);
Expand All @@ -78,7 +85,7 @@ void FixupResources (ITaskItem item, Dictionary<string, string> acwMap)
MonoAndroidHelper.SetWriteable (tmpdest);
try {
bool success = AndroidResource.UpdateXmlResource (resdir, tmpdest, acwMap,
ResourceDirectories.Where (s => s != item).Select(s => s.ItemSpec), (t, m) => {
resourcedirectories, (t, m) => {
string targetfile = file;
if (targetfile.StartsWith (resdir, StringComparison.InvariantCultureIgnoreCase)) {
targetfile = file.Substring (resdir.Length).TrimStart (Path.DirectorySeparatorChar);
Expand Down

0 comments on commit 508c1c1

Please sign in to comment.