Skip to content

Commit

Permalink
[xabuild] Multiple Symlinking xabuilds (dotnet#940)
Browse files Browse the repository at this point in the history
This commit fixes a couple of issues which appeared when
using `xabuild.exe` on macOS. Firstly if the symlink exists
already the SymbolicLink code will error out and fail the
build completely. This happens because if you run two or
more `xabuild.exe` instances at the same time they trip over
each other trying to create the symlink.

So rather than error'ing completely we should only error if
the link does NOT exist. If it does exist after an attempted
creation we should ignore the exception.

The other is about where we look for extensions. Xamarin.Android
is installed on macOS into

	/Library/Frameworks/Mono.framework/External/xbuild

this was not included in the search path for MSBuild, so it never
manages to find the required `.targets` files.
  • Loading branch information
dellis1972 authored and Redth committed Oct 30, 2017
1 parent c5f7aed commit bc2980e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions tools/xabuild/SymbolicLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ public static bool Create (string source, string target)
if (!CreateSymbolicLink (source, target, SymbolLinkFlag.Directory | SymbolLinkFlag.AllowUnprivilegedCreate) &&
!CreateSymbolicLink (source, target, SymbolLinkFlag.Directory)) {
var error = new Win32Exception ().Message;
Console.Error.WriteLine ($"Unable to create symbolic link from `{source}` to `{target}`: {error}");
return false;
var result = Directory.Exists (source);
if (!result)
Console.Error.WriteLine ($"Unable to create symbolic link from `{source}` to `{target}`: {error}");
return result;
}
} else {
try {
var sourceInfo = new UnixFileInfo (source);
var fileInfo = new UnixFileInfo (target);
fileInfo.CreateSymbolicLink (source);
} catch (Exception exc) {
Console.Error.WriteLine ($"Unable to create symbolic link from `{source}` to `{target}`: {exc.Message}");
} catch (UnixIOException exc) {
if (exc.ErrorCode == Mono.Unix.Native.Errno.EEXIST) {
return true;
}
Console.Error.WriteLine ($"Unable to create symbolic link from `{source}` to `{target}`: {exc}");
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/xabuild/XABuildPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ public XABuildPaths ()
SearchPathsOS = "windows";
} else {
string mono = IsMacOS ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" : "/usr/lib/mono";
string monoExternal = IsMacOS ? "/Library/Frameworks/Mono.framework/External/" : "/usr/lib/mono";
MSBuildPath = Path.Combine (mono, "msbuild");
MSBuildBin = Path.Combine (MSBuildPath, "15.0", "bin");
MSBuildConfig = Path.Combine (MSBuildBin, "MSBuild.dll.config");
ProjectImportSearchPaths = new [] { MSBuildPath, Path.Combine (mono, "xbuild") };
ProjectImportSearchPaths = new [] { MSBuildPath, Path.Combine (mono, "xbuild"), Path.Combine (monoExternal, "xbuild") };
SystemProfiles = Path.Combine (mono, "xbuild-frameworks");
XABuildConfig = Path.Combine (XABuildDirectory, "MSBuild.dll.config");
SearchPathsOS = IsMacOS ? "osx" : "unix";
Expand Down

0 comments on commit bc2980e

Please sign in to comment.