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

Add Path.GetRelativePath#11689

Merged
JeremyKuhne merged 3 commits into
dotnet:masterfrom
JeremyKuhne:CreateRelativePath
Sep 20, 2016
Merged

Add Path.GetRelativePath#11689
JeremyKuhne merged 3 commits into
dotnet:masterfrom
JeremyKuhne:CreateRelativePath

Conversation

@JeremyKuhne
Copy link
Copy Markdown
Member

This change adds Path.GetRelativePath, which will calculate the relative
path from one directory to another file/directory.

The original proposal: #6191

@terrajobst, @ericstj, @jamesqo
CC: @danmosemsft

@davidfowl
Copy link
Copy Markdown
Member

cc @BrennanConroy


/// <summary>
/// Create a relative path from one path to another. Paths will be resolved before calculating the difference.
/// Default path comparison for the active platform will be used (OrdinalIgnoreCase for Windows, Ordinal for Unix/Mac).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Mac is not necessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@JeremyKuhne JeremyKuhne force-pushed the CreateRelativePath branch 2 times, most recently from a08e1d5 to d7b445c Compare September 14, 2016 04:16

internal const string ParentDirectoryPrefix = @"../";

internal static readonly StringComparison DefaultPathComparison = StringComparison.Ordinal;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be OrdinalIgnoreCase on macOS?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I noted yesterday, we also already have internal support for this, which we should just reuse:
https://github.com/dotnet/corefx/blob/master/src/Common/src/System/IO/PathInternal.CaseSensitivity.cs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be OrdinalIgnoreCase on macOS?

Yes, thanks.

As I noted yesterday, we also already have internal support for this

I'm slightly uncomfortable with case sensitivity coming from the state of the temp directory. I need to think that over a bit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I can't use the existing class as it has dependencies on System.IO.FileSystem. Updating with comments.

@JeremyKuhne JeremyKuhne force-pushed the CreateRelativePath branch 2 times, most recently from 4fdae51 to c50d2c3 Compare September 15, 2016 01:56
@JeremyKuhne
Copy link
Copy Markdown
Member Author

@joperezr This should tackle #11321 - can you take a look?

Comment thread init-tools.cmd Outdated

:: Need updated nuget binaries in our cli drop
echo Updating CLI Nuget Frameworks map...
robocopy "%TOOLRUNTIME_DIR%" "%TOOLRUNTIME_DIR%\dotnetcli\sdk\%DOTNET_VERSION%" Nuget.Frameworks.dll /XO >> "%INIT_TOOLS_LOG%"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that copying all of the Nuget.* dlls causes failures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting Nuget.*.dll to work as well. What errors are you seeing?


In reply to: 78878113 [](ancestors = 78878113)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tries to bring in some other class that it can't find- I didn't dig into it further, just pedaled back for expediency

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this as opposed to pulling them in via BuildTools?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are already in buildtools, we're just making CLI use the updated one from buildtools. You could ask "why aren't we pulling it in via CLI?" and the answer would be: CLI takes too long to update and its unclear if folks care about updating the current form given the msbuild switch.

@JeremyKuhne
Copy link
Copy Markdown
Member Author

@dotnet-bot test Innerloop Windows_NT Debug Build and Test

@JeremyKuhne
Copy link
Copy Markdown
Member Author

Not sure why the init-tools.cmd is failing on the CI, is there a way to get init-tools.log files?

@ericstj
Copy link
Copy Markdown
Member

ericstj commented Sep 15, 2016

@dotnet-bot test Innerloop Windows_NT Debug Build and Test

Comment thread init-tools.cmd
echo %PROJECT_JSON_CONTENTS% > "%PROJECT_JSON_FILE%"
echo Running %0 > "%INIT_TOOLS_LOG%"

set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why moving this line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it outside of the block that might be skipped

Comment thread init-tools.cmd
:afterbuildtoolsrestore

echo Initializing BuildTools ...
echo Initializing BuildTools...
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unwanted space

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the extra space to make it match the rest

Comment thread init-tools.sh Outdated
fi

echo "Updating CLI Nuget Frameworks map..."
cp -u $__TOOLRUNTIME_DIR/Nuget.Frameworks.dll $__TOOLRUNTIME_DIR/dotnetcli/sdk/$__DOTNET_TOOLS_VERSION >> $__init_tools_log
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we verify that the exit code is 0 after this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably- I need to look up how to do this, so rusty with bash...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is what the previous checks for if [ "$?" != "0" ]; then checks are doing

Comment thread src/ref.builds
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="*\ref\**\*.*proj">
<Project Include="*\ref\**\*.builds;*\ref\**\*.*proj">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that with this approach some projects will get built twice? wherever there is a builds file, we shouldn't build the csprojs that it calls, but I'm not sure how to do this. @ericstj thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't actually build twice, MSBuild is smart enough to prevent that. If this becomes common-place we'll switch to builds everywhere, but right now that's unnecessary overhead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also worry about this a little but I'm good with this for now.

<ItemGroup>
<Project Include="System.Runtime.Extensions.csproj" />
<Project Include="System.Runtime.Extensions.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericstj should we have a different AssemblyVersion for the netcoreapp1.1 contract?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: we have similar precedent on desktop where more surface area is visible via facades.

@@ -0,0 +1 @@
MembersMustExist : Member 'System.IO.Path.CreateRelativePath(System.String, System.String)' does not exist in the implementation but it does exist in the contract. No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this wasn't complaining before?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't have exceptions for net462, that's already shipped. I suspect that the net462 targetgroup is resolving the wrong contract assembly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try removing this- it might be an artifact of iteration

<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp1.1'">
<TestNugetTargetMoniker Include="$(NugetTargetMoniker)">
<Folder>netcoreapp1.1</Folder>
</TestNugetTargetMoniker>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this as I saw that it is already in dir.props

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

<ItemGroup Condition="'$(TargetGroup)'=='netstandard1.7'">
<TestNugetTargetMoniker Include="$(NugetTargetMoniker)">
<Folder>ns1.7-netcoreapp1.1</Folder>
</TestNugetTargetMoniker>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably go in dir.props as I suppose a lot of test projects will start doing this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@ericstj
Copy link
Copy Markdown
Member

ericstj commented Sep 16, 2016

@JeremyKuhne , can you rebase on master and remove the init-tools workaround?

@JeremyKuhne
Copy link
Copy Markdown
Member Author

@ericstj I removed the init-tools workaround last night.

@JeremyKuhne JeremyKuhne force-pushed the CreateRelativePath branch 2 times, most recently from c3f4c5b to bc045b5 Compare September 16, 2016 23:15
@JeremyKuhne
Copy link
Copy Markdown
Member Author

@ericstj, @weshaggard, @joperezr This should be clean now- can I get sign off?

"System.Runtime": "4.1.0"
},
"frameworks": {
"netstandard1.7": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will generate a warning when you build the netcoreapp1.1 configuration. You can also delete the imports, they're no longer needed for the package version you are referencing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

Copy link
Copy Markdown
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulo a couple nits it looks good.

<TargetingPackReference Include="System.Private.Interop" />
<TargetingPackReference Include="System.Private.Reflection" /> <!-- can remove once we remove the Environment reflection workaround -->
<TargetingPackReference Include="System.Private.Reflection" />
<!-- can remove once we remove the Environment reflection workaround -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: reformatting here may have changed meaning of the comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this above, thanks

@JeremyKuhne
Copy link
Copy Markdown
Member Author

@dotnet-bot test Innerloop Windows_NT Release Build and Test

This change adds Path.GetRelativePath, which will calculate the relative
path from one directory to another file/directory.

This change also adds support for targetting netcoreapp
@JeremyKuhne
Copy link
Copy Markdown
Member Author

@dotnet-bot test this please

{
"dependencies": {
"System.Runtime": "4.0.20"
"System.Runtime": "4.1.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to the latest System.Runtime package prerelease? that way you will get netstandard1.7 version of System.Runtime surface area.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll update it

"netstandard1.7": {}
"netstandard1.7": {},
"netcoreapp1.1": {},
"netcoreapp1.0": {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't need netcoreapp1.0 since that should come from the supports corefx.Test.netcoreapp1.0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll try and remove it

<DefineConstants Condition="'$(TargetGroup)'=='netstandard1.7'">$(DefineConstants);netstandard17</DefineConstants>
<NugetTargetMoniker Condition="'$(NugetTargetMoniker)'==''">.NETStandard,Version=v1.5</NugetTargetMoniker>
</PropertyGroup>
<ItemGroup Condition="'$(TargetGroup)'=='netstandard1.7'">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log an issue in buildtools to move this code there instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go with the 1.2 issue, right? Or at least be associated.

Copy link
Copy Markdown
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments but this LGTM assuming CI is green.

The workarounds are no longer needed and fail with the dir.targets
workaround removed.
Test targets need updated to avoid issues when building multithreaded.
See #11468.
@JeremyKuhne
Copy link
Copy Markdown
Member Author

@dotnet-bot test Innerloop CentOS7.1 Release Build and Test

@JeremyKuhne JeremyKuhne merged commit e4ea1fd into dotnet:master Sep 20, 2016
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
@JeremyKuhne JeremyKuhne deleted the CreateRelativePath branch January 3, 2017 21:28
@JeremyKuhne
Copy link
Copy Markdown
Member Author

We want to get this in netfx eventually.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants