Skip to content

Commit

Permalink
Add platform abstraction for OS name and architecture. (#851)
Browse files Browse the repository at this point in the history
* Add platform abstraction for OS name and architecture.

Related #820 #679

* Fix build failures due to incorrect references.

* Publish projects for net46 if mono is available.

* Fix typo in build script.

* Support for mono in multitargeted tests.

Choose mono as launcher for net46 tests if the launcher for vstest.console
is not mono (e.g. dotnet test).
  • Loading branch information
codito authored Jun 20, 2017
1 parent 8451cd4 commit bf43157
Show file tree
Hide file tree
Showing 34 changed files with 403 additions and 181 deletions.
106 changes: 62 additions & 44 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ DOTNET_RUNTIME_VERSION="2.0.0-preview2-25331-01"
# Build configuration
#
TPB_Solution="TestPlatform.sln"
TPB_TargetFramework="net46"
TPB_TargetFrameworkCore="netcoreapp2.0"
TPB_TargetFrameworkCore10="netcoreapp1.0"
TPB_Configuration=$CONFIGURATION
Expand Down Expand Up @@ -203,8 +204,6 @@ function invoke_build()
log ".. .. Build: Source: $TPB_Solution"

if $TPB_HasMono; then
# Workaround for https://github.com/dotnet/sdk/issues/335
export FrameworkPathOverride=/usr/lib/mono/4.5/
if [ -z "$PROJECT_NAME_PATTERNS" ]
then
$dotnet build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild || failed=true
Expand Down Expand Up @@ -259,57 +258,71 @@ function publish_package()
log "publish_package: Started."
local start=$SECONDS

coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore

PROJECTPACKAGEOUTPUTMAP=( \
$TP_PACKAGE_PROJ_DIR/package.csproj:$coreCLRPackageDir \
$TP_ROOT_DIR/src/vstest.console/vstest.console.csproj:$coreCLRPackageDir \
$TP_ROOT_DIR/src/datacollector/datacollector.csproj:$coreCLRPackageDir
local packageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFramework/$TPB_TargetRuntime
local coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore
local frameworkPackageDirMap=( \
$TPB_TargetFrameworkCore:$coreCLRPackageDir \
$TPB_TargetFramework:$packageDir
)

for item in "${PROJECTPACKAGEOUTPUTMAP[@]}" ;
for fxpkg in "${frameworkPackageDirMap[@]}" ;
do
projectToPackage="${item%%:*}"
packageOutputPath="${item##*:}"
log "Package: Publish $projectToPackage"
$dotnet publish $projectToPackage --configuration $TPB_Configuration --framework $TPB_TargetFrameworkCore --output $packageOutputPath -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild
local framework="${fxpkg%%:*}"
local packageDir="${fxpkg##*:}"
local projects=( \
$TP_PACKAGE_PROJ_DIR/package.csproj \
$TP_ROOT_DIR/src/vstest.console/vstest.console.csproj \
$TP_ROOT_DIR/src/datacollector/datacollector.csproj
)

if [ "$framework" == "net46" ] && ! $TPB_HasMono; then
# Skip publish if mono is not available
continue
fi

log "Package: Publish projects for $framework"
for project in "${projects[@]}" ;
do
log ".. Package: Publish $project"
$dotnet publish $project --configuration $TPB_Configuration --framework $framework --output $packageDir -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild
done

# Copy TestHost for desktop targets if we've built net46
# packages with mono
if $TPB_HasMono; then
local testhost=$packageDir/TestHost
mkdir -p $testhost
cp -r src/testhost/bin/$TPB_Configuration/net46/win7-x64/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/net46/win7-x64/* $testhost
fi

# Copy over the logger assemblies to the Extensions folder.
local extensionsDir="$packageDir/Extensions"
# Create an extensions directory.
mkdir -p $extensionsDir

# Note Note: If there are some dependencies for the logger assemblies, those need to be moved too.
# Ideally we should just be publishing the loggers to the Extensions folder.
loggers=("Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll" "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.pdb")
for i in ${loggers[@]}; do
mv $packageDir/${i} $extensionsDir
done

# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
runtimeproviders=("Microsoft.TestPlatform.TestHostRuntimeProvider.dll" "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
for i in ${runtimeproviders[@]}; do
mv $packageDir/${i} $extensionsDir
done
newtonsoft=$TP_PACKAGES_DIR/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
cp $newtonsoft $packageDir
done

# Publish TestHost for netcoreapp1.0 target
log "Package: Publish testhost.csproj"
log ".. Package: Publish testhost.csproj"
local projectToPackage=$TP_ROOT_DIR/src/testhost/testhost.csproj
local packageOutputPath=$TP_OUT_DIR/$TPB_Configuration/Microsoft.TestPlatform.TestHost/$TPB_TargetFrameworkCore10
$dotnet publish $projectToPackage --configuration $TPB_Configuration --framework $TPB_TargetFrameworkCore10 --output $packageOutputPath -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild

# Copy TestHost for desktop targets if we've built net46
# packages with mono
if $TPB_HasMono; then
local testhost=$coreCLRPackageDir/TestHost
mkdir -p $testhost
cp -r src/testhost/bin/$TPB_Configuration/net46/win7-x64/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/net46/win7-x64/* $testhost
fi

# Copy over the logger assemblies to the Extensions folder.
coreCLRExtensionsDir="$coreCLRPackageDir/Extensions"
# Create an extensions directory.
mkdir -p $coreCLRExtensionsDir

# Note Note: If there are some dependencies for the logger assemblies, those need to be moved too.
# Ideally we should just be publishing the loggers to the Extensions folder.
loggers=("Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll" "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.pdb")
for i in ${loggers[@]}; do
mv $coreCLRPackageDir/${i} $coreCLRExtensionsDir
done

# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
runtimeproviders=("Microsoft.TestPlatform.TestHostRuntimeProvider.dll" "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
for i in ${runtimeproviders[@]}; do
mv $coreCLRPackageDir/${i} $coreCLRExtensionsDir
done
newtonsoft=$TP_PACKAGES_DIR/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
cp $newtonsoft $coreCLRPackageDir

# For libraries that are externally published, copy the output into artifacts. These will be signed and packaged independently.
packageName="Microsoft.TestPlatform.Build"
binariesDirectory="src/$packageName/bin/$TPB_Configuration/**"
Expand Down Expand Up @@ -397,6 +410,11 @@ log "Test platform environment variables: "
log "Test platform build variables: "
(set | grep ^TPB_)

if $TPB_HasMono; then
# Workaround for https://github.com/dotnet/sdk/issues/335
export FrameworkPathOverride=/usr/lib/mono/4.5/
fi

if [ -z "$PROJECT_NAME_PATTERNS" ]
then
install_cli && restore_package && invoke_build && publish_package && create_package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,82 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Resources;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

public class DotnetHostHelper : IDotnetHostHelper
{
public const string MONOEXENAME = "mono";

private readonly IFileHelper fileHelper;
private readonly IEnvironment environment;

/// <summary>
/// Initializes a new instance of the <see cref="DotnetHostHelper"/> class.
/// </summary>
public DotnetHostHelper() : this(new FileHelper())
public DotnetHostHelper() : this(new FileHelper(), new PlatformEnvironment())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DotnetHostHelper"/> class.
/// </summary>
/// <param name="fileHelper">File Helper</param>
public DotnetHostHelper(IFileHelper fileHelper)
public DotnetHostHelper(IFileHelper fileHelper, IEnvironment environment)
{
this.fileHelper = fileHelper;
this.environment = environment;
}

/// <inheritdoc />
public string GetDotnetHostFullPath()
public string GetDotnetPath()
{
char separator = ';';
var dotnetExeName = "dotnet.exe";
if (!TryGetExecutablePath("dotnet", out string dotnetPath))
{
string errorMessage = string.Format(Resources.NoDotnetExeFound, "dotnet");

EqtTrace.Error(errorMessage);
throw new FileNotFoundException(errorMessage);
}

#if !NET46
// Use semicolon(;) as path separator for windows
// colon(:) for Linux and OSX
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return dotnetPath;
}

public string GetMonoPath()
{
if (!TryGetExecutablePath(MONOEXENAME, out string monoPath))
{
separator = ':';
dotnetExeName = "dotnet";
string errorMessage = string.Format(Resources.NoDotnetExeFound, MONOEXENAME);

EqtTrace.Error(errorMessage);
throw new FileNotFoundException(errorMessage);
}
#endif

return monoPath;
}

private bool TryGetExecutablePath(string executableBaseName, out string executablePath)
{
if (this.environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows))
{
executableBaseName = executableBaseName + ".exe";
}

executablePath = string.Empty;
var pathString = Environment.GetEnvironmentVariable("PATH");
foreach (string path in pathString.Split(separator))
foreach (string path in pathString.Split(Path.PathSeparator))
{
string exeFullPath = Path.Combine(path.Trim(), dotnetExeName);
string exeFullPath = Path.Combine(path.Trim(), executableBaseName);
if (this.fileHelper.Exists(exeFullPath))
{
return exeFullPath;
executablePath = exeFullPath;
return true;
}
}

string errorMessage = string.Format(Resources.NoDotnetExeFound, dotnetExeName);

EqtTrace.Error(errorMessage);
throw new FileNotFoundException(errorMessage);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces
public interface IDotnetHostHelper
{
/// <summary>
/// Get full path for the .net host
/// Gets the full path for of .net core host.
/// </summary>
/// <returns>Full path to <c>dotnet</c> executable</returns>
/// <remarks>Debuggers require the full path of executable to launch it.</remarks>
string GetDotnetHostFullPath();
string GetDotnetPath();

/// <summary>
/// Gets the full path of mono host.
/// </summary>
/// <returns>Full path to <c>mono</c> executable</returns>
string GetMonoPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<value>Unhandled exception occurred while processing a job from the '{0}' queue: {1}</value>
</data>
<data name="NoDotnetExeFound" xml:space="preserve">
<value>Could not find {0}. Make sure that the dotnet is installed on the machine.</value>
<value>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</value>
</data>
<data name="QueueAlreadyDisposed" xml:space="preserve">
<value>The {0} queue has already been disposed.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">Nejde najít {0}. Ujistěte se, že na počítači je nainstalovaný dotnet.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">Nejde najít {0}. Ujistěte se, že na počítači je nainstalovaný dotnet.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">{0} wurde nicht gefunden. Stellen Sie sicher, dass das dotnet auf dem Computer installiert ist.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">{0} wurde nicht gefunden. Stellen Sie sicher, dass das dotnet auf dem Computer installiert ist.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">No se pudo encontrar {0}. Asegúrese de que dotnet esté instalado en la máquina.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">No se pudo encontrar {0}. Asegúrese de que dotnet esté instalado en la máquina.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">{0} est introuvable. Vérifiez que le dotnet est installé sur la machine.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">{0} est introuvable. Vérifiez que le dotnet est installé sur la machine.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">{0} non è stato trovato. Assicurarsi che dotnet sia installato nel computer.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">{0} non è stato trovato. Assicurarsi che dotnet sia installato nel computer.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">{0} が見つかりませんでした。dotnet がマシンにインストールされていることを確認してください。</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">{0} が見つかりませんでした。dotnet がマシンにインストールされていることを確認してください。</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">{0}을(를) 찾을 수 없습니다. 컴퓨터에 dotnet이 설치되어 있는지 확인하세요.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">{0}을(를) 찾을 수 없습니다. 컴퓨터에 dotnet이 설치되어 있는지 확인하세요.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">Nie znaleziono elementu {0}. Upewnij się, że program dotnet jest zainstalowany na maszynie.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">Nie znaleziono elementu {0}. Upewnij się, że program dotnet jest zainstalowany na maszynie.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<note from="bb-metadata">fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4"</note>
</trans-unit>
<trans-unit id="NoDotnetExeFound">
<source>Could not find {0}. Make sure that the dotnet is installed on the machine.</source>
<target state="translated">Não foi possível localizar {0}. Certifique-se de que o dotnet esteja instalado no computador.</target>
<note />
<source>Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable.</source>
<target state="new">Não foi possível localizar {0}. Certifique-se de que o dotnet esteja instalado no computador.</target>
<note></note>
</trans-unit>
</body>
</file>
Expand Down
Loading

0 comments on commit bf43157

Please sign in to comment.