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 @@ -74,10 +74,10 @@ void FixupResources (ITaskItem item, Dictionary<string, string> acwMap)
}
Log.LogDebugMessage (" Processing: {0} {1} > {2}", file, srcmodifiedDate, lastUpdate);
var tmpdest = Path.GetTempFileName ();
MonoAndroidHelper.CopyIfChanged (file, tmpdest);
File.Copy (file, tmpdest, overwrite: true);
MonoAndroidHelper.SetWriteable (tmpdest);
try {
AndroidResource.UpdateXmlResource (resdir, tmpdest, acwMap,
bool success = AndroidResource.UpdateXmlResource (resdir, tmpdest, acwMap,
ResourceDirectories.Where (s => s != item).Select(s => s.ItemSpec), (t, m) => {
string targetfile = file;
if (targetfile.StartsWith (resdir, StringComparison.InvariantCultureIgnoreCase)) {
Expand All @@ -98,6 +98,10 @@ void FixupResources (ITaskItem item, Dictionary<string, string> acwMap)
break;
}
});
if (!success) {
//If we failed to write the file, a warning is logged, we should skip to the next file
continue;
}

// We strip away an eventual UTF-8 BOM from the XML file.
// This is a requirement for the Android designer because the desktop Java renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,50 @@ public void BuildBasicApplicationReleaseFSharp ()
}
}

[Test]
public void BuildInParallel ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity");

var packages = proj.Packages;
packages.Add (KnownPackages.XamarinForms_3_0_0_561731);
packages.Add (KnownPackages.Android_Arch_Core_Common_26_1_0);
packages.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0);
packages.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0);
packages.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
packages.Add (KnownPackages.SupportCompat_27_0_2_1);
packages.Add (KnownPackages.SupportCoreUI_27_0_2_1);
packages.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
packages.Add (KnownPackages.SupportDesign_27_0_2_1);
packages.Add (KnownPackages.SupportFragment_27_0_2_1);
packages.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
packages.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
packages.Add (KnownPackages.SupportV7CardView_27_0_2_1);
packages.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
packages.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1);

using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
//We don't want these things stepping on each other
b.BuildLogFile = null;
b.Save (proj, saveProject: true);
proj.NuGetRestore (Path.Combine (Root, b.ProjectDirectory), b.PackagesDirectory);

Parallel.For (0, 5, i => {
try {
//NOTE: things are going to break here
b.Build (proj);
} catch (Exception exc) {
TestContext.WriteLine ("Expected error in {0}: {1}", nameof (BuildInParallel), exc);
}
});

//The key here, is a build afterward should work
b.BuildLogFile = "after.log";
Assert.IsTrue (b.Build (proj), "The build after a parallel failed build should succeed!");
}
}

[Test]
public void CheckKeystoreIsCreated ()
{
Expand Down
11 changes: 5 additions & 6 deletions src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Monodroid {
static class AndroidResource {

public static void UpdateXmlResource (string res, string filename, Dictionary<string, string> acwMap, IEnumerable<string> additionalDirectories = null, Action<TraceLevel, string> logMessage = null)
public static bool UpdateXmlResource (string res, string filename, Dictionary<string, string> acwMap, IEnumerable<string> additionalDirectories = null, Action<TraceLevel, string> logMessage = null)
{
// use a temporary file so we only update the real file if things actually changed
string tmpfile = filename + ".bk";
Expand All @@ -24,14 +24,13 @@ public static void UpdateXmlResource (string res, string filename, Dictionary<st
xw.WriteNode (doc.CreateNavigator (), false);
Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged (tmpfile, filename);
File.Delete (tmpfile);
}
catch (Exception e) {
return true;
} catch (Exception e) {
if (File.Exists (tmpfile)) {
File.Delete (tmpfile);
}
if (logMessage != null)
logMessage (TraceLevel.Warning, $"AndroidResgen: Warning while updating Resource XML '{filename}': {e.Message}");
return;
logMessage?.Invoke (TraceLevel.Warning, $"AndroidResgen: Warning while updating Resource XML '{filename}': {e.Message}");
return false;
}
}

Expand Down