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
2 changes: 1 addition & 1 deletion external/Java.Interop
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static Pipeline CreatePipeline (LinkerOptions options)

if (options.LinkNone) {
pipeline.AppendStep (new FixAbstractMethodsStep ());
pipeline.AppendStep (new OutputStep ());
pipeline.AppendStep (new OutputStepWithTimestamps ());
return pipeline;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ static Pipeline CreatePipeline (LinkerOptions options)
pipeline.AppendStep (new StripEmbeddedLibraries ());
// end monodroid specific
pipeline.AppendStep (new RegenerateGuidStep ());
pipeline.AppendStep (new OutputStep ());
pipeline.AppendStep (new OutputStepWithTimestamps ());

return pipeline;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Linker.Steps;
using Xamarin.Android.Tools;

namespace MonoDroid.Tuner
{
/// <summary>
/// A subclass of OutputStep that overrides CopyAssembly and timestamps files properly with Files.CopyIfChanged
/// * original source from: https://github.com/mono/linker/blob/aa65acca5e41fbc1f8f597799381b853049704ff/src/linker/Linker.Steps/OutputStep.cs#L198-L231
/// </summary>
class OutputStepWithTimestamps : OutputStep
{
static FileInfo GetOriginalAssemblyFileInfo (AssemblyDefinition assembly)
{
return new FileInfo (assembly.MainModule.FileName);
}

protected override void CopyAssembly (AssemblyDefinition assembly, string directory)
{
// Special case. When an assembly has embedded pdbs, link symbols is not enabled, and the assembly's action is copy,
// we want to match the behavior of assemblies with the other symbol types and end up with an assembly that does not have symbols.
// In order to do that, we can't simply copy files. We need to write the assembly without symbols
if (assembly.MainModule.HasSymbols && !Context.LinkSymbols && assembly.MainModule.SymbolReader is EmbeddedPortablePdbReader) {
WriteAssembly (assembly, directory, new WriterParameters ());
return;
}

FileInfo fi = GetOriginalAssemblyFileInfo (assembly);
string target = Path.GetFullPath (Path.Combine (directory, fi.Name));
string source = fi.FullName;
if (source == target)
return;

Files.CopyIfChanged (source, target);

if (!Context.LinkSymbols)
return;

var mdb = source + ".mdb";
if (File.Exists (mdb))
Files.CopyIfChanged (mdb, target + ".mdb");

var pdb = Path.ChangeExtension (source, "pdb");
if (File.Exists (pdb))
Files.CopyIfChanged (pdb, Path.ChangeExtension (target, "pdb"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,9 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease)
// Xamarin.Android unless fastdev is enabled.
foreach (var file in new [] { "typemap.mj", "typemap.jm" }) {
var info = new FileInfo (Path.Combine (intermediate, "android", file));
if (!info.Exists) {
Assert.Ignore ($"{info.Name} does not exist, timestamp check skipped");
continue;
if (info.Exists) {
Assert.IsTrue (info.LastWriteTimeUtc > start, $"`{file}` is older than `{start}`, with a timestamp of `{info.LastWriteTimeUtc}`!");
}
Assert.IsTrue (info.LastWriteTimeUtc > start, $"`{file}` is older than `{start}`, with a timestamp of `{info.LastWriteTimeUtc}`!");
}

//One last build with no changes
Expand Down Expand Up @@ -1187,12 +1185,6 @@ public void BuildBasicApplicationCheckMdbRepeatBuild ()
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.pdb")),
"UnnamedProject.dll.mdb must be copied to the Intermediate directory");
Assert.IsTrue (b.Build (proj), "second build failed");
Assert.IsTrue (
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
"the _CopyMdbFiles target should be skipped");
Assert.IsTrue (
b.Output.IsTargetSkipped ("_CopyPdbFiles"),
"the _CopyPdbFiles target should be skipped");
Assert.IsTrue (
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.dll.mdb")) ||
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android/assets/UnnamedProject.pdb")),
Expand Down Expand Up @@ -1252,39 +1244,39 @@ public Class2 ()
Assert.IsTrue (libb.Build (lib), "Library1 Build should have succeeded.");
using (var b = CreateApkBuilder (Path.Combine (path, "App1"))) {
Assert.IsTrue (b.Build (proj), "App1 Build should have succeeded.");
var assetsPdb = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "Library1.pdb");
var linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "Library1.pdb");
var linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "Library1.pdb");
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
var outputPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
var assetsPdb = Path.Combine (intermediate, "android", "assets", "Library1.pdb");
var linkDst = Path.Combine (intermediate, "linkdst", "Library1.pdb");
var binSrc = Path.Combine (outputPath, "Library1.pdb");
Assert.IsTrue (
File.Exists (assetsPdb),
"Library1.pdb must be copied to Intermediate directory");
Assert.IsFalse (
File.Exists (linkDst),
"Library1.pdb should not be copied to linkdst directory because it has no Abstrsact methods to fix up.");
Assert.IsTrue (
File.Exists (linkSrc),
"Library1.pdb must be copied to linksrc directory");
var outputPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
File.Exists (binSrc),
"Library1.pdb must be copied to bin directory");
using (var apk = ZipHelper.OpenZip (Path.Combine (outputPath, proj.PackageName + "-Signed.apk"))) {
var data = ZipHelper.ReadFileFromZip (apk, "assemblies/Library1.pdb");
if (data == null)
data = File.ReadAllBytes (assetsPdb);
var filedata = File.ReadAllBytes (linkSrc);
Assert.AreEqual (filedata.Length, data.Length, "Library1.pdb in the apk should match {0}", linkSrc);
var filedata = File.ReadAllBytes (binSrc);
Assert.AreEqual (filedata.Length, data.Length, "Library1.pdb in the apk should match {0}", binSrc);
}
linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "App1.pdb");
linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "App1.pdb");
linkDst = Path.Combine (intermediate, "linkdst", "App1.pdb");
binSrc = Path.Combine (outputPath, "App1.pdb");
Assert.IsTrue (
File.Exists (linkDst),
"App1.pdb should be copied to linkdst directory because it has Abstrsact methods to fix up.");
Assert.IsTrue (
File.Exists (linkSrc),
"App1.pdb must be copied to linksrc directory");
FileAssert.AreEqual (linkSrc, linkDst, "{0} and {1} should not differ.", linkSrc, linkDst);
linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "App1.dll");
linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "App1.dll");
FileAssert.AreEqual (linkSrc, linkDst, "{0} and {1} should match.", linkSrc, linkDst);

File.Exists (binSrc),
"App1.pdb must be copied to bin directory");
FileAssert.AreEqual (binSrc, linkDst, "{0} and {1} should not differ.", binSrc, linkDst);
linkDst = Path.Combine (intermediate, "linkdst", "App1.dll");
binSrc = Path.Combine (outputPath, "App1.dll");
FileAssert.AreEqual (binSrc, linkDst, "{0} and {1} should match.", binSrc, linkDst);
}
}
}
Expand Down Expand Up @@ -1333,15 +1325,9 @@ public void BuildBasicApplicationCheckMdbAndPortablePdb ()
File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "NetStandard16.pdb")),
"NetStandard16.pdb must be copied to Intermediate directory");
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "second build failed");
Assert.IsTrue (
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
"the _CopyMdbFiles target should be skipped");
var lastTime = File.GetLastWriteTimeUtc (pdbToMdbPath);
pdb.Timestamp = DateTimeOffset.UtcNow;
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "third build failed");
Assert.IsFalse (
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
"the _CopyMdbFiles target should not be skipped");
Assert.Less (lastTime,
File.GetLastWriteTimeUtc (pdbToMdbPath),
"{0} should have been updated", pdbToMdbPath);
Expand Down Expand Up @@ -2855,16 +2841,10 @@ public void BuildBasicApplicationCheckPdb ()
}
b.BuildLogFile = "build1.log";
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "second build failed");
Assert.IsTrue (
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
"the _CopyMdbFiles target should be skipped");
b.BuildLogFile = "build2.log";
var lastTime = File.GetLastWriteTimeUtc (pdbToMdbPath);
pdb.Timestamp = DateTimeOffset.UtcNow;
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "third build failed");
Assert.IsFalse (
b.Output.IsTargetSkipped ("_CopyMdbFiles"),
"the _CopyMdbFiles target should not be skipped");
Assert.Less (lastTime,
File.GetLastWriteTimeUtc (pdbToMdbPath),
"{0} should have been updated", pdbToMdbPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,11 @@ public Class2 ()
public void AppProjectTargetsDoNotBreak ()
{
var targets = new List<string> {
"_CopyIntermediateAssemblies",
"_GeneratePackageManagerJava",
"_ResolveLibraryProjectImports",
"_BuildAdditionalResourcesCache",
"_CleanIntermediateIfNuGetsChange",
"_CopyConfigFiles",
"_CopyPdbFiles",
};
var proj = new XamarinFormsAndroidApplicationProject {
OtherBuildItems = {
Expand All @@ -366,7 +364,6 @@ public void AppProjectTargetsDoNotBreak ()
if (IsWindows) {
//NOTE: pdb2mdb will run on Windows on the current project's symbols if DebugType=Full
proj.SetProperty (proj.DebugProperties, "DebugType", "Full");
targets.Add ("_CopyMdbFiles");
targets.Add ("_ConvertPdbFiles");
}
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public void CheckBuildIdIsUnique ()
var allFilesInArchive = Directory.GetFiles (archivePath, "*", SearchOption.AllDirectories);
string extension = "dll";
Assert.IsTrue (allFilesInArchive.Any (x => Path.GetFileName (x) == $"{proj.ProjectName}.{extension}"), $"{proj.ProjectName}.{extension} should exist in {archivePath}");
//NOTE: Windows is still generating mdb files here
extension = IsWindows ? "dll.mdb" : "pdb";
extension = "pdb";
Assert.IsTrue (allFilesInArchive.Any (x => Path.GetFileName (x) == $"{proj.ProjectName}.{extension}"), $"{proj.ProjectName}.{extension} should exist in {archivePath}");

string intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Linker\MonoDroid.Tuner\Linker.cs" />
<Compile Include="Linker\MonoDroid.Tuner\LinkerOptions.cs" />
<Compile Include="Linker\MonoDroid.Tuner\MonoDroidMarkStep.cs" />
<Compile Include="Linker\MonoDroid.Tuner\OutputStepWithTimestamps.cs" />
<Compile Include="Linker\MonoDroid.Tuner\PreserveHttpAndroidClientHandler.cs" />
<Compile Include="Linker\MonoDroid.Tuner\StripEmbeddedLibraries.cs" />
<Compile Include="Tasks\Aapt.cs" />
Expand Down
Loading