2017-03-03 05:04:03 +00: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-11 00:13:46 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2017-03-17 03:26:26 +00:00
|
|
|
using System.Xml.Linq;
|
2016-10-16 01:34:03 +00:00
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
2016-10-11 00:13:46 +00:00
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
|
|
|
{
|
|
|
|
public class RepoDirectoriesProvider
|
|
|
|
{
|
|
|
|
private static string s_repoRoot;
|
2017-03-17 03:26:26 +00:00
|
|
|
private static string s_buildRid;
|
2016-10-11 00:13:46 +00:00
|
|
|
|
|
|
|
private string _artifacts;
|
|
|
|
private string _builtDotnet;
|
|
|
|
private string _nugetPackages;
|
|
|
|
private string _stage2Sdk;
|
2017-04-06 20:43:26 +00:00
|
|
|
private string _stage2WithLegacyRuntimeDirectory;
|
2016-10-11 00:13:46 +00:00
|
|
|
private string _testPackages;
|
2016-10-28 01:46:43 +00:00
|
|
|
private string _pjDotnet;
|
2016-10-11 00:13:46 +00:00
|
|
|
|
|
|
|
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 16:32:49 +00:00
|
|
|
public static string BuildRid
|
2017-03-17 03:26:26 +00: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-11 00:13:46 +00:00
|
|
|
public string Artifacts => _artifacts;
|
|
|
|
public string BuiltDotnet => _builtDotnet;
|
|
|
|
public string NugetPackages => _nugetPackages;
|
2016-10-28 01:46:43 +00:00
|
|
|
public string PjDotnet => _pjDotnet;
|
2016-10-11 00:13:46 +00:00
|
|
|
public string Stage2Sdk => _stage2Sdk;
|
2017-04-06 20:43:26 +00:00
|
|
|
public string Stage2WithLegacyRuntimeDirectory => _stage2WithLegacyRuntimeDirectory;
|
2016-10-11 00:13:46 +00:00
|
|
|
public string TestPackages => _testPackages;
|
|
|
|
|
|
|
|
public RepoDirectoriesProvider(
|
|
|
|
string artifacts = null,
|
|
|
|
string builtDotnet = null,
|
|
|
|
string nugetPackages = null,
|
|
|
|
string corehostPackages = null,
|
2016-10-28 01:46:43 +00:00
|
|
|
string corehostDummyPackages = null,
|
|
|
|
string pjDotnet = null)
|
2016-10-11 00:13:46 +00:00
|
|
|
{
|
2017-03-17 03:26:26 +00:00
|
|
|
_artifacts = artifacts ?? Path.Combine(RepoRoot, "artifacts", BuildRid);
|
2016-10-11 00:13:46 +00:00
|
|
|
_builtDotnet = builtDotnet ?? Path.Combine(_artifacts, "intermediate", "sharedFrameworkPublish");
|
2016-10-28 01:46:43 +00:00
|
|
|
_nugetPackages = nugetPackages ?? Path.Combine(RepoRoot, ".nuget", "packages");
|
|
|
|
_pjDotnet = pjDotnet ?? GetPjDotnetPath();
|
2016-10-11 00:13:46 +00:00
|
|
|
_stage2Sdk = Directory.EnumerateDirectories(Path.Combine(_artifacts, "stage2", "sdk")).First();
|
2017-04-06 20:43:26 +00:00
|
|
|
_stage2WithLegacyRuntimeDirectory = Path.Combine(_artifacts, "stage2WithLegacyRuntime");
|
2016-11-01 19:46:29 +00:00
|
|
|
_testPackages = Path.Combine(RepoRoot, "artifacts", "testpackages", "packages");
|
2016-10-11 00:13:46 +00:00
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
private string GetPjDotnetPath()
|
|
|
|
{
|
2016-11-03 06:01:57 +00:00
|
|
|
return new DirectoryInfo(Path.Combine(RepoRoot, ".dotnet_stage0PJ"))
|
2016-10-28 01:46:43 +00:00
|
|
|
.GetDirectories().First()
|
|
|
|
.GetFiles("dotnet*").First()
|
|
|
|
.FullName;
|
|
|
|
}
|
2016-10-11 00:13:46 +00:00
|
|
|
}
|
2017-03-03 04:35:20 +00:00
|
|
|
}
|