Skip to content
Closed
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
49 changes: 49 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/SetMSBuildExtensionsPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.IO;
using System.Linq;

using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Tasks
{
public sealed class SetMSBuildExtensionsPath : Task
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name seems to suggest that it sets the path to some given path. Since, it's trying to compute it internally, maybe it should renamed to indicate what it is doing or setting the path to?

{
const string MSBuildExtensionsPath = "MSBuildExtensionsPath";
const string XBUILD_FRAMEWORK_FOLDERS_PATH = "XBUILD_FRAMEWORK_FOLDERS_PATH";
public override bool Execute ()
{
var frameworksPath = Path.GetDirectoryName (typeof (SetMSBuildExtensionsPath).Assembly.Location);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this task being loaded from? Can this path that we are trying to determine here, be computed in the targets and passed as input here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task is being loaded from wherever Xamarin.Android.Build.Tasks.dll is installed, $prefix/lib/xbuild/Xamarin/Android on OS X.

if (Path.DirectorySeparatorChar == '\\') {
// TODO: Default Windows search location
} else {
// e == $prefix/lib/xbuild/Xamarin/Android
// Want: $prefix/lib/xbuild-frameworks
if (!frameworksPath.EndsWith ("xbuild/Xamarin/Android", StringComparison.OrdinalIgnoreCase)) {
throw new NotSupportedException ("Cannot determine path to xbuild-frameworks!");
}
frameworksPath = Path.GetDirectoryName (Path.GetDirectoryName (Path.GetDirectoryName (frameworksPath)));
frameworksPath = Path.Combine (frameworksPath, "xbuild-frameworks");
}

UpdateEnvironmentVariable (MSBuildExtensionsPath, frameworksPath);
UpdateEnvironmentVariable (XBUILD_FRAMEWORK_FOLDERS_PATH, frameworksPath);

return !Log.HasLoggedErrors;
}

void UpdateEnvironmentVariable (string environmentVariable, string newPath)
{
var p = (Environment.GetEnvironmentVariable (environmentVariable) ?? "")
.Split (new [] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
if (p.Any (x => string.Equals (x, newPath, StringComparison.OrdinalIgnoreCase))) {
return;
}

var newValue = string.Join (Path.PathSeparator.ToString (), new [] { newPath }.Concat (p));
Log.LogMessage (MessageImportance.Low, $" Setting environment variable `{environmentVariable}`='{newValue}'.");
Environment.SetEnvironmentVariable (environmentVariable, newValue);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
<UsingTask TaskName="Xamarin.Android.Tasks.CreateNativeLibraryArchive" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.ImportJavaDoc" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.MDoc" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.SetMSBuildExtensionsPath" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />

<!--
*******************************************
Expand Down Expand Up @@ -142,6 +143,7 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
</PropertyGroup>

<Target Name="_GetReferenceAssemblyPaths">
<SetMSBuildExtensionsPath />
<GetReferenceAssemblyPaths
TargetFrameworkMoniker="$(TargetFrameworkIdentifier),Version=v1.0"
RootPath="$(TargetFrameworkRootPath)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@
<Compile Include="Tasks\CheckTargetFrameworks.cs" />
<Compile Include="Tasks\Dx.cs" />
<Compile Include="Tasks\CreateMsymManifest.cs" />
<Compile Include="Tasks\SetMSBuildExtensionsPath.cs" />
<Compile Include="Utilities\AndroidResource.cs">
<Link>Utilities\AndroidResource.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<UsingTask TaskName="Xamarin.Android.Tasks.Proguard" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.DetermineJavaLibrariesToCompile" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.CreateMultiDexMainDexClassList" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tasks.SetMSBuildExtensionsPath" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />

<!--
*******************************************
Expand Down Expand Up @@ -531,6 +532,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
</Target>

<Target Name="_GetReferenceAssemblyPaths">
<SetMSBuildExtensionsPath />
<GetReferenceAssemblyPaths
TargetFrameworkMoniker="$(TargetFrameworkIdentifier),Version=v1.0"
RootPath="$(TargetFrameworkRootPath)">
Expand Down