Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit cc80ed4

Browse files
author
William Lee
authored
Tools shim maker and env path handling (#8085)
* Tools shim maker and env path handling Includes component: * Given executable, create shim (all three OSs) * Add executable path to Env PATH during first run * including manual instruction when there is no access
1 parent c17ffbf commit cc80ed4

35 files changed

+1149
-79
lines changed

Microsoft.DotNet.Cli.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Msbuild.Tests.Utilities", "
232232
EndProject
233233
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ToolPackageObtainer.Tests", "test\Microsoft.DotNet.ToolPackageObtainer.Tests\Microsoft.DotNet.ToolPackageObtainer.Tests.csproj", "{F0D50831-9468-4ACB-8FD8-E9883DD553FB}"
234234
EndProject
235+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.ShellShimMaker.Tests", "test\Microsoft.DotNet.ShellShimMaker.Tests\Microsoft.DotNet.ShellShimMaker.Tests.csproj", "{20376E28-68EB-4BE5-81A5-51500F1235E2}"
236+
EndProject
235237
Global
236238
GlobalSection(SolutionConfigurationPlatforms) = preSolution
237239
Debug|Any CPU = Debug|Any CPU
@@ -1640,6 +1642,30 @@ Global
16401642
{F0D50831-9468-4ACB-8FD8-E9883DD553FB}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
16411643
{F0D50831-9468-4ACB-8FD8-E9883DD553FB}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
16421644
{F0D50831-9468-4ACB-8FD8-E9883DD553FB}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
1645+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1646+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
1647+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|x64.ActiveCfg = Debug|Any CPU
1648+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|x64.Build.0 = Debug|Any CPU
1649+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|x86.ActiveCfg = Debug|Any CPU
1650+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Debug|x86.Build.0 = Debug|Any CPU
1651+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
1652+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
1653+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
1654+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|x64.Build.0 = Debug|Any CPU
1655+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU
1656+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.MinSizeRel|x86.Build.0 = Debug|Any CPU
1657+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
1658+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|Any CPU.Build.0 = Release|Any CPU
1659+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|x64.ActiveCfg = Release|Any CPU
1660+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|x64.Build.0 = Release|Any CPU
1661+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|x86.ActiveCfg = Release|Any CPU
1662+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.Release|x86.Build.0 = Release|Any CPU
1663+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
1664+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
1665+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
1666+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
1667+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
1668+
{20376E28-68EB-4BE5-81A5-51500F1235E2}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
16431669
EndGlobalSection
16441670
GlobalSection(SolutionProperties) = preSolution
16451671
HideSolutionNode = FALSE
@@ -1713,6 +1739,7 @@ Global
17131739
{44759218-B558-4AF0-8991-515F1100DCF5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
17141740
{E7C72EF2-8480-48B4-AAE8-A596F1A6048E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
17151741
{F0D50831-9468-4ACB-8FD8-E9883DD553FB} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
1742+
{20376E28-68EB-4BE5-81A5-51500F1235E2} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
17161743
EndGlobalSection
17171744
GlobalSection(ExtensibilityGlobals) = postSolution
17181745
SolutionGuid = {B526D2CE-EE2D-4AD4-93EF-1867D90FF1F5}

scripts/cli-test-env.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ done
1313

1414
REPO_ROOT="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )"
1515

16-
if [ "$uname" = "Darwin" ]
16+
uname=$(uname)
17+
if [ "$(uname)" == "Darwin" ]
1718
then
18-
RID=osx-x64
19+
RID=osx.10.13-x64
1920
else
2021
RID=linux-x64
2122
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.DotNet.Cli.Utils
5+
{
6+
public interface IEnvironmentPath: IEnvironmentPathInstruction
7+
{
8+
void AddPackageExecutablePathToUserPath();
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Microsoft.DotNet.Cli.Utils
2+
{
3+
public interface IEnvironmentPathInstruction
4+
{
5+
void PrintAddPathInstructionIfPathDoesNotExist();
6+
}
7+
}

src/Microsoft.DotNet.Cli.Utils/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
[assembly: InternalsVisibleTo("Microsoft.DotNet.TestFramework, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1313
[assembly: InternalsVisibleTo("Microsoft.DotNet.Tools.Tests.Utilities, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1414
[assembly: InternalsVisibleTo("Microsoft.DotNet.ProjectJsonMigration, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
15+
[assembly: InternalsVisibleTo("Microsoft.DotNet.ShellShimMaker.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

src/Microsoft.DotNet.Configurer/CliFallbackFolderPathCalculator.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Runtime.InteropServices;
7+
using Microsoft.DotNet.Cli.Utils;
8+
using Microsoft.DotNet.PlatformAbstractions;
9+
using NuGet.Common;
10+
11+
namespace Microsoft.DotNet.Configurer
12+
{
13+
public class CliFolderPathCalculator
14+
{
15+
private const string ToolsFolderName = "tools";
16+
private const string DotnetProfileDirectoryName = ".dotnet";
17+
18+
public string CliFallbackFolderPath => Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
19+
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
20+
21+
public string ExecutablePackagesPath => Path.Combine(DotnetUserProfileFolderPath, ToolsFolderName) ;
22+
public readonly string ExecutablePackagesPathOnMacEnvPath = $"~/{DotnetProfileDirectoryName}/{ToolsFolderName}";
23+
24+
public static string DotnetUserProfileFolderPath
25+
{
26+
get
27+
{
28+
string profileDir = Environment.GetEnvironmentVariable(
29+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "USERPROFILE" : "HOME");
30+
31+
return Path.Combine(profileDir, DotnetProfileDirectoryName);
32+
}
33+
}
34+
35+
public string NuGetUserSettingsDirectory =>
36+
NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
37+
}
38+
}

src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
45
using System.IO;
6+
using System.Runtime.InteropServices;
57
using Microsoft.DotNet.Cli.Utils;
68
using Microsoft.Extensions.EnvironmentAbstractions;
79

@@ -15,25 +17,30 @@ public class DotnetFirstTimeUseConfigurer
1517
private INuGetCacheSentinel _nugetCacheSentinel;
1618
private IFirstTimeUseNoticeSentinel _firstTimeUseNoticeSentinel;
1719
private string _cliFallbackFolderPath;
20+
private readonly IEnvironmentPath _pathAdder;
1821

1922
public DotnetFirstTimeUseConfigurer(
2023
INuGetCachePrimer nugetCachePrimer,
2124
INuGetCacheSentinel nugetCacheSentinel,
2225
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
2326
IEnvironmentProvider environmentProvider,
2427
IReporter reporter,
25-
string cliFallbackFolderPath)
28+
string cliFallbackFolderPath,
29+
IEnvironmentPath pathAdder)
2630
{
2731
_nugetCachePrimer = nugetCachePrimer;
2832
_nugetCacheSentinel = nugetCacheSentinel;
2933
_firstTimeUseNoticeSentinel = firstTimeUseNoticeSentinel;
3034
_environmentProvider = environmentProvider;
3135
_reporter = reporter;
3236
_cliFallbackFolderPath = cliFallbackFolderPath;
37+
_pathAdder = pathAdder ?? throw new ArgumentNullException(nameof(pathAdder));
3338
}
3439

3540
public void Configure()
3641
{
42+
AddPackageExecutablePath();
43+
3744
if (ShouldPrintFirstTimeUseNotice())
3845
{
3946
PrintFirstTimeUseNotice();
@@ -54,6 +61,23 @@ public void Configure()
5461
}
5562
}
5663

64+
private void AddPackageExecutablePath()
65+
{
66+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
67+
{
68+
if (!_firstTimeUseNoticeSentinel.Exists())
69+
{
70+
// Invoke when Windows first run
71+
_pathAdder.AddPackageExecutablePathToUserPath();
72+
}
73+
}
74+
else
75+
{
76+
// Invoke during installer, otherwise, _pathAdder will be no op object that this point
77+
_pathAdder.AddPackageExecutablePathToUserPath();
78+
}
79+
}
80+
5781
private bool ShouldPrintFirstTimeUseNotice()
5882
{
5983
var showFirstTimeUseNotice =

src/Microsoft.DotNet.Configurer/FirstTimeUseNoticeSentinel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class FirstTimeUseNoticeSentinel : IFirstTimeUseNoticeSentinel
1919

2020
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
2121

22-
public FirstTimeUseNoticeSentinel(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) :
22+
public FirstTimeUseNoticeSentinel(CliFolderPathCalculator cliFolderPathCalculator) :
2323
this(
24-
cliFallbackFolderPathCalculator.DotnetUserProfileFolderPath,
24+
CliFolderPathCalculator.DotnetUserProfileFolderPath,
2525
FileSystemWrapper.Default.File,
2626
FileSystemWrapper.Default.Directory)
2727
{

src/Microsoft.DotNet.Configurer/NuGetCachePrimer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@ public class NuGetCachePrimer : INuGetCachePrimer
1717

1818
private readonly INuGetCacheSentinel _nuGetCacheSentinel;
1919

20-
private readonly CliFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
20+
private readonly CliFolderPathCalculator _cliFolderPathCalculator;
2121

2222
public NuGetCachePrimer(
2323
INuGetPackagesArchiver nugetPackagesArchiver,
2424
INuGetCacheSentinel nuGetCacheSentinel,
25-
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
25+
CliFolderPathCalculator cliFolderPathCalculator)
2626
: this(nugetPackagesArchiver,
2727
nuGetCacheSentinel,
28-
cliFallbackFolderPathCalculator,
28+
cliFolderPathCalculator,
2929
FileSystemWrapper.Default.File)
3030
{
3131
}
3232

3333
internal NuGetCachePrimer(
3434
INuGetPackagesArchiver nugetPackagesArchiver,
3535
INuGetCacheSentinel nuGetCacheSentinel,
36-
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator,
36+
CliFolderPathCalculator cliFolderPathCalculator,
3737
IFile file)
3838
{
3939
_nugetPackagesArchiver = nugetPackagesArchiver;
4040

4141
_nuGetCacheSentinel = nuGetCacheSentinel;
4242

43-
_cliFallbackFolderPathCalculator = cliFallbackFolderPathCalculator;
43+
_cliFolderPathCalculator = cliFolderPathCalculator;
4444

4545
_file = file;
4646
}
@@ -52,7 +52,7 @@ public void PrimeCache()
5252
return;
5353
}
5454

55-
var nuGetFallbackFolder = _cliFallbackFolderPathCalculator.CliFallbackFolderPath;
55+
var nuGetFallbackFolder = _cliFolderPathCalculator.CliFallbackFolderPath;
5656

5757
_nugetPackagesArchiver.ExtractArchive(nuGetFallbackFolder);
5858

0 commit comments

Comments
 (0)