Skip to content

Commit afc3ab9

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] F# tests use NuGet packages (#740)
1 parent 333dbbc commit afc3ab9

File tree

11 files changed

+90
-29
lines changed

11 files changed

+90
-29
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void CheckResourceDesignerIsUpdatedWhenReadOnly (bool isRelease, ProjectL
383383
};
384384
using (var b = CreateApkBuilder ("temp/CheckResourceDesignerIsUpdatedWhenReadOnly")) {
385385
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
386-
var designerPath = Path.Combine (Root, b.ProjectDirectory, "Resources", "Resource.designer" + language.DefaultExtension);
386+
var designerPath = Path.Combine (Root, b.ProjectDirectory, "Resources", "Resource.designer" + language.DefaultDesignerExtension);
387387
var attr = File.GetAttributes (designerPath);
388388
File.SetAttributes (designerPath, FileAttributes.ReadOnly);
389389
Assert.IsTrue ((File.GetAttributes (designerPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly,
@@ -400,25 +400,28 @@ public void CheckResourceDesignerIsUpdatedWhenReadOnly (bool isRelease, ProjectL
400400
[TestCaseSource("ReleaseLanguage")]
401401
public void CheckOldResourceDesignerIsNotUsed (bool isRelease, ProjectLanguage language)
402402
{
403+
if (language == XamarinAndroidProjectLanguage.FSharp)
404+
Assert.Ignore ("Skipping CheckOldResourceDesignerIsNotUsed for FSharp until Xamarin.Android.FSharp.ResourceProvider supports it.");
403405
var proj = new XamarinAndroidApplicationProject () {
404406
Language = language,
405407
IsRelease = isRelease,
406408
};
407409
proj.SetProperty ("AndroidUseIntermediateDesignerFile", "True");
408410
using (var b = CreateApkBuilder ("temp/CheckOldResourceDesignerIsNotUsed")) {
409-
var designer = proj.Sources.First (x => x.Include() == "Resources\\Resource.designer" + proj.Language.DefaultExtension);
410-
designer.Deleted = true;
411+
var designer = Path.Combine ("Resources", "Resource.designer" + proj.Language.DefaultDesignerExtension);
412+
if (File.Exists (designer))
413+
File.Delete (Path.Combine (Root, b.ProjectDirectory, designer));
411414
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
412415
Assert.IsFalse (File.Exists (Path.Combine (b.ProjectDirectory, "Resources",
413-
"Resource.designer" + proj.Language.DefaultExtension)),
414-
"{0} should not exists", designer.Include ());
416+
"Resource.designer" + proj.Language.DefaultDesignerExtension)),
417+
"{0} should not exists", designer);
415418
var outputFile = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath,
416-
"Resource.Designer" + proj.Language.DefaultExtension);
419+
"Resource.Designer" + proj.Language.DefaultDesignerExtension);
417420
Assert.IsTrue (File.Exists (outputFile), "Resource.Designer{1} should have been created in {0}",
418-
proj.IntermediateOutputPath, proj.Language.DefaultExtension);
421+
proj.IntermediateOutputPath, proj.Language.DefaultDesignerExtension);
419422
Assert.IsTrue (b.Clean (proj), "Clean should have succeeded.");
420423
Assert.IsFalse (File.Exists (outputFile), "Resource.Designer{1} should have been cleaned in {0}",
421-
proj.IntermediateOutputPath, proj.Language.DefaultExtension);
424+
proj.IntermediateOutputPath, proj.Language.DefaultDesignerExtension);
422425
}
423426
}
424427

@@ -427,26 +430,30 @@ public void CheckOldResourceDesignerIsNotUsed (bool isRelease, ProjectLanguage l
427430
[TestCaseSource("ReleaseLanguage")]
428431
public void CheckOldResourceDesignerWithWrongCasingIsRemoved (bool isRelease, ProjectLanguage language)
429432
{
433+
if (language == XamarinAndroidProjectLanguage.FSharp)
434+
Assert.Ignore ("Skipping CheckOldResourceDesignerIsNotUsed for FSharp until Xamarin.Android.FSharp.ResourceProvider supports it.");
430435
var proj = new XamarinAndroidApplicationProject () {
431436
Language = language,
432437
IsRelease = isRelease,
433438
};
434439
proj.SetProperty ("AndroidUseIntermediateDesignerFile", "True");
435440
proj.SetProperty ("AndroidResgenFile", "Resources\\Resource.Designer" + proj.Language.DefaultExtension);
436441
using (var b = CreateApkBuilder ("temp/CheckOldResourceDesignerWithWrongCasingIsRemoved")) {
437-
var designer = proj.Sources.First (x => x.Include() == "Resources\\Resource.designer" + proj.Language.DefaultExtension);
442+
var designer = proj.Sources.FirstOrDefault (x => x.Include() == "Resources\\Resource.designer" + proj.Language.DefaultDesignerExtension);
443+
designer = designer ?? proj.OtherBuildItems.FirstOrDefault (x => x.Include () == "Resources\\Resource.designer" + proj.Language.DefaultDesignerExtension);
444+
Assert.IsNotNull (designer, $"Failed to retrieve the Resource.designer.{proj.Language.DefaultDesignerExtension}");
438445
designer.Deleted = true;
439446
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
440447
Assert.IsFalse (File.Exists (Path.Combine (b.ProjectDirectory, "Resources",
441-
"Resource.designer" + proj.Language.DefaultExtension)),
448+
"Resource.designer" + proj.Language.DefaultDesignerExtension)),
442449
"{0} should not exists", designer.Include ());
443450
var outputFile = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath,
444-
"Resource.Designer" + proj.Language.DefaultExtension);
451+
"Resource.Designer" + proj.Language.DefaultDesignerExtension);
445452
Assert.IsTrue (File.Exists (outputFile), "Resource.Designer{1} should have been created in {0}",
446-
proj.IntermediateOutputPath, proj.Language.DefaultExtension);
453+
proj.IntermediateOutputPath, proj.Language.DefaultDesignerExtension);
447454
Assert.IsTrue (b.Clean (proj), "Clean should have succeeded.");
448455
Assert.IsFalse (File.Exists (outputFile), "Resource.Designer{1} should have been cleaned in {0}",
449-
proj.IntermediateOutputPath, proj.Language.DefaultExtension);
456+
proj.IntermediateOutputPath, proj.Language.DefaultDesignerExtension);
450457
}
451458
}
452459

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public void CheckJavaError ()
735735
using (var b = CreateApkBuilder ("temp/CheckJavaError")) {
736736
b.ThrowOnBuildFailure = false;
737737
Assert.IsFalse (b.Build (proj), "Build should have failed.");
738-
if (b.RunXBuild) {
738+
if (b.IsUnix) {
739739
var text = "TestMe.java(1,8): javacerror : error: class, interface, or enum expected";
740740
if (b.RunningMSBuild)
741741
text = "TestMe.java(1,8): javac error : error: class, interface, or enum expected";

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ public static class KnownPackages
238238
},
239239
}
240240
};
241+
public static Package FSharp_Core_Latest = new Package {
242+
Id = "FSharp.Core",
243+
Version = "4.0.0.1",
244+
TargetFramework = "monoandroid71",
245+
References = {
246+
new BuildItem.Reference ("mscorlib"),
247+
new BuildItem.Reference ("FSharp.Core") {
248+
MetadataValues = "HintPath=..\\packages\\FSharp.Core.4.0.0.1\\lib\\portable-net45+monoandroid10+monotouch10+xamarinios10\\FSharp.Core.dll"
249+
},
250+
}
251+
};
252+
public static Package Xamarin_Android_FSharp_ResourceProvider_Runtime = new Package {
253+
Id = "Xamarin.Android.FSharp.ResourceProvider",
254+
Version = "1.0.0.13",
255+
TargetFramework = "monoandroid71",
256+
References = {
257+
new BuildItem.Reference ("FSharp.Core") {
258+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.FSharp.ResourceProvider.1.0.0.13\\lib\\Xamarin.Android.FSharp.ResourceProvider.Runtime.dll"
259+
},
260+
}
261+
};
241262
}
242263
}
243264

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug"
3939
SetProperty ("AndroidApplication", "True");
4040

4141
SetProperty ("AndroidResgenClass", "Resource");
42-
SetProperty ("AndroidResgenFile", () => "Resources\\Resource.designer" + Language.DefaultExtension);
42+
SetProperty ("AndroidResgenFile", () => "Resources\\Resource.designer" + Language.DefaultDesignerExtension);
4343
SetProperty ("AndroidManifest", "Properties\\AndroidManifest.xml");
4444
SetProperty (DebugProperties, "AndroidLinkMode", "None");
4545
SetProperty (ReleaseProperties, "AndroidLinkMode", "SdkOnly");
46+
SetProperty (DebugProperties, "EmbedAssembliesIntoApk", "False");
47+
SetProperty (ReleaseProperties, "EmbedAssembliesIntoApk", "True");
4648

4749
AndroidManifest = default_android_manifest;
4850
LayoutMain = default_layout_main;

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidCommonProject.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public abstract class XamarinAndroidCommonProject : XamarinAndroidProject
1717
public static readonly byte[] icon_binary_xxhdpi;
1818
public static readonly byte[] icon_binary_xxxhdpi;
1919

20+
BuildItem.Source resourceDesigner;
21+
2022
static byte[] ScaleIcon (Image image, int width, int height)
2123
{
2224
float scale = Math.Min (width / image.Width, height / image.Height);
@@ -56,8 +58,8 @@ protected XamarinAndroidCommonProject (string debugConfigurationName = "Debug",
5658
{
5759
AndroidResources = new List<BuildItem> ();
5860
ItemGroupList.Add (AndroidResources);
59-
60-
Sources.Add (new BuildItem.Source (() => "Resources\\Resource.designer" + Language.DefaultExtension) { TextContent = () => string.Empty });
61+
resourceDesigner = new BuildItem.Source (() => "Resources\\Resource.designer" + Language.DefaultDesignerExtension) { TextContent = () => string.Empty };
62+
Sources.Add (resourceDesigner);
6163
AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable-mdpi\\Icon.png") { BinaryContent = () => icon_binary_mdpi });
6264
AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable-hdpi\\Icon.png") { BinaryContent = () => icon_binary_hdpi });
6365
AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable-xhdpi\\Icon.png") { BinaryContent = () => icon_binary_xhdpi });
@@ -78,5 +80,21 @@ public override ProjectRootElement Construct ()
7880
root.AddImport (import.Project ());
7981
return root;
8082
}
83+
84+
public override ProjectLanguage Language {
85+
get {
86+
return base.Language;
87+
}
88+
set {
89+
base.Language = value;
90+
if (value == XamarinAndroidProjectLanguage.FSharp) {
91+
// add the stuff needed for FSharp
92+
Packages.Add (KnownPackages.FSharp_Core_Latest);
93+
Packages.Add (KnownPackages.Xamarin_Android_FSharp_ResourceProvider_Runtime);
94+
Sources.Remove (resourceDesigner);
95+
OtherBuildItems.Add (new BuildItem.NoActionResource (() => "Resources\\Resource.designer" + Language.DefaultDesignerExtension) { TextContent = () => string.Empty });
96+
}
97+
}
98+
}
8199
}
82100
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidProjectLanguage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public override string ProjectTypeGuid {
3333
public override string DefaultExtension {
3434
get { return ".fs"; }
3535
}
36+
public override string DefaultDesignerExtension {
37+
get { return ".cs"; }
38+
}
3639
public override string DefaultProjectExtension {
3740
get { return ".fsproj"; }
3841
}
@@ -55,6 +58,9 @@ public override string ProjectTypeGuid {
5558
public override string DefaultExtension {
5659
get { return ".cs"; }
5760
}
61+
public override string DefaultDesignerExtension {
62+
get { return ".cs"; }
63+
}
5864
public override string DefaultProjectExtension {
5965
get { return ".csproj"; }
6066
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/BuildOutput.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public bool IsTargetSkipped (string target)
4949
if (!Builder.LastBuildOutput.Contains (target))
5050
throw new ArgumentException (string.Format ("Target '{0}' is not even in the build output.", target));
5151
return Builder.LastBuildOutput.Contains (string.Format ("Target {0} skipped due to ", target))
52-
|| Builder.LastBuildOutput.Contains (string.Format ("Skipping target \"{0}\" because its outputs are up-to-date", target));
52+
|| Builder.LastBuildOutput.Contains (string.Format ("Skipping target \"{0}\" because its outputs are up-to-date", target))
53+
|| Builder.LastBuildOutput.Contains ($"Skipping target \"{target}\" because all output files are up-to-date");
5354
}
5455

5556
public bool IsApkInstalled {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/Builder.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,36 @@ public class Builder : IDisposable
1414
const string msbuildapp = "msbuild";
1515
string msbuildExe;
1616

17-
public bool RunXBuild { get; set; }
17+
public bool IsUnix { get; set; }
1818
public bool RunningMSBuild { get; set; }
1919
public LoggerVerbosity Verbosity { get; set; }
2020
public string LastBuildOutput { get; set; }
2121
public TimeSpan LastBuildTime { get; protected set; }
2222
public string BuildLogFile { get; set; }
2323
public bool ThrowOnBuildFailure { get; set; }
2424

25-
string GetXbuildPath ()
25+
string GetUnixBuildExe ()
2626
{
27+
RunningMSBuild = false;
2728
string path = Path.Combine (fixed_osx_xbuild_path, xbuildapp);
2829
if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("USE_MSBUILD"))) {
2930
path = Path.Combine (fixed_osx_xbuild_path, msbuildapp);
3031
RunningMSBuild = true;
3132
}
32-
return File.Exists (path) ? path : xbuildapp;
33+
return File.Exists (path) ? path : msbuildapp;
3334
}
3435

3536
public string MSBuildExe {
3637
get {
37-
return RunXBuild
38-
? File.Exists (fixed_osx_xbuild_path) ? fixed_osx_xbuild_path : "xbuild"
38+
return IsUnix
39+
? GetUnixBuildExe ()
3940
: msbuildExe;
4041
}
4142
}
4243

4344
public string FrameworkLibDirectory {
4445
get {
45-
if (RunXBuild) {
46+
if (IsUnix) {
4647
var outdir = Environment.GetEnvironmentVariable ("XA_BUILD_OUTPUT_PATH");
4748
if (String.IsNullOrEmpty(outdir))
4849
outdir = Path.GetFullPath (Path.Combine (Root, "..", "..", "..", "..", "..", "..", "..", "out"));
@@ -69,7 +70,7 @@ public string Root {
6970

7071
public Builder ()
7172
{
72-
RunXBuild = Environment.OSVersion.Platform != PlatformID.Win32NT;
73+
IsUnix = Environment.OSVersion.Platform != PlatformID.Win32NT;
7374
BuildLogFile = "build.log";
7475
// Allow the override of the location of MSBuild and try a couple of backup paths for
7576
// MSBuild 14.0 and 4.0
@@ -124,7 +125,7 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
124125
ndkPath = Path.GetFullPath (Path.Combine (androidSdkToolPath, "ndk"));
125126
StringBuilder args = new StringBuilder ();
126127
var psi = new ProcessStartInfo (MSBuildExe);
127-
if (RunXBuild) {
128+
if (IsUnix) {
128129
if (Directory.Exists (sdkPath)) {
129130
args.AppendFormat ("/p:AndroidSdkDirectory=\"{0}\" ", sdkPath);
130131
}
@@ -140,9 +141,12 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
140141
psi.EnvironmentVariables ["MSBuildExtensionsPath"] = targetsdir;
141142
}
142143
if (Directory.Exists (outdir)) {
144+
var frameworksPath = Path.Combine (outdir, "lib", "xamarin.android", "xbuild-frameworks");
143145
psi.EnvironmentVariables ["MONO_ANDROID_PATH"] = outdir;
144146
psi.EnvironmentVariables ["XBUILD_FRAMEWORK_FOLDERS_PATH"] = Path.Combine (outdir, "lib", "xbuild-frameworks");
145147
args.AppendFormat ("/p:MonoDroidInstallDirectory=\"{0}\" ", outdir);
148+
if (RunningMSBuild)
149+
args.AppendFormat ($"/p:TargetFrameworkRootPath={frameworksPath} ");
146150
}
147151
args.AppendFormat ("/t:{0} {1} /p:UseHostCompilerIfAvailable=false /p:BuildingInsideVisualStudio=true", target, QuoteFileName (Path.Combine (Root, projectOrSolution)));
148152
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public struct RuntimeInfo
119119
public RuntimeInfo [] GetSupportedRuntimes ()
120120
{
121121
var runtimeInfo = new List<RuntimeInfo> ();
122-
string outdir = FrameworkLibDirectory;
123-
string path = Path.Combine (outdir, RunXBuild ? Path.Combine ("xbuild", "Xamarin", "Android", "lib") : "");
122+
var outdir = FrameworkLibDirectory;
123+
var path = Path.Combine (outdir, IsUnix ? Path.Combine ("xbuild", "Xamarin", "Android", "lib") : "");
124124
foreach (var file in Directory.EnumerateFiles (path, "libmono-android.*.*.so", SearchOption.AllDirectories)) {
125125
string fullFilePath = Path.GetFullPath (file);
126126
DirectoryInfo parentDir = Directory.GetParent (fullFilePath);

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectLanguage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public abstract class ProjectLanguage
1111
{
1212
public abstract string DefaultAssemblyInfo { get; }
1313
public abstract string DefaultExtension { get; }
14+
public abstract string DefaultDesignerExtension { get; }
1415
public abstract string DefaultProjectExtension { get; }
1516
public abstract string ProjectTypeGuid { get; }
1617
}

0 commit comments

Comments
 (0)