Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] fix incremental builds for Xamarin.Forms projects #2088

Merged
merged 2 commits into from
Aug 31, 2018
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 @@ -259,20 +259,44 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease)
var start = DateTime.UtcNow.AddSeconds (-1);
var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
AndroidResources = {
new AndroidItem.AndroidResource ("Resources\\layout\\Tabbar.axml") {
TextContent = () => {
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.TabLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:app=\"http://schemas.android.com/apk/res-auto\" android:id=\"@+id/sliding_tabs\" android:background=\"?attr/colorPrimary\" android:theme=\"@style/ThemeOverlay.AppCompat.Dark.ActionBar\" app:tabIndicatorColor=\"@android:color/white\" app:tabGravity=\"fill\" app:tabMode=\"fixed\" />";
}
}
}
};
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))) {
//To be sure we are at a clean state, delete bin/obj
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
if (Directory.Exists (intermediate))
Directory.Delete (intermediate, true);
var output = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
if (Directory.Exists (output))
Directory.Delete (output, true);
//To be sure we are at a clean state
var projectDir = Path.Combine (Root, b.ProjectDirectory);
if (Directory.Exists (projectDir))
Directory.Delete (projectDir, true);

var intermediate = Path.Combine (projectDir, proj.IntermediateOutputPath);
Assert.IsTrue (b.Build (proj), "first build should have succeeded.");

//Absolutely non of these files should be *older* than the starting time of this test!
var files = Directory.EnumerateFiles (intermediate, "*", SearchOption.AllDirectories).ToList ();
files.AddRange (Directory.EnumerateFiles (output, "*", SearchOption.AllDirectories));
foreach (var file in files) {
var info = new FileInfo (file);
Assert.IsTrue (info.LastWriteTimeUtc > start, $"`{file}` is older than `{start}`, with a timestamp of `{info.LastWriteTimeUtc}`!");
Expand All @@ -291,8 +315,13 @@ public void CheckTimestamps ([Values (true, false)] bool isRelease)

//One last build with no changes
Assert.IsTrue (b.Build (proj), "third build should have succeeded.");
string targetName = isRelease ? "_LinkAssembliesShrink" : "_LinkAssembliesNoShrink";
Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!");
var targetsToBeSkipped = new [] {
isRelease ? "_LinkAssembliesShrink" : "_LinkAssembliesNoShrink",
"_UpdateAndroidResgen",
};
foreach (var targetName in targetsToBeSkipped) {
Assert.IsTrue (b.Output.IsTargetSkipped (targetName), $"`{targetName}` should be skipped!");
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public static bool ExtractAll(ZipArchive zip, string destination, Action<int, in
if (forceUpdate || entry.ModificationTime > dt) {
try {
entry.Extract (destination, fullName, FileMode.Create);
var utcNow = DateTime.UtcNow;
File.SetLastWriteTimeUtc (outfile, utcNow);
File.SetLastAccessTimeUtc (outfile, utcNow);
} catch (PathTooLongException) {
throw new PathTooLongException ($"Could not extract \"{fullName}\" to \"{outfile}\". Path is too long.");
}
Expand Down
31 changes: 23 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1952,9 +1952,11 @@ because xbuild doesn't support framework reference assemblies.
DestinationFiles="@(_AndroidResolvedSatellitePaths->'$(MonoAndroidLinkerInputDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
SkipUnchangedFiles="true"
/>
<Touch Files="@(ResolvedAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension)')" />
<Touch Files="@(_AndroidResolvedSatellitePaths->'$(MonoAndroidLinkerInputDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<Delete Files="@(ResolvedAssemblies->'$(MonoAndroidLinkerInputDir)%(Filename)%(Extension).mdb')" />
<ItemGroup>
<_IntermediateAssemblyFiles Include="$(MonoAndroidLinkerInputDir)*" />
</ItemGroup>
<Touch Files="@(_IntermediateAssemblyFiles)" />
</Target>

<Target Name="_CollectConfigFiles"
Expand Down Expand Up @@ -2028,7 +2030,7 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="CopiedFiles" ItemName="_PdbDebugFilesCopiedToLinkerSrc" />
<Output TaskParameter="CopiedFiles" ItemName="FileWrites" />
</Copy>
<Touch Files="@(_DebugFilesCopiedToLinkerSrc)" />
<Touch Files="@(_PdbFilesCopied);@(_PdbDebugFilesCopiedToLinkerSrc)" />
<WriteLinesToFile
File="$(IntermediateOutputPath)$(CleanFile)"
Lines="@(_PdbFilesCopied->'%(FullPath)');@(_PdbDebugFilesCopiedToLinkerSrc->'%(FullPath)')"
Expand All @@ -2050,7 +2052,7 @@ because xbuild doesn't support framework reference assemblies.
SkipUnchangedFiles="true">
<Output TaskParameter="CopiedFiles" ItemName="_MdbDebugFilesCopiedToLinkerSrc" />
</Copy>
<Touch Files="@(_DebugFilesCopiedToLinkerSrc)" />
<Touch Files="@(_MdbFilesCopied);@(_MdbDebugFilesCopiedToLinkerSrc)" />
<WriteLinesToFile
File="$(IntermediateOutputPath)$(CleanFile)"
Lines="@(_MdbFilesCopied->'%(FullPath)');@(_MdbDebugFilesCopiedToLinkerSrc->'%(FullPath)')"
Expand Down Expand Up @@ -2079,9 +2081,9 @@ because xbuild doesn't support framework reference assemblies.

<!--NOTE: the linker's use of File.Copy requires us to update the timestamps of output files -->
<ItemGroup>
<_FilesToTouch Include="$(MonoAndroidIntermediateAssemblyTempDir)*" />
<_LinkAssembliesNoShrinkFiles Include="$(MonoAndroidIntermediateAssemblyTempDir)*" />
</ItemGroup>
<Touch Files="@(_FilesToTouch)" />
<Touch Files="@(_LinkAssembliesNoShrinkFiles)" />

<!-- We don't have to depend on flag file for NoShrink, but it is used to check timestamp -->
<Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />
Expand Down Expand Up @@ -2116,6 +2118,12 @@ because xbuild doesn't support framework reference assemblies.
HttpClientHandlerType="$(AndroidHttpClientHandlerType)"
TlsProvider="$(AndroidTlsProvider)" />

<!--NOTE: the linker's use of File.Copy requires us to update the timestamps of output files -->
<ItemGroup>
<_LinkAssembliesShrinkFiles Include="$(MonoAndroidIntermediateAssetsDir)*" />
</ItemGroup>
<Touch Files="@(_LinkAssembliesShrinkFiles)" />

<!-- We have to use a flag instead of normal outputs because linking can delete unused assemblies -->
<Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />
</Target>
Expand Down Expand Up @@ -2198,7 +2206,7 @@ because xbuild doesn't support framework reference assemblies.
<Target Name="_GenerateJavaStubs"
DependsOnTargets="_SetLatestTargetFrameworkVersion;_PrepareAssemblies;$(_AfterPrepareAssemblies)"
Inputs="$(MSBuildAllProjects);@(_ResolvedAssemblies);$(_AndroidManifestAbs);$(_AndroidBuildPropertiesCache);@(_AndroidResourceDest)"
Outputs="$(IntermediateOutputPath)android\AndroidManifest.xml;$(_AcwMapFile);$(_AndroidTypeMappingJavaToManaged);$(_AndroidTypeMappingManagedToJava)">
Outputs="$(IntermediateOutputPath)_javastubs.stamp">
<GenerateJavaStubs
ResolvedAssemblies="@(_ResolvedAssemblies)"
ResolvedUserAssemblies="@(_ResolvedUserAssemblies)"
Expand All @@ -2225,7 +2233,13 @@ because xbuild doesn't support framework reference assemblies.
<ConvertResourcesCases
ResourceDirectories="$(MonoAndroidResDirIntermediate);@(LibraryResourceDirectories)"
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
AcwMapFile="$(_AcwMapFile)" />
AcwMapFile="$(_AcwMapFile)"
AndroidConversionFlagFile="$(IntermediateOutputPath)_javastubs.stamp"
/>
<Touch Files="$(IntermediateOutputPath)_javastubs.stamp;$(_AndroidResgenFlagFile)" AlwaysCreate="True" />
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)_javastubs.stamp" />
</ItemGroup>
</Target>

<Target Name="_GetAddOnPlatformLibraries" DependsOnTargets="_GenerateJavaStubs">
Expand Down Expand Up @@ -3057,6 +3071,7 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="$(MonoAndroidIntermediate)__AndroidNativeLibraries__.zip" />
<Delete Files="$(MonoAndroidIntermediate)stub_application_data.txt" />
<Delete Files="$(IntermediateOutputPath)_javac.stamp" />
<Delete Files="$(IntermediateOutputPath)_javastubs.stamp" />
<Delete Files="$(IntermediateOutputPath)compiled.flata" />
<Delete Files="$(_AndroidResFlagFile)" />
<Delete Files="$(_AndroidStripFlag)" />
Expand Down