Skip to content

Move SDK file location creation to right branch - #4546

Merged
ViktorHofer merged 1 commit into
dotnet:masterfrom
ViktorHofer:SdkLocationFileFix
Dec 16, 2019
Merged

ViktorHofer merged 1 commit into
dotnet:masterfrom
ViktorHofer:SdkLocationFileFix

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

The SDK file creation logic was placed in a sub-branch which doesn't
always execute. This was reported in the runtime repository.

Fixes dotnet/runtime#871

The SDK file creation logic was placed in a sub-branch which doesn't
always execute. This was reported in the runtime repository.

Fixes dotnet/runtime#871
Comment thread eng/common/tools.ps1
# Creates a temporary file under the toolset dir.
# The following code block is protecting against concurrent access so that this function can
# be called in parallel.
if ($createSdkLocationFile) {

@jkotas jkotas Dec 16, 2019 •

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.

Would it make sense to check whether the file exists already, as an optimization?

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.

In case where the sdk entry is updated in global.json and the file already exists we would still need to re-create the file as the path could have changed from repo-local to global. Also this doesn't slow the execution measurably so I think overwriting the file always is necessary to guarantee that the path is correct.

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.

Also the global installation could have changed, so we need to make sure that we always call into the IntializeDotNetCli function when we want to use the SDK. When doing that we should always update the file in case paths have changed.

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.

In case where the sdk entry is updated in global.json

If you update global.json or any similar global settings, your best bet is to clean everything and do a fresh build. The build scripts are not robust against that in many different ways.

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.

A .\build.cmd/sh -restore was always enough in such cases at least in corefx, core-setup and other arcadified reopsitories and should be enough in the runtime repo now.

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.

Are you sure? I do not think that -Force overwrites when the file exists. You should see error like this:

PS D:\repro> Rename-Item -Force -Path .\a.txt b.txt
Rename-Item : Cannot create a file when that file already exists.

@ViktorHofer ViktorHofer Dec 16, 2019 •

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 was under the impression that force would overwrite an existing file but you are right. Instead I should probably use Move-Item -Path ... -Destination ... -Force.

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.

Is Move-Item -Force guaranteed to be atomic so that the parallel invocation of the scripts still work reliably?

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.

Just researched a bit and it seems file metadata only changes are atomic but what I'm trying to accomplish here doesn't seem to be possible with Powershell. I tend towards reverting to my old solution of just writing into the destination file directly and fall into the catch if this code path is ever hit concurrently. Does that sound fine?

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.

just writing into the destination file directly

This would not be reliable with concurrent use that you have said is important.

fall into the catch if this code path is ever hit concurrently

You can hit situations where one invocation sees partially written file, while the other one is overwriting it.

Comment thread eng/common/tools.ps1 Resolved

@jkotas jkotas left a comment

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.

The current delta should fix the problem that folks are reporting. The other issues being discussed can be resolved separately.

@ViktorHofer
ViktorHofer merged commit 4736ddc into dotnet:master Dec 16, 2019
@ViktorHofer
ViktorHofer deleted the SdkLocationFileFix branch December 16, 2019 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools.ps1 should ensure sdk.txt is always created if createSdkLocationFile is true

3 participants