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

Fix relative path tool path #9330

Merged
merged 3 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public static string GetRelativePath(DirectoryInfo directory, FileSystemInfo chi
/// </summary>
public static string GetRelativePath(string path1, string path2)
{
if (!Path.IsPathRooted(path1) || !Path.IsPathRooted(path2))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

{
throw new ArgumentException("both paths need to be rooted/full path");
}

return GetRelativePath(path1, path2, Path.DirectorySeparatorChar, true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/ShellShim/AppHostShimMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension);
}

var appHostDestinationFilePath = shimPath.Value;
var appBinaryFilePath = PathUtility.GetRelativePath(appHostDestinationFilePath, entryPoint.Value);
var appHostDestinationFilePath = Path.GetFullPath(shimPath.Value);
var appBinaryFilePath = Path.GetRelativePath(Path.GetDirectoryName(appHostDestinationFilePath), Path.GetFullPath(entryPoint.Value));

This comment was marked as spam.


EmbedAppNameInHost.EmbedAndReturnModifiedAppHostPath(
appHostSourceFilePath: appHostSourcePath,
Expand Down
31 changes: 29 additions & 2 deletions test/Microsoft.DotNet.ShellShim.Tests/ShellShimRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ public void GivenAnExecutablePathItCanGenerateShimFile()
stdOut.Should().Contain("Hello World");
}

// Reproduce https://github.com/dotnet/cli/issues/9319

This comment was marked as spam.

[Fact]
public void GivenAnExecutableAndRelativePathToShimPathItCanGenerateShimFile()
{
var outputDll = MakeHelloWorldExecutableDll("GivenAnExecutableAndRelativePath");
// To reproduce the bug, dll need to be nested under the shim
var parentPathAsShimPath = outputDll.GetDirectoryPath().GetParentPath().GetParentPath().Value;
var relativePathToShim = Path.GetRelativePath(
Directory.GetCurrentDirectory(),
parentPathAsShimPath);

ShellShimRepository shellShimRepository = ConfigBasicTestDependecyShellShimRepository(relativePathToShim);
var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName();

shellShimRepository.CreateShim(outputDll, shellCommandName);

var stdOut = ExecuteInShell(shellCommandName, relativePathToShim);

stdOut.Should().Contain("Hello World");
}

private static ShellShimRepository ConfigBasicTestDependecyShellShimRepository(string pathToShim)
{
string stage2AppHostTemplateDirectory = GetAppHostTemplateFromStage2();
Expand Down Expand Up @@ -473,13 +494,19 @@ private static string GetAppHostTemplateFromStage2()
return stage2AppHostTemplateDirectory;
}

private static FilePath MakeHelloWorldExecutableDll()
private static FilePath MakeHelloWorldExecutableDll(string instanceName = null)
{
const string testAppName = "TestAppSimple";
const string emptySpaceToTestSpaceInPath = " ";
const string directoryNamePostFix = "Test";

if (instanceName == null)
{
instanceName = testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix;
}

TestAssetInstance testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName + emptySpaceToTestSpaceInPath + directoryNamePostFix)
.CreateInstance(instanceName)
.UseCurrentRuntimeFrameworkVersion()
.WithRestoreFiles()
.WithBuildFiles();
Expand Down