Skip to content

Commit

Permalink
Allow artifacts directory to be overridden with DOTNET_SDK_ARTIFACTS_…
Browse files Browse the repository at this point in the history
…DIR environment variable

This makes it possible to work with the same copy of the repo from both
Linux and Windows by using a different artifacts directory for one of them.
  • Loading branch information
dsplaisted committed Feb 9, 2018
1 parent e32884f commit 854c1f7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
</PropertyGroup>

<PropertyGroup>
<ArtifactsDir>$(DOTNET_SDK_ARTIFACTS_DIR)</ArtifactsDir>
<ArtifactsDir Condition="'$(ArtifactsDir)' == ''">$(RepoRoot)artifacts\</ArtifactsDir>
<ArtifactsDir>$([MSBuild]::EnsureTrailingSlash($(ArtifactsDir)))</ArtifactsDir>
<DOTNET_INSTALL_DIR Condition="'$(DOTNET_INSTALL_DIR)' == ''">$(RepoRoot)artifacts\.dotnet\$(DotNetCliVersion)\</DOTNET_INSTALL_DIR>
</PropertyGroup>

Expand Down
10 changes: 7 additions & 3 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function InstallDotNetCli {
$DotNetInstallVerbosity = ""

if (!$env:DOTNET_INSTALL_DIR) {
$env:DOTNET_INSTALL_DIR = Join-Path $RepoRoot "artifacts\.dotnet\$DotNetCliVersion"
$env:DOTNET_INSTALL_DIR = Join-Path $ArtifactsDir ".dotnet\$DotNetCliVersion"
}

$DotNetRoot = $env:DOTNET_INSTALL_DIR
Expand Down Expand Up @@ -134,7 +134,7 @@ function InstallDotNetCli {
}

function InstallNuGet {
$NugetInstallDir = Join-Path $RepoRoot "artifacts\.nuget"
$NugetInstallDir = Join-Path $ArtifactsDir ".nuget"
$NugetExe = Join-Path $NugetInstallDir "nuget.exe"

if (!(Test-Path -Path $NugetExe)) {
Expand Down Expand Up @@ -283,7 +283,11 @@ if ($help -or (($properties -ne $null) -and ($properties.Contains("/help") -or $

$RepoRoot = Join-Path $PSScriptRoot ".."
$RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot);
$ArtifactsDir = Join-Path $RepoRoot "artifacts"

$ArtifactsDir = $env:DOTNET_SDK_ARTIFACTS_DIR
if (!($ArtifactsDir)) {
$ArtifactsDir = Join-Path $RepoRoot "artifacts"
}
$ArtifactsConfigurationDir = Join-Path $ArtifactsDir $configuration
$LogDir = Join-Path $ArtifactsConfigurationDir "log"
$VersionsProps = Join-Path $PSScriptRoot "Versions.props"
Expand Down
13 changes: 10 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function InstallDotNetCli {

if [ -z "$DOTNET_INSTALL_DIR" ]
then
export DOTNET_INSTALL_DIR="$RepoRoot/artifacts/.dotnet/$DotNetCliVersion"
export DOTNET_INSTALL_DIR="$ArtifactsDir/.dotnet/$DotNetCliVersion"
fi

DotNetRoot=$DOTNET_INSTALL_DIR
Expand Down Expand Up @@ -297,15 +297,22 @@ done
ScriptRoot="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

RepoRoot="$ScriptRoot/.."
ArtifactsDir="$RepoRoot/artifacts"
if [ -z $DOTNET_SDK_ARTIFACTS_DIR ]
then
ArtifactsDir="$RepoRoot/artifacts"
else
ArtifactsDir="$DOTNET_SDK_ARTIFACTS_DIR"
fi


ArtifactsConfigurationDir="$ArtifactsDir/$configuration"
LogDir="$ArtifactsConfigurationDir/log"
VersionsProps="$ScriptRoot/Versions.props"

# HOME may not be defined in some scenarios, but it is required by NuGet
if [ -z $HOME ]
then
export HOME="$RepoRoot/artifacts/.home/"
export HOME="$ArtifactsDir/.home/"
CreateDirectory "$HOME"
fi

Expand Down
15 changes: 11 additions & 4 deletions src/Tests/Microsoft.NET.TestFramework/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ public static void Initialize(TestCommandLine commandLine)
repoConfiguration = new DirectoryInfo(AppContext.BaseDirectory).Parent.Parent.Parent.Name;
}
}

string artifactsDir = Environment.GetEnvironmentVariable("DOTNET_SDK_ARTIFACTS_DIR");
if (!string.IsNullOrEmpty(artifactsDir))
{
artifactsDir = Path.Combine(repoRoot, "artifacts");
}

if (repoRoot != null)
{
testContext.NuGetFallbackFolder = Path.Combine(repoRoot, "artifacts", ".nuget", "NuGetFallbackFolder");
testContext.NuGetExePath = Path.Combine(repoRoot, "artifacts", ".nuget", $"nuget{Constants.ExeSuffix}");
testContext.NuGetCachePath = Path.Combine(repoRoot, "artifacts", ".nuget", "packages");
testContext.NuGetFallbackFolder = Path.Combine(artifactsDir, ".nuget", "NuGetFallbackFolder");
testContext.NuGetExePath = Path.Combine(artifactsDir, ".nuget", $"nuget{Constants.ExeSuffix}");
testContext.NuGetCachePath = Path.Combine(artifactsDir, ".nuget", "packages");
}
else
{
Expand All @@ -127,7 +134,7 @@ public static void Initialize(TestCommandLine commandLine)
testContext.BuildVersion = assemblyInformationalVersion.InformationalVersion;
}

testContext.ToolsetUnderTest = ToolsetInfo.Create(repoRoot, repoConfiguration, commandLine);
testContext.ToolsetUnderTest = ToolsetInfo.Create(repoRoot, artifactsDir, repoConfiguration, commandLine);

TestContext.Current = testContext;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private SdkCommandSpec CreateCommand(params string[] args)
return ret;
}

public static ToolsetInfo Create(string repoRoot, string configuration, TestCommandLine commandLine)
public static ToolsetInfo Create(string repoRoot, string repoArtifactsDir, string configuration, TestCommandLine commandLine)
{
var ret = new ToolsetInfo();

Expand All @@ -116,8 +116,8 @@ public static ToolsetInfo Create(string repoRoot, string configuration, TestComm
var dotnetCliVersion = GetDotNetCliVersion(repoRoot);

ret.CliVersionForBundledVersions = dotnetCliVersion;
ret.DotNetHostPath = Path.Combine(repoRoot, "artifacts", ".dotnet", dotnetCliVersion, $"dotnet{Constants.ExeSuffix}");
ret.SdksPath = Path.Combine(repoRoot, "artifacts", configuration, "bin", "Sdks");
ret.DotNetHostPath = Path.Combine(repoArtifactsDir, ".dotnet", dotnetCliVersion, $"dotnet{Constants.ExeSuffix}");
ret.SdksPath = Path.Combine(repoArtifactsDir, configuration, "bin", "Sdks");
}
else
{
Expand Down

0 comments on commit 854c1f7

Please sign in to comment.