Skip to content

Commit 9bb1589

Browse files
This should fix the MSBuild tests
1 parent eaebb88 commit 9bb1589

File tree

7 files changed

+80
-46
lines changed

7 files changed

+80
-46
lines changed

src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/Linker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static Pipeline CreatePipeline (LinkerOptions options)
6262

6363
if (options.LinkNone) {
6464
pipeline.AppendStep (new FixAbstractMethodsStep ());
65-
pipeline.AppendStep (new OutputStep ());
65+
pipeline.AppendStep (new OutputStepWithTimestamps ());
6666
return pipeline;
6767
}
6868

@@ -117,7 +117,7 @@ static Pipeline CreatePipeline (LinkerOptions options)
117117
pipeline.AppendStep (new StripEmbeddedLibraries ());
118118
// end monodroid specific
119119
pipeline.AppendStep (new RegenerateGuidStep ());
120-
pipeline.AppendStep (new OutputStep ());
120+
pipeline.AppendStep (new OutputStepWithTimestamps ());
121121

122122
return pipeline;
123123
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.IO;
2+
using Mono.Cecil;
3+
using Mono.Cecil.Cil;
4+
using Mono.Linker.Steps;
5+
using Xamarin.Android.Tools;
6+
7+
namespace MonoDroid.Tuner
8+
{
9+
/// <summary>
10+
/// A subclass of OutputStep that overrides CopyAssembly and timestamps files properly with Files.CopyIfChanged
11+
/// * original source from: https://github.com/mono/linker/blob/aa65acca5e41fbc1f8f597799381b853049704ff/src/linker/Linker.Steps/OutputStep.cs#L198-L231
12+
/// </summary>
13+
class OutputStepWithTimestamps : OutputStep
14+
{
15+
static FileInfo GetOriginalAssemblyFileInfo (AssemblyDefinition assembly)
16+
{
17+
return new FileInfo (assembly.MainModule.FileName);
18+
}
19+
20+
protected override void CopyAssembly (AssemblyDefinition assembly, string directory)
21+
{
22+
// Special case. When an assembly has embedded pdbs, link symbols is not enabled, and the assembly's action is copy,
23+
// we want to match the behavior of assemblies with the other symbol types and end up with an assembly that does not have symbols.
24+
// In order to do that, we can't simply copy files. We need to write the assembly without symbols
25+
if (assembly.MainModule.HasSymbols && !Context.LinkSymbols && assembly.MainModule.SymbolReader is EmbeddedPortablePdbReader) {
26+
WriteAssembly (assembly, directory, new WriterParameters ());
27+
return;
28+
}
29+
30+
FileInfo fi = GetOriginalAssemblyFileInfo (assembly);
31+
string target = Path.GetFullPath (Path.Combine (directory, fi.Name));
32+
string source = fi.FullName;
33+
if (source == target)
34+
return;
35+
36+
Files.CopyIfChanged (source, target);
37+
38+
if (!Context.LinkSymbols)
39+
return;
40+
41+
var mdb = source + ".mdb";
42+
if (File.Exists (mdb))
43+
Files.CopyIfChanged (mdb, target + ".mdb");
44+
45+
var pdb = Path.ChangeExtension (source, "pdb");
46+
if (File.Exists (pdb))
47+
Files.CopyIfChanged (pdb, Path.ChangeExtension (target, "pdb"));
48+
}
49+
}
50+
}

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

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,9 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease)
486486
// Xamarin.Android unless fastdev is enabled.
487487
foreach (var file in new [] { "typemap.mj", "typemap.jm" }) {
488488
var info = new FileInfo (Path.Combine (intermediate, "android", file));
489-
if (!info.Exists) {
490-
Assert.Ignore ($"{info.Name} does not exist, timestamp check skipped");
491-
continue;
489+
if (info.Exists) {
490+
Assert.IsTrue (info.LastWriteTimeUtc > start, $"`{file}` is older than `{start}`, with a timestamp of `{info.LastWriteTimeUtc}`!");
492491
}
493-
Assert.IsTrue (info.LastWriteTimeUtc > start, $"`{file}` is older than `{start}`, with a timestamp of `{info.LastWriteTimeUtc}`!");
494492
}
495493

496494
//One last build with no changes
@@ -1164,12 +1162,6 @@ public void BuildBasicApplicationCheckMdbRepeatBuild ()
11641162
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.pdb")),
11651163
"UnnamedProject.dll.mdb must be copied to the Intermediate directory");
11661164
Assert.IsTrue (b.Build (proj), "second build failed");
1167-
Assert.IsTrue (
1168-
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
1169-
"the _CopyMdbFiles target should be skipped");
1170-
Assert.IsTrue (
1171-
b.Output.IsTargetSkipped ("_CopyPdbFiles"),
1172-
"the _CopyPdbFiles target should be skipped");
11731165
Assert.IsTrue (
11741166
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.dll.mdb")) ||
11751167
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.pdb")),
@@ -1229,39 +1221,39 @@ public Class2 ()
12291221
Assert.IsTrue (libb.Build (lib), "Library1 Build should have succeeded.");
12301222
using (var b = CreateApkBuilder (Path.Combine (path, "App1"))) {
12311223
Assert.IsTrue (b.Build (proj), "App1 Build should have succeeded.");
1232-
var assetsPdb = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "Library1.pdb");
1233-
var linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "Library1.pdb");
1234-
var linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "Library1.pdb");
1224+
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
1225+
var outputPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
1226+
var assetsPdb = Path.Combine (intermediate, "android", "assets", "Library1.pdb");
1227+
var linkDst = Path.Combine (intermediate, "linkdst", "Library1.pdb");
1228+
var binSrc = Path.Combine (outputPath, "Library1.pdb");
12351229
Assert.IsTrue (
12361230
File.Exists (assetsPdb),
12371231
"Library1.pdb must be copied to Intermediate directory");
12381232
Assert.IsFalse (
12391233
File.Exists (linkDst),
12401234
"Library1.pdb should not be copied to linkdst directory because it has no Abstrsact methods to fix up.");
12411235
Assert.IsTrue (
1242-
File.Exists (linkSrc),
1243-
"Library1.pdb must be copied to linksrc directory");
1244-
var outputPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
1236+
File.Exists (binSrc),
1237+
"Library1.pdb must be copied to bin directory");
12451238
using (var apk = ZipHelper.OpenZip (Path.Combine (outputPath, proj.PackageName + "-Signed.apk"))) {
12461239
var data = ZipHelper.ReadFileFromZip (apk, "assemblies/Library1.pdb");
12471240
if (data == null)
12481241
data = File.ReadAllBytes (assetsPdb);
1249-
var filedata = File.ReadAllBytes (linkSrc);
1250-
Assert.AreEqual (filedata.Length, data.Length, "Library1.pdb in the apk should match {0}", linkSrc);
1242+
var filedata = File.ReadAllBytes (binSrc);
1243+
Assert.AreEqual (filedata.Length, data.Length, "Library1.pdb in the apk should match {0}", binSrc);
12511244
}
1252-
linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "App1.pdb");
1253-
linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "App1.pdb");
1245+
linkDst = Path.Combine (intermediate, "linkdst", "App1.pdb");
1246+
binSrc = Path.Combine (outputPath, "App1.pdb");
12541247
Assert.IsTrue (
12551248
File.Exists (linkDst),
12561249
"App1.pdb should be copied to linkdst directory because it has Abstrsact methods to fix up.");
12571250
Assert.IsTrue (
1258-
File.Exists (linkSrc),
1259-
"App1.pdb must be copied to linksrc directory");
1260-
FileAssert.AreEqual (linkSrc, linkDst, "{0} and {1} should not differ.", linkSrc, linkDst);
1261-
linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "App1.dll");
1262-
linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "App1.dll");
1263-
FileAssert.AreEqual (linkSrc, linkDst, "{0} and {1} should match.", linkSrc, linkDst);
1264-
1251+
File.Exists (binSrc),
1252+
"App1.pdb must be copied to bin directory");
1253+
FileAssert.AreEqual (binSrc, linkDst, "{0} and {1} should not differ.", binSrc, linkDst);
1254+
linkDst = Path.Combine (intermediate, "linkdst", "App1.dll");
1255+
binSrc = Path.Combine (outputPath, "App1.dll");
1256+
FileAssert.AreEqual (binSrc, linkDst, "{0} and {1} should match.", binSrc, linkDst);
12651257
}
12661258
}
12671259
}
@@ -1310,15 +1302,9 @@ public void BuildBasicApplicationCheckMdbAndPortablePdb ()
13101302
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "NetStandard16.pdb")),
13111303
"NetStandard16.pdb must be copied to Intermediate directory");
13121304
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "second build failed");
1313-
Assert.IsTrue (
1314-
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
1315-
"the _CopyMdbFiles target should be skipped");
13161305
var lastTime = File.GetLastWriteTimeUtc (pdbToMdbPath);
13171306
pdb.Timestamp = DateTimeOffset.UtcNow;
13181307
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "third build failed");
1319-
Assert.IsFalse (
1320-
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
1321-
"the _CopyMdbFiles target should not be skipped");
13221308
Assert.Less (lastTime,
13231309
File.GetLastWriteTimeUtc (pdbToMdbPath),
13241310
"{0} should have been updated", pdbToMdbPath);
@@ -2853,16 +2839,10 @@ public void BuildBasicApplicationCheckPdb ()
28532839
}
28542840
b.BuildLogFile = "build1.log";
28552841
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "second build failed");
2856-
Assert.IsTrue (
2857-
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
2858-
"the _CopyMdbFiles target should be skipped");
28592842
b.BuildLogFile = "build2.log";
28602843
var lastTime = File.GetLastWriteTimeUtc (pdbToMdbPath);
28612844
pdb.Timestamp = DateTimeOffset.UtcNow;
28622845
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "third build failed");
2863-
Assert.IsFalse (
2864-
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
2865-
"the _CopyMdbFiles target should not be skipped");
28662846
Assert.Less (lastTime,
28672847
File.GetLastWriteTimeUtc (pdbToMdbPath),
28682848
"{0} should have been updated", pdbToMdbPath);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,11 @@ public Class2 ()
346346
public void AppProjectTargetsDoNotBreak ()
347347
{
348348
var targets = new List<string> {
349-
"_CopyIntermediateAssemblies",
350349
"_GeneratePackageManagerJava",
351350
"_ResolveLibraryProjectImports",
352351
"_BuildAdditionalResourcesCache",
353352
"_CleanIntermediateIfNuGetsChange",
354353
"_CopyConfigFiles",
355-
"_CopyPdbFiles",
356354
};
357355
var proj = new XamarinFormsAndroidApplicationProject {
358356
OtherBuildItems = {
@@ -367,7 +365,6 @@ public void AppProjectTargetsDoNotBreak ()
367365
if (IsWindows) {
368366
//NOTE: pdb2mdb will run on Windows on the current project's symbols if DebugType=Full
369367
proj.SetProperty (proj.DebugProperties, "DebugType", "Full");
370-
targets.Add ("_CopyMdbFiles");
371368
targets.Add ("_ConvertPdbFiles");
372369
}
373370
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public void CheckBuildIdIsUnique ()
6666
var allFilesInArchive = Directory.GetFiles (archivePath, "*", SearchOption.AllDirectories);
6767
string extension = "dll";
6868
Assert.IsTrue (allFilesInArchive.Any (x => Path.GetFileName (x) == $"{proj.ProjectName}.{extension}"), $"{proj.ProjectName}.{extension} should exist in {archivePath}");
69-
//NOTE: Windows is still generating mdb files here
70-
extension = IsWindows ? "dll.mdb" : "pdb";
69+
extension = "pdb";
7170
Assert.IsTrue (allFilesInArchive.Any (x => Path.GetFileName (x) == $"{proj.ProjectName}.{extension}"), $"{proj.ProjectName}.{extension} should exist in {archivePath}");
7271

7372
string intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Compile Include="Linker\MonoDroid.Tuner\Linker.cs" />
122122
<Compile Include="Linker\MonoDroid.Tuner\LinkerOptions.cs" />
123123
<Compile Include="Linker\MonoDroid.Tuner\MonoDroidMarkStep.cs" />
124+
<Compile Include="Linker\MonoDroid.Tuner\OutputStepWithTimestamps.cs" />
124125
<Compile Include="Linker\MonoDroid.Tuner\PreserveHttpAndroidClientHandler.cs" />
125126
<Compile Include="Linker\MonoDroid.Tuner\StripEmbeddedLibraries.cs" />
126127
<Compile Include="Tasks\Aapt.cs" />

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,8 @@ because xbuild doesn't support framework reference assemblies.
21222122
;_CheckForObsoleteAssemblies
21232123
;_ResolveSatellitePaths
21242124
;_CreatePackageWorkspace
2125+
;_CopyConfigFiles
2126+
;_ConvertPdbFiles
21252127
;_LinkAssemblies
21262128
</_PrepareAssembliesDependsOnTargets>
21272129
</PropertyGroup>
@@ -2891,6 +2893,11 @@ because xbuild doesn't support framework reference assemblies.
28912893
_SetLatestTargetFrameworkVersion;
28922894
_GetLibraryImports;
28932895
_RemoveRegisterAttribute;
2896+
_ResolveAssemblies;
2897+
_ResolveSatellitePaths;
2898+
_CreatePackageWorkspace;
2899+
_CopyConfigFiles;
2900+
_ConvertPdbFiles;
28942901
_LinkAssemblies;
28952902
_GenerateJavaStubs;
28962903
_ConvertCustomView;

0 commit comments

Comments
 (0)