Skip to content

Commit

Permalink
Merge pull request #923 from DustinCampbell/mono-build-environment
Browse files Browse the repository at this point in the history
Add logic to set MSBuildExtensionsPath to Mono's xbuild directory
  • Loading branch information
DustinCampbell authored Jul 26, 2017
2 parents d3d1915 + 666d413 commit 6b9c7cf
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 76 deletions.
7 changes: 5 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ Task("Test")
var instanceFolder = CombinePaths(env.Folders.Tests, testProject, "bin", testConfiguration, "net46");

// Copy xunit executable to test folder to solve path errors
var xunitToolsFolder = CombinePaths(env.Folders.Tools, "xunit.runner.console", "tools");
var xunitToolsFolder = CombinePaths(env.Folders.Tools, "xunit.runner.console", "tools", "net452");
var xunitInstancePath = CombinePaths(instanceFolder, "xunit.console.exe");
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.console.exe"), xunitInstancePath, overwrite: true);
FileHelper.Copy(CombinePaths(xunitToolsFolder, "xunit.runner.utility.net452.dll"), CombinePaths(instanceFolder, "xunit.runner.utility.net452.dll"), overwrite: true);
var targetPath = CombinePaths(instanceFolder, $"{testProject}.dll");
var logFile = CombinePaths(env.Folders.ArtifactsLogs, $"{testProject}-desktop-result.xml");
var arguments = $"\"{targetPath}\" -parallel none -xml \"{logFile}\" -notrait category=failing";
var arguments = $"\"{targetPath}\" -parallel none -noshadow -xml \"{logFile}\" -notrait category=failing";

if (Platform.Current.IsWindows)
{
Expand Down Expand Up @@ -511,9 +511,12 @@ Task("OnlyPublish")
DirectoryHelper.Copy($"{env.Folders.MSBuildBase}-{framework}", CombinePaths(outputFolder, "msbuild"));

// For OSX/Linux net46 builds, copy the MSBuild libraries built for Mono.
// In addition, delete System.Runtime.InteropServices.RuntimeInformation, which is Windows-specific.
if (!Platform.Current.IsWindows && framework == "net46")
{
DirectoryHelper.Copy($"{env.Folders.MonoMSBuildLib}", outputFolder);

FileHelper.Delete(CombinePaths(outputFolder, "System.Runtime.InteropServices.RuntimeInformation.dll"));
}

if (requireArchive)
Expand Down
4 changes: 2 additions & 2 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"LegacyDotNetVersion": "1.0.0-preview2-1-003177",
"RequiredMonoVersion": "5.2.0.196",
"DownloadURL": "https://omnisharpdownload.blob.core.windows.net/ext",
"MSBuildRuntimeForMono": "Microsoft.Build.Runtime.Mono-alpha4.zip",
"MSBuildLibForMono": "Microsoft.Build.Lib.Mono-alpha4.zip",
"MSBuildRuntimeForMono": "Microsoft.Build.Runtime.Mono-alpha5.zip",
"MSBuildLibForMono": "Microsoft.Build.Lib.Mono-alpha5.zip",
"Frameworks": [
"net46",
"netcoreapp1.1"
Expand Down
123 changes: 93 additions & 30 deletions src/OmniSharp.Abstractions/Utilities/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ namespace OmniSharp.Utilities
{
public static class PlatformHelper
{
private static Lazy<bool> s_isMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
private static Lazy<string> s_monoRuntimePath = new Lazy<string>(FindMonoRuntimePath);
private static Lazy<string> s_monoXBuildFrameworksDirPath = new Lazy<string>(FindMonoXBuildFrameworksDirPath);

public static bool IsMono => s_isMono.Value;
public static string MonoRuntimePath => s_monoRuntimePath.Value;
public static string MonoXBuildFrameworksDirPath => s_monoXBuildFrameworksDirPath.Value;
private static IEnumerable<string> s_searchPaths;
private static string s_monoRuntimePath;
private static string s_monoLibDirPath;

public static bool IsMono => Type.GetType("Mono.Runtime") != null;
public static bool IsWindows => Path.DirectorySeparatorChar == '\\';

private static IEnumerable<string> s_searchPaths;

public static IEnumerable<string> GetSearchPaths()
{
if (s_searchPaths == null)
Expand Down Expand Up @@ -65,55 +60,123 @@ private static string RealPath(string path)
return result;
}

private static string FindMonoRuntimePath()
public static string GetMonoRuntimePath()
{
if (IsWindows)
{
return null;
}

var monoPath = GetSearchPaths()
.Select(p => Path.Combine(p, "mono"))
.FirstOrDefault(File.Exists);

if (monoPath == null)
if (s_monoRuntimePath == null)
{
return null;
var monoPath = GetSearchPaths()
.Select(p => Path.Combine(p, "mono"))
.FirstOrDefault(File.Exists);

if (monoPath == null)
{
return null;
}

s_monoRuntimePath = RealPath(monoPath);
}

return RealPath(monoPath);
return s_monoRuntimePath;
}

private static string FindMonoXBuildFrameworksDirPath()
public static string GetMonoLibDirPath()
{
if (IsWindows)
{
return null;
}

const string defaultXBuildFrameworksDirPath = "/usr/lib/mono/xbuild-frameworks";
if (Directory.Exists(defaultXBuildFrameworksDirPath))
const string DefaultMonoLibPath = "/usr/lib/mono";
if (Directory.Exists(DefaultMonoLibPath))
{
return defaultXBuildFrameworksDirPath;
return DefaultMonoLibPath;
}

// The normal Unix path doesn't exist, so we'll fallback to finding Mono using the
// runtime location. This is the likely situation on macOS.
var monoRuntimePath = MonoRuntimePath;
if (string.IsNullOrEmpty(monoRuntimePath))

if (s_monoLibDirPath == null)
{
var monoRuntimePath = GetMonoRuntimePath();
if (monoRuntimePath == null)
{
return null;
}

var monoDirPath = Path.GetDirectoryName(monoRuntimePath);

var monoLibDirPath = Path.Combine(monoDirPath, "..", "lib", "mono");
monoLibDirPath = Path.GetFullPath(monoLibDirPath);

s_monoLibDirPath = Directory.Exists(monoLibDirPath)
? monoLibDirPath
: null;
}

return s_monoLibDirPath;
}

public static string GetMonoMSBuildDirPath()
{
if (IsWindows)
{
return null;
}

var monoLibDirPath = GetMonoLibDirPath();

var monoMSBuildDirPath = Path.Combine(monoLibDirPath, "msbuild");
monoMSBuildDirPath = Path.GetFullPath(monoMSBuildDirPath);

return Directory.Exists(monoMSBuildDirPath)
? monoMSBuildDirPath
: null;
}

public static string GetMonoXBuildDirPath()
{
if (IsWindows)
{
return null;
}

// mono should be located within a directory that is a sibling to the lib directory.
var monoDirPath = Path.GetDirectoryName(monoRuntimePath);
const string DefaultMonoXBuildDirPath = "/usr/lib/mono/xbuild";
if (Directory.Exists(DefaultMonoXBuildDirPath))
{
return DefaultMonoXBuildDirPath;
}

var monoLibDirPath = GetMonoLibDirPath();

var monoXBuildDirPath = Path.Combine(monoLibDirPath, "xbuild");
monoXBuildDirPath = Path.GetFullPath(monoXBuildDirPath);

return Directory.Exists(monoXBuildDirPath)
? monoXBuildDirPath
: null;
}

public static string GetMonoXBuildFrameworksDirPath()
{
if (IsWindows)
{
return null;
}

const string DefaultMonoXBuildFrameworksDirPath = "/usr/lib/mono/xbuild-frameworks";
if (Directory.Exists(DefaultMonoXBuildFrameworksDirPath))
{
return DefaultMonoXBuildFrameworksDirPath;
}

// The base directory is one folder up
var monoBaseDirPath = Path.Combine(monoDirPath, "..");
monoBaseDirPath = Path.GetFullPath(monoBaseDirPath);
var monoLibDirPath = GetMonoLibDirPath();

// We expect the xbuild-frameworks to be in /Versions/Current/lib/mono/xbuild-frameworks.
var monoXBuildFrameworksDirPath = Path.Combine(monoBaseDirPath, "lib", "mono", "xbuild-frameworks");
var monoXBuildFrameworksDirPath = Path.Combine(monoLibDirPath, "xbuild-frameworks");
monoXBuildFrameworksDirPath = Path.GetFullPath(monoXBuildFrameworksDirPath);

return Directory.Exists(monoXBuildFrameworksDirPath)
Expand Down
Loading

0 comments on commit 6b9c7cf

Please sign in to comment.