2017-03-02 21:04:03 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
2016-10-10 17:13:46 -07:00
using System ;
using System.IO ;
using System.Linq ;
2017-03-16 22:26:26 -05:00
using System.Xml.Linq ;
2016-10-15 18:34:03 -07:00
using Microsoft.DotNet.PlatformAbstractions ;
2016-10-10 17:13:46 -07:00
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class RepoDirectoriesProvider
{
private static string s_repoRoot ;
2017-03-16 22:26:26 -05:00
private static string s_buildRid ;
2016-10-10 17:13:46 -07:00
private string _artifacts ;
private string _builtDotnet ;
private string _nugetPackages ;
private string _stage2Sdk ;
2017-04-07 16:36:23 -07:00
private string _stage2WithBackwardsCompatibleRuntimesDirectory ;
2016-10-10 17:13:46 -07:00
private string _testPackages ;
public static string RepoRoot
{
get
{
if ( ! string . IsNullOrEmpty ( s_repoRoot ) )
{
return s_repoRoot ;
}
#if NET451
string directory = AppDomain . CurrentDomain . BaseDirectory ;
#else
string directory = AppContext . BaseDirectory ;
#endif
while ( ! Directory . Exists ( Path . Combine ( directory , ".git" ) ) & & directory ! = null )
{
directory = Directory . GetParent ( directory ) . FullName ;
}
if ( directory = = null )
{
throw new Exception ( "Cannot find the git repository root" ) ;
}
s_repoRoot = directory ;
return s_repoRoot ;
}
}
2017-03-20 11:32:49 -05:00
public static string BuildRid
2017-03-16 22:26:26 -05:00
{
get
{
if ( string . IsNullOrEmpty ( s_buildRid ) )
{
var buildInfoPath = Path . Combine ( RepoRoot , "artifacts" , "obj" , "BuildInfo.props" ) ;
var root = XDocument . Load ( buildInfoPath ) . Root ;
var ns = root . Name . Namespace ;
s_buildRid = root
. Elements ( ns + "PropertyGroup" )
. Elements ( ns + "Rid" )
. FirstOrDefault ( )
? . Value ;
if ( string . IsNullOrEmpty ( s_buildRid ) )
{
throw new InvalidOperationException ( $"Could not find a property named 'Rid' in {buildInfoPath}" ) ;
}
}
return s_buildRid ;
}
}
2016-10-10 17:13:46 -07:00
public string Artifacts = > _artifacts ;
public string BuiltDotnet = > _builtDotnet ;
public string NugetPackages = > _nugetPackages ;
public string Stage2Sdk = > _stage2Sdk ;
2017-04-07 16:36:23 -07:00
public string Stage2WithBackwardsCompatibleRuntimesDirectory = > _stage2WithBackwardsCompatibleRuntimesDirectory ;
2016-10-10 17:13:46 -07:00
public string TestPackages = > _testPackages ;
public RepoDirectoriesProvider (
string artifacts = null ,
string builtDotnet = null ,
string nugetPackages = null ,
string corehostPackages = null ,
2018-03-27 10:24:10 -07:00
string corehostDummyPackages = null )
2016-10-10 17:13:46 -07:00
{
2017-03-16 22:26:26 -05:00
_artifacts = artifacts ? ? Path . Combine ( RepoRoot , "artifacts" , BuildRid ) ;
2016-10-10 17:13:46 -07:00
_builtDotnet = builtDotnet ? ? Path . Combine ( _artifacts , "intermediate" , "sharedFrameworkPublish" ) ;
2016-10-27 18:46:43 -07:00
_nugetPackages = nugetPackages ? ? Path . Combine ( RepoRoot , ".nuget" , "packages" ) ;
2017-06-20 22:05:44 -07:00
_stage2Sdk = Directory
. EnumerateDirectories ( Path . Combine ( _artifacts , "stage2" , "sdk" ) )
. First ( d = > ! d . Contains ( "NuGetFallbackFolder" ) ) ;
2017-04-07 16:36:23 -07:00
_stage2WithBackwardsCompatibleRuntimesDirectory =
2017-04-08 00:29:20 -07:00
Path . Combine ( _artifacts , "stage2WithBackwardsCompatibleRuntimes" ) ;
2016-11-01 12:46:29 -07:00
_testPackages = Path . Combine ( RepoRoot , "artifacts" , "testpackages" , "packages" ) ;
2016-10-10 17:13:46 -07:00
}
2016-10-27 18:46:43 -07:00
private string GetPjDotnetPath ( )
{
2016-11-02 23:01:57 -07:00
return new DirectoryInfo ( Path . Combine ( RepoRoot , ".dotnet_stage0PJ" ) )
2016-10-27 18:46:43 -07:00
. GetDirectories ( ) . First ( )
. GetFiles ( "dotnet*" ) . First ( )
. FullName ;
}
2016-10-10 17:13:46 -07:00
}
2017-03-02 20:35:20 -08:00
}