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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Xamarin.ProjectTools;
using NUnit.Framework;
using System.Linq;
Expand Down Expand Up @@ -37,14 +37,19 @@ public void RepetitiveBuild ()
[Test]
public void DesignTimeBuild ([Values(false, true)] bool isRelease)
{
var path = Path.Combine (Root, "temp", $"DesignTimeBuild_{isRelease}");
var cachePath = Path.Combine (path, "Cache");
var envVar = new Dictionary<string, string> () {
{ "XAMARIN_CACHEPATH", cachePath },
};
var url = "http://dl-ssl.google.com/android/repository/build-tools_r24-macosx.zip";
var md5 = MD5.Create ();
var hash = string.Concat (md5.ComputeHash (Encoding.UTF8.GetBytes (url)).Select (b => b.ToString ("X02")));
var zipPath = Path.Combine (CachePath, "zips", $"{hash}.zip");
var zipPath = Path.Combine (cachePath, "zips", $"{hash}.zip");
if (File.Exists (zipPath))
File.Delete (zipPath);

var extractedDir = Path.Combine (CachePath, "Lib1");
var extractedDir = Path.Combine (cachePath, "Lib1");
if (Directory.Exists (extractedDir))
Directory.Delete (extractedDir, recursive: true);

Expand All @@ -65,19 +70,24 @@ public void DesignTimeBuild ([Values(false, true)] bool isRelease)
new BuildItem.ProjectReference (@"..\Lib1\Lib1.csproj", lib.ProjectName, lib.ProjectGuid),
},
};
var path = Path.Combine (Root, "temp", $"DesignTimeBuild_{isRelease}");

using (var l = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
using (var b = CreateApkBuilder (Path.Combine (path, proj.ProjectName))) {
l.Verbosity = LoggerVerbosity.Diagnostic;
Assert.IsTrue(l.Clean(lib), "Lib1 should have cleaned successfully");
Assert.IsTrue (l.Build (lib), "Lib1 should have built successfully");
b.Verbosity = LoggerVerbosity.Diagnostic;
b.ThrowOnBuildFailure = false;
Assert.IsTrue (b.UpdateAndroidResources (proj, parameters: new string [] { "DesignTimeBuild=true" }),
Assert.IsTrue (b.Clean(proj), "App should have cleaned successfully");
Assert.IsTrue (b.UpdateAndroidResources (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=true" }, environmentVariables: envVar),
"first build failed");
Assert.IsTrue (b.LastBuildOutput.Contains ("Skipping download of "),
"failed to skip the downloading of files.");
Assert.IsTrue (b.Build (proj), "second build failed");
Assert.IsTrue (File.Exists (zipPath), $"Zip should have been downloaded to {zipPath}");
WaitFor (1000);
b.Target = "Build";
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=false" }, environmentVariables: envVar), "second build failed");
Assert.IsFalse(b.Output.IsTargetSkipped ("_BuildAdditionalResourcesCache"), "_BuildAdditionalResourcesCache should have run.");
Assert.IsTrue (b.LastBuildOutput.Contains($"Downloading {url}") || b.LastBuildOutput.Contains ($"reusing existing archive: {zipPath}"), $"{url} should have been downloaded.");
Assert.IsTrue (File.Exists (Path.Combine (extractedDir, "1", "content", "android-N", "aapt")), $"Files should have been extracted to {extractedDir}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Xamarin.ProjectTools;
using NUnit.Framework;
using System.Linq;
using System.Threading;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -51,6 +52,12 @@ public string Root {
}
}

protected void WaitFor(int milliseconds)
{
var pause = new ManualResetEvent(false);
pause.WaitOne(milliseconds);
}

protected static string RunAdbCommand (string command, bool ignoreErrors = true)
{
string ext = Environment.OSVersion.Platform != PlatformID.Unix ? ".exe" : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using Microsoft.Build.Framework;
using System.Text;
using System.Collections.Generic;

namespace Xamarin.ProjectTools
{
Expand Down Expand Up @@ -97,7 +98,7 @@ string GetPathFromRegistry (string valueName)
return null;
}

protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null)
protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null)
{
string buildLogFullPath = (!string.IsNullOrEmpty (BuildLogFile))
? Path.GetFullPath (Path.Combine (Root, Path.GetDirectoryName (projectOrSolution), BuildLogFile))
Expand Down Expand Up @@ -154,7 +155,13 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
args.AppendFormat (" /p:{0}", param);
}
}
if (environmentVariables != null) {
foreach (var kvp in environmentVariables) {
psi.EnvironmentVariables[kvp.Key] = kvp.Value;
}
}
psi.Arguments = args.ToString ();

psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public void Save (XamarinProject project, bool doNotCleanupOnUpdate = false, boo
project.UpdateProjectFiles (ProjectDirectory, files, doNotCleanupOnUpdate);
}

public bool Build (XamarinProject project, bool doNotCleanupOnUpdate = false, string [] parameters = null, bool saveProject = true)
public bool Build (XamarinProject project, bool doNotCleanupOnUpdate = false, string [] parameters = null, bool saveProject = true, Dictionary<string, string> environmentVariables = null)
{
Save (project, doNotCleanupOnUpdate, saveProject);

Output = project.CreateBuildOutput (this);

project.NuGetRestore (ProjectDirectory, PackagesDirectory);

bool result = BuildInternal (Path.Combine (ProjectDirectory, project.ProjectFilePath), Target, parameters);
bool result = BuildInternal (Path.Combine (ProjectDirectory, project.ProjectFilePath), Target, parameters, environmentVariables);
built_before = true;

if (CleanupAfterSuccessfulBuild)
Expand All @@ -83,12 +83,12 @@ public bool Clean (XamarinProject project, bool doNotCleanupOnUpdate = false)
}
}

public bool UpdateAndroidResources (XamarinProject project, bool doNotCleanupOnUpdate = false, string [] parameters = null)
public bool UpdateAndroidResources (XamarinProject project, bool doNotCleanupOnUpdate = false, string [] parameters = null, Dictionary<string, string> environmentVariables = null)
{
var oldTarget = Target;
Target = "UpdateAndroidResources";
try {
return Build (project, doNotCleanupOnUpdate: doNotCleanupOnUpdate, parameters: parameters);
return Build (project, doNotCleanupOnUpdate: doNotCleanupOnUpdate, parameters: parameters, environmentVariables: environmentVariables);
}
finally {
Target = oldTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
</PropertyGroup>
</Target>

<PropertyGroup>
<_BeforeBuildAdditionalResourcesCache>
_CreatePropertiesCache;
</_BeforeBuildAdditionalResourcesCache>
</PropertyGroup>

<Target Name="_BuildAdditionalResourcesCache"
Inputs="@(ReferencePath);@(ReferenceDependencyPaths);$(MSBuildProjectFullPath);$(NugetPackagesConfig);$(_AndroidBuildPropertiesCache)"
Outputs="$(_AndroidResourcePathsCache)"
Expand Down