Skip to content

Commit

Permalink
Cherry-pick fix for #1286
Browse files Browse the repository at this point in the history
Fixes: #1286
  • Loading branch information
jonpryor authored Feb 15, 2018
2 parents 3e0db25 + be0c744 commit ef7a59f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ Copyright (C) 2014 Xamarin. All rights reserved.

<PropertyGroup>
<Debugger Condition="'$(Debugger)'==''">Xamarin</Debugger>
<_IsRunningXBuild Condition=" '$(MSBuildRuntimeVersion)' == '' ">true</_IsRunningXBuild>
</PropertyGroup>

<Target Name="_RegisterMdbFilesWithFileWrites" BeforeTargets="IncrementalClean">
<CreateItem Include="$(OutDir)*.dll.mdb;$(MonoAndroidIntermediateAssemblyDir)*.dll.mdb;$(MonoAndroidIntermediateAssemblyDir)*.pdb;$(MonoAndroidLinkerInputDir)*.dll.mdb;$(MonoAndroidLinkerInputDir)*.pdb;$(_AndroidManagedResourceDesignerFile)">
<Output TaskParameter="Include" ItemName="_FilesToRegister" />
</CreateItem>
<Target Name="_RegisterAndroidFilesWithFileWrites" BeforeTargets="IncrementalClean" Condition=" '$(_IsRunningXBuild)' != 'true' ">
<CreateItem Include="$(OutDir)*.pdb;$(OutDir)*.dll;$(OutDir)*.dll.mdb;$(MonoAndroidIntermediateAssemblyDir)*.dll.mdb;$(MonoAndroidIntermediateAssemblyDir)*.pdb;$(MonoAndroidLinkerInputDir)*.dll.mdb;$(MonoAndroidLinkerInputDir)*.pdb">
<Output TaskParameter="Include" ItemName="_FilesToRegister" />
</CreateItem>
<CreateItem Include="$([System.IO.Path]::GetFullPath('%(_FilesToRegister.Identity)'))"
Condition="Exists('%(_FilesToRegister.Identity)')">
<Output TaskParameter="Include" ItemName="_CleanCurrentFileWrites" />
</CreateItem>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ public void BuildAppWithManagedResourceParser()
"Target '_ManagedUpdateAndroidResgen' should not have run.");

Assert.IsTrue (appBuilder.Clean (appProj), "Clean should have succeeded");
Assert.IsFalse (File.Exists (designerFile), $"'{designerFile}' should have been cleaned.");
Assert.IsTrue (File.Exists (designerFile), $"'{designerFile}' should not have been cleaned.");

}
}
Expand Down Expand Up @@ -1110,10 +1110,10 @@ public void BuildAppWithManagedResourceParserAndLibraries ()


Assert.IsTrue (appBuilder.Clean (appProj), "Clean should have succeeded");
Assert.IsFalse (File.Exists (designerFile), $"'{designerFile}' should have been cleaned.");
Assert.IsTrue (File.Exists (designerFile), $"'{designerFile}' should not have been cleaned.");
designerFile = Path.Combine (Root, path, libProj.ProjectName, libProj.IntermediateOutputPath, "designtime", "Resource.Designer.cs");
Assert.IsTrue (libBuilder.Clean (libProj), "Clean should have succeeded");
Assert.IsFalse (File.Exists (designerFile), $"'{designerFile}' should have been cleaned.");
Assert.IsTrue (File.Exists (designerFile), $"'{designerFile}' should not have been cleaned.");


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,85 @@ namespace Xamarin.Android.Build.Tests
[Parallelizable (ParallelScope.Children)]
public class IncrementalBuildTest : BaseTest
{
[Test]
public void IncrementalCleanDuringClean ()
{
var path = Path.Combine ("temp", TestName);
var proj = new XamarinAndroidApplicationProject () {
ProjectName = "App1",
IsRelease = true,
};
proj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True");
proj.SetProperty ("BuildingInsideVisualStudio", "True");
using (var b = CreateApkBuilder (path)) {
b.Target = "Compile";
Assert.IsTrue(b.Build (proj), "DesignTime Build should have succeeded");
var designTimeDesigner = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "designtime", "Resource.designer.cs");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should have been created.");
b.Target = "Build";
Assert.IsTrue(b.Build (proj), "Build should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after Build.");
b.Target = "Clean";
Assert.IsTrue(b.Build (proj), "Clean should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after Clean.");
b.Target = "Compile";
Assert.IsTrue(b.Build (proj), "Build should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after Compile.");
b.Target = "Build";
Assert.IsTrue(b.Build (proj), "Build should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after second Build.");
Assert.IsTrue(b.Build (proj), "Build should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after third Build.");
b.Target = "Compile";
Assert.IsTrue(b.Build (proj), "Build should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after second Compile.");
b.Target = "Clean";
Assert.IsTrue(b.Build (proj), "Clean should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after second Clean.");
b.Target = "ReBuild";
Assert.IsTrue(b.Build (proj), "ReBuild should have succeeded");
FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should still exist after ReBuild.");
}

}

[Test]
public void LibraryIncrementalBuild () {

var testPath = Path.Combine ("temp", TestName);
var class1Source = new BuildItem.Source ("Class1.cs") {
TextContent = () => @"
using System;
namespace Lib
{
public class Class1
{
public Class1 ()
{
}
}
}"
};
var lib = new XamarinAndroidLibraryProject () {
ProjectName = "Lib",
ProjectGuid = Guid.NewGuid ().ToString (),
Sources = {
class1Source,
},
};
using (var b = CreateDllBuilder (Path.Combine (testPath, "Lib"))) {
Assert.IsTrue (b.Build (lib), "Build should have succeeded.");
Assert.IsTrue (b.LastBuildOutput.ContainsText ("LogicalName=__AndroidLibraryProjects__.zip") ||
b.LastBuildOutput.ContainsText ("Lib.obj.Debug.__AndroidLibraryProjects__.zip,__AndroidLibraryProjects__.zip"),
"The LogicalName for __AndroidLibraryProjects__.zip should be set.");
class1Source.Timestamp = DateTime.UtcNow.Add (TimeSpan.FromMinutes (1));
Assert.IsTrue (b.Build (lib), "Build should have succeeded.");
Assert.IsTrue (b.LastBuildOutput.ContainsText ("LogicalName=__AndroidLibraryProjects__.zip") ||
b.LastBuildOutput.ContainsText ("Lib.obj.Debug.__AndroidLibraryProjects__.zip,__AndroidLibraryProjects__.zip"),
"The LogicalName for __AndroidLibraryProjects__.zip should be set.");
}
}

[Test]
public void AllProjectsHaveSameOutputDirectory()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,6 @@ because xbuild doesn't support framework reference assemblies.
<Compile Remove="@(CorrectCasedItem)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And '%(CorrectCasedItem.Identity)' != '' "/>
<Compile Include="$(_AndroidManagedResourceDesignerFile)" Condition=" '$(ManagedDesignTimeBuild)' == 'True' And Exists ('$(_AndroidManagedResourceDesignerFile)')" />
</ItemGroup>
<WriteLinesToFile
Condition="Exists ('$(_AndroidManagedResourceDesignerFile)')"
File="$(IntermediateOutputPath)$(CleanFile)"
Lines="$([System.IO.Path]::GetFullPath('$(_AndroidManagedResourceDesignerFile)'))"
Overwrite="false" />
</Target>

<!-- Resource Build -->
Expand Down

0 comments on commit ef7a59f

Please sign in to comment.